So I guess I'm not searching for the right thing but I'm looking to see how you can get VIM to act like Textmate when it comes to writing a set of curly braces, parens, or square brackets hit enter and you get this. Pipe indicates cursor.
function doSomething(){
|
}
#selector{
|
}
Instead of this garbage
function doSomething(){
|}
#selector{
|}
I already have the [{( closing each other when they are typed just the return and indentation is jacked. As usual any help would be appreciated.
You can use the % key to jump to a matching opening or closing parenthesis, square bracket or a curly brace.
On English keyboards, the open bracket and close bracket are on the same key as the [ and ] (square bracket) keys, located near the Enter key. To get a curly bracket, press and hold the Shift key, then press the { or } key.
{} (curly braces)Define the beginning and end of functions blocks and statement blocks such as the for and if structures. Curly braces are also used for defining initial values in array declarations.
Creating and executing a simple template Handlebars expressions are put into double curly braces {{expr}} for HTML-escaped content; otherwise, use triple curly brackets {{{expr}}} to avoid HTML-escaping.
I use the following mappings in my .vimrc
:
inoremap {<cr> {<cr>}<c-o>O<tab>
inoremap [<cr> [<cr>]<c-o>O<tab>
inoremap (<cr> (<cr>)<c-o>O<tab>
So when I input:
function foo(){<cr>
I get:
function foo(){
|
}
Similar with (<cr>
and [<cr>
.
When using the delimitMate plugin, the mappings of the other answers interfere with the plugin. Luckily, this behavior is already available in delimitMate (but disabled by default), by setting the delmitMateExpansion
options. E.g. add
let delimitMate_expand_cr = 1
to your .vimrc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With