How do I move to the next capital letter?

前端 未结 5 1154
庸人自扰
庸人自扰 2021-02-01 02:25

In vim I can use f followed by a character to go to the next occurrence of that character on the current line. For example, if I have the following (cursor position

相关标签:
5条回答
  • 2021-02-01 02:27

    When I searched for that I would be happy to just have the "native" solution: just enter in command mode:

    /\u
    

    which stands for "search for an uppercase letter". After that just move between capital letters with n and N (shift + n).

    0 讨论(0)
  • 2021-02-01 02:29

    I have found this vim tip for moving within CamelCaseWords that might be useful:

    " 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
    
    0 讨论(0)
  • 2021-02-01 02:36

    I would recommand the following script : camelcasemotion. It allows you to jump , delete inner 'camel case words', using ,+ normal navigation [w,b,e] etc...

    0 讨论(0)
  • 2021-02-01 02:44

    wilhelmtell's answer will work unless 'ignorecase' parameter is set. If 'smartcase' is activated or 'noignorecase' then it is okay.

    However a pattern that can replace [A-Z] is \u (see :help /\u or more globally :help pattern). Therefore you can replace your mapping with:

    :nnoremap <leader>C /\u<CR>:nohlsearch<CR>
    
    0 讨论(0)
  • 2021-02-01 02:48
    :nmap <leader>C /[A-Z]<CR>:nohlsearch<CR>
    

    Then in normal mode <leader>C (which by default means \C)

    0 讨论(0)
提交回复
热议问题