13

I'm searching for shortcut in WebStorm for auto completing my html code. So in my case if I write code like .row and press something it should automatically write <div class="row"></div>.

7
  • 5
    If you write div.row and hit Tab it will do it. Otherwise how is it supposed to know what element you want that class to be on? Commented Oct 23, 2016 at 17:16
  • 1
    Omg, yes tab does the trick. I was hitting everything else, just not tab. even if you write .class it writes you <div class="class"></div>. Write your answer and i will accept it! Thank you Commented Oct 23, 2016 at 17:18
  • 1
    @jonrsharpe "Otherwise how is it supposed to know what element you want that class to be on?" It's a standard behaviour of Emmet -- it will be a div tag with that class applied to it. Commented Oct 23, 2016 at 18:48
  • 2
    @Valor_ Tab is default .. but it can also be Enter or Space .. or even custom key of your choice -- Settings/Preferences | Editor | Emmet Commented Oct 23, 2016 at 18:50
  • @LazyOne oh cool, didn't know that. I thought it only worked tacked onto specific element names. Commented Oct 23, 2016 at 19:11

2 Answers 2

31

Such "transformation" (abbreviation expansion) called Emmet .. and by default it uses Tab key.

But it can also be Enter or Space .. or even custom key of your choice -- you can change it at Settings/Preferences | Editor | Emmet


P.S. For big chunks of code -- have a look at Live Templates (Code Snippets).

Sign up to request clarification or add additional context in comments.

3 Comments

Btw, do you know how can we export these code snippets to back up or share them with others?
@Tung What "code snippets" exactly? If you are referring to the standard Emmet abbreviations.. then they are standard ones already (docs.emmet.io/cheat-sheet) so if your editor/IDE supports Emmet it should have them already. If standard Live Templates -- well, they are standard for IDE (bundled) so no need to share anything. For custom Live Templates that you can create yourself -- jetbrains.com/help/phpstorm/… -- they are stored intemplates subfolder.
Thank you for the link of abbreviations cheat sheet. It answers my question. If they were implemented by default, we don't need to save the configuration for them.
10

You can use the Tab key to auto-complete the code. For example:

Write .row#row and press Tab key will make <div class="row" id="row"></div>.

I think this would help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.