Reputation: 2649
I'd like to be able to hit tab and have it step over/move outside the closing tag in Vim. I can kind of achieve this by adding
inoremap <C-e> <C-o>A
to my .vimrc, but this only works by hitting Ctrl+e (and it moves to the end of line, not outside the closing marker). I'd prefer to use tab.
I had this set up in Sublime Text 2 by using:
[
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[;=><',)\"\\]]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
}
]
Thanks for your help
Upvotes: 1
Views: 746
Reputation: 1137
What about
<Esc>va(<Esc>`<
that puts the cursor on previous "(" character matched after current position ?
"<", instead of the last ">", will put cursor on next unmatched ")" ... "(" can be replaced by "{" or "[" or "s" (sentences) or "p" (paragraphs) or """ (strings). More possibilities are shown by:
:help a(
To go at end of current paragraph, you also have:
<C-o>}
Replace "}" by ")" to go at end of current sentence.
To go at end of next () or {} or [], you can type
<C-o>%
Upvotes: 1
Reputation: 1072
Some time ago I wrote this little vimscript that I think does what you want to do. Hope it helps
if !exists( "g:out_of_expression_quick_key" )
let g:out_of_expression_quick_key = "<Tab>"
endif
execute "imap " . g:out_of_expression_quick_key . " <C-r>=IncreaseColNumber()<CR>"
execute "imap " . g:out_of_expression_quick_key[0] . 'S-' . g:out_of_expression_quick_key[1:] . ' <C-r>=DecreaseColNumber()<CR>'
let s:delimiters_exp = '[\[\]{}())"' . "'" . '<>]'
fun! IncreaseColNumber()
let l:colnum = col('.')
let l:line = getline('.')
if l:line[col('.') - 1:l:colnum] =~# s:delimiters_exp
return "\<Right>"
endif
if g:out_of_expression_quick_key =~# "<Return>"
return "\<CR>"
endif
if g:out_of_expression_quick_key =~# "<Tab>"
return "\<Tab>"
endif
endfunction
fun! DecreaseColNumber()
let l:line = getline('.')
if l:line[col('.') - 2] =~# s:delimiters_exp
return "\<Left>"
endif
if g:out_of_expression_quick_key =~# "<Return>"
return "\<S-CR>"
endif
if g:out_of_expression_quick_key =~# "<Tab>"
return "\<S-Tab>"
endif
endfunction
Upvotes: 3