简体   繁体   中英

Sublime text 2 HTML autocomplete with “>” character

When using Notepad++, I used to simply type <div> (without pressing tab or anything) and the software would instantly add the closing tag like this : <div></div> , setting the cursor position between the two tags. It appears that Notepad++ simply uses the > key to trigger the autocompletion, while I need to press tab or using the autocompletion box in Sublime text 2 to make it work.

Is there a way in Sublime text 2 to do the same thing ? I want to trigger the autocompletion simply by closing the opening tag without pressing any other keys.

Thanks for your help

In sublime text 2 .. you can type

  <d  and then a enter 

and you obtain

<div></div>

Sublime Text offers a variety of shortcuts. You can also create your own shortcuts!

[On Windows] Preferences > Key Bindings - User [On OS X] Sublime Text > Preferences > Key Bindings - User

See here for a tutorial.

http://codezag.com/sublime-text-create-shortcuts-key-bindings/

I wrote this line in Key Bindings - User :

{"keys": [">"], "command": "insert_best_completion"}

It works fine with simple tags like <div> (which autocompletes to <div></div> ) but it doesn't work when adding attributes like <div id="something"> or <div width="100px"> . In this case ST2 won't write the > character so I can't even close the opening tag.

What should I add to make Sublime text "ignore" the attributes and still close the tags wether they have attributes or not ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM