Is there a way to tab through fields and values in a json file in Vim as you would form fields on a web form?
1 Answer
There is not native way to do this however a few mappings should do the trick.
Add the following to ~/.vim/after/ftplugin/javascript.vim
:
nnoremap <buffer> <tab> :<c-u>call search('\v("<bar>null<bar>\d+<bar>true<bar>false<bar>\[\]<bar>\{\})\ze\n=\s*[]:,}]')<bar>execute "normal! vi". (getline('.')[col('.')-1] == '"' ? '"' : 'w')<cr>
xmap <buffer> <tab> <esc>`>l<tab>
The basic idea is to search for items followed by ,
, }
, ]
.
For more information see:
:h :search
:h <bar>
:h /\|
:h /\ze
:h :execute
:h :normal
:h getline()
:h col()
:h c_CTRL-U
-
-
1It would break if the latter part of the mapping didn't use
vi"
to actually select the string. You could also do some fancy look-behind to avoid sniffing syntax. Aug 18, 2015 at 1:55 -