Vim: Go to Beginning/End of Next Method

前端 未结 4 1156
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 15:26

Is there native functionality in Vim that allows one to move the cursor to the beginning/end of the next method? I already know about [[, ]],

相关标签:
4条回答
  • 2020-12-14 15:48

    I spent hours to make this pattern: /^\s*\(\i\+\_[ \t\*]\+\)\+\i\+\_s*(\_[^)]*)\_s*{, it works good for me.

    EDIT: a better pattern(version 2): /\(\(if\|for\|while\|switch\|catch\)\_s*\)\@64<!(\_[^)]*)\_[^;{}()]*\zs{

    see the effect here:

    you can map some convenient bindings in your .vimrc, such as:

    " jump to the previous function
    nnoremap <silent> [f :call search('^\s*\(\i\+\_[ \t\*]\+\)\+\i\+\_s*(\_[^)]*)\_s*{', "bw")<CR>
    " jump to the next function
    nnoremap <silent> ]f :call search('^\s*\(\i\+\_[ \t\*]\+\)\+\i\+\_s*(\_[^)]*)\_s*{', "w")<CR>
    

    EDIT: a better pattern(version 2):

    " jump to the previous function
    nnoremap <silent> [f :call
    \ search('\(\(if\\|for\\|while\\|switch\\|catch\)\_s*\)\@64<!(\_[^)]*)\_[^;{}()]*\zs{', "bw")<CR>
    " jump to the next function
    nnoremap <silent> ]f :call
    \ search('\(\(if\\|for\\|while\\|switch\\|catch\)\_s*\)\@64<!(\_[^)]*)\_[^;{}()]*\zs{', "w")<CR>
    
    0 讨论(0)
  • 2020-12-14 15:57

    Looks like a duplicate of: Vim [m motion with c#

    You could, for instance, give a try to this dirty trick: 9]}. Which just jumps to the 9-th } from the current location (if you're not too nested, should work...)

    0 讨论(0)
  • 2020-12-14 15:58

    If you use taglist, I added a feature that does just that. You can jump from one tag to the other using Ctrl-up & Ctrl-down, provided the language is supported by taglist.

    Here: https://github.com/man9ourah/taglist

    and this to your .vimrc.

    nmap <silent> <c-up> <plug>(TlistJumpTagUp)     " Map ctrl-up to move one tag up
    nmap <silent> <c-down> <plug>(TlistJumpTagDown) " Map ctrl-down to move one tag down
    
    0 讨论(0)
  • 2020-12-14 16:07

    Vim has [m / ]m built in "for Java or similar structured language".

    I have written custom versions that handle Vim functions, VBScript, and batch files, among others. These are all powered by my CountJump plugin, which can be used to write custom jump functions based on regular expressions.

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