在vim中,我可以使用f后跟一个字符来转到当前行上该字符的下一个匹配项.例如,如果我有以下(光标位置标记|):
m|akeBinExprNode = undefined
我可以使用fB移动到B并dtE删除,直到前E,留给我:
make|ExprNode = undefined
我想知道是否有办法做到这一点,不涉及输入确切的字符,即某种动作,意思是"转到下一个大写字母"和/或"在下一个大写字母前右转".
Ant*_*hev 26
当我搜索到它时,我很乐意拥有"原生"解决方案:只需进入命令模式:
/\u
它代表"搜索大写字母".之后只需在大写字母n和N(shift + n)之间移动.
mb1*_*b14 14
我建议使用以下脚本:camelcasemotion.它允许你跳跃,删除内部'骆驼案例词',使用,+普通导航[w,b,e]等...
我发现这个vim提示可以在CamelCaseWords中移动,这可能很有用:
" Use one of the following to define the camel characters.
" Stop on capital letters.
let g:camelchar = "A-Z"
" Also stop on numbers.
let g:camelchar = "A-Z0-9"
" Include '.' for class member, ',' for separator, ';' end-statement,
" and <[< bracket starts and "'` quotes.
let g:camelchar = "A-Z0-9.,;:{([`'\""
nnoremap <silent><C-Left> :<C-u>call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%^','bW')<CR>
nnoremap <silent><C-Right> :<C-u>call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%$','W')<CR>
inoremap <silent><C-Left> <C-o>:call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%^','bW')<CR>
inoremap <silent><C-Right> <C-o>:call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%$','W')<CR>
vnoremap <silent><C-Left> :<C-U>call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%^','bW')<CR>v`>o
vnoremap <silent><C-Right> <Esc>`>:<C-U>call search('\C\<\<Bar>\%(^\<Bar>[^'.g:camelchar.']\@<=\)['.g:camelchar.']\<Bar>['.g:camelchar.']\ze\%([^'.g:camelchar.']\&\>\@!\)\<Bar>\%$','W')<CR>v`<o
除非'ignorecase'参数设置,否则wilhelmtell的答案将起作用.如果'smartcase'被激活或者'noignorecase'它没有问题.
然而,可以取代的模式[A-Z]是\u(参见:help /\u或更全面:help pattern).因此,您可以用以下内容替换映射:
:nnoremap <leader>C /\u<CR>:nohlsearch<CR>
:nmap <leader>C /[A-Z]<CR>:nohlsearch<CR>
然后在正常模式下<leader>C(默认情况下\C)