Search code examples
phpstorm

When I create a new class="" the cursor starts outside the quotes in PhpStorm. How can I get it to go between the quotes so I can continue typing?


When I type in class="" it autofills and puts the cursor after the closing quote.

This means I need to delete a quote to enter the class name or click between them. Both of which ruin my workflow.

Is there a way to put the cursor inbetween the quotes in settings? And if there is, is there a way to jump out of the quotes and keep adding to my markup?

In Sublime Text it puts the cursor in the class and then tab takes you outside of it. I'm sure PhpStorm can do the same.


Solution

  • Instead of typing the whole class="" thing by yourself -- just let IDE autocompletion to do the job for you.

    Just two characters (cl) is enough to make class entry first in the list (unless you have used some other similarly named attributes/properties recently that would temporarily bring them higher than class):

    enter image description here

    • Completing with Enter will have the text inserted into current position with caret located in the right place class="[CARET_HERE]".
    • Completing with Tab does the same but replaces the text that is currently under caret (useful when changing class/image name/function/etc completely).

    If standard code completion is not good enough for some reason or you do not like automatic completion popop (and prefer invoking it manually only when needed) -- you will be interested in Live Templates functionality that allows creating some abbreviation and expanding it into the final snippet with minimal key presses (e.g. cl[Tab] into class="|")


    IDE also has options to:

    • insert quotes ("" or '') after typing = in XML/HTML attributes.
      Settings/Preferences | Editor | General | Smart Keys --> Add quotes for attribute value on typing '=' and attribute completion
    • insert pair quotes (closing one) when entering opening one -- works in different contexts/languages. It will "eat" the closing quote preventing you from typing too many. Settings/Preferences | Editor | General | Smart Keys --> Insert pair quote

    In Sublime Text it puts the cursor in the class and then tab takes you outside of it. I'm sure PhpStorm can do the same.

    If I understood you correctly (sorry, never used Sublime myself) -- No... and may not have it for quite some time (devs say that the way how IDE works somehow conflicts with proposed Tab or Esc behaviour).

    Better explanation/arguments from both sides can be found in actual ticket: https://youtrack.jetbrains.com/issue/IDEABKL-6984