Reputation: 3046
I would like to set up vim so that it moves my cursor right if I press tab on a closing parentheses. This is useful when used with auto complete parentheses.
Here is what I have so far (does not work):
inoremap <expr> <Tab> strpart(getline('.'), col('.')-1, 1) == "}" ? "\<Right>" : "\<Tab>"
inoremap <expr> <Tab> strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : "\<Tab>"
inoremap <expr> <Tab> strpart(getline('.'), col('.')-1, 1) == "]" ? "\<Right>" : "\<Tab>"
What am I doing wrong?
Upvotes: 1
Views: 995
Reputation: 53604
There can be only one working mapping to one key (you can define at least two: buffer-local (one per buffer) and one global, but they do not work at the same time), so you need something like that:
inoremap <expr> <Tab> stridx('])}', getline('.')[col('.')-1])==-1 ? "\t" : "\<Right>"
Don’t use strpart()
, string[idx1:idx2]
works fine (all of idx1
, idx2
, :
are optional, but at least one must be present), is less to type and is more readable.
Upvotes: 3