Vim: Go to Beginning/End of Next Method

前端 未结 4 1245
伪装坚强ぢ
伪装坚强ぢ 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

    see the effect here:

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

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

    EDIT: a better pattern(version 2):

    " jump to the previous function
    nnoremap  [f :call
    \ search('\(\(if\\|for\\|while\\|switch\\|catch\)\_s*\)\@64
    " jump to the next function
    nnoremap  ]f :call
    \ search('\(\(if\\|for\\|while\\|switch\\|catch\)\_s*\)\@64
    

提交回复
热议问题