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?
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:
Don’t use
strpart(),string[idx1:idx2]works fine (all ofidx1,idx2,:are optional, but at least one must be present), is less to type and is more readable.