I just want to jump to from one function to the next in .c/.cpp files. How do I do that?
-
java / C++ methods http://stackoverflow.com/questions/12128678/vim-go-to-beginning-end-of-next-method (must be enclosed on a top `class {}`), beginning of function: http://stackoverflow.com/questions/2109503/how-to-jump-to-the-beginning-of-a-function-body-in-vim – Ciro Santilli OurBigBook.com Apr 25 '17 at 14:55
6 Answers
I believe you are looking for ]]
which jumps to the next {
char on the first column.
There are similar options, just try :help ]]
for more information.

- 8,189
- 2
- 43
- 57
Regarding the use of [[ and ]], note the following from motion.txt in the vim docs:
If your '{' or '}' are not in the first column, and you would like to use "[[" and "]]" anyway, try these mappings: :map [[ ?{w99[{ :map ][ /}b99]} :map ]] j0[[%/{ :map [] k$][%?}

- 204,365
- 48
- 270
- 300
-
3The problem with these is that if you have a search active and you use these maps, your search will be overwritten. – Jake Mar 10 '17 at 19:24
Simply use ]m
to jump to the next method, [m
to jump to the previous method.
In your ~/.vimrc
, you can do
nnoremap ]m ]mzz
nnoremap [m [mzz
so that everytime you jump between methods, you put the method at the center of your screen.

- 355
- 3
- 5
I use these mappings which will make [[ and ]] work with functions that don't put the starting { at the beginning of the line.
map ]] :call search("^\\(\\w.*\\)\\?{")<CR>
map [[ :call search("^\\(\\w.*\\)\\?{", "b")<CR>
map ][ :call search("^}")<CR>
map [] :call search("^}", "b")<CR>

- 2,106
- 1
- 24
- 23
-
Huh, make the cursor to the end of the match which is '{' or '}' like `map ]] :call search("^\\(\\w.*\\)\\?{", "e")
` maybe better. – zhenguoli Mar 10 '17 at 15:47
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

- 31
- 1
- 6