Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move from one C/C++ function to the next (both directions)

Tags:

vim

I just want to jump to from one function to the next in .c/.cpp files. How do I do that?

like image 706
vehomzzz Avatar asked Aug 31 '09 13:08

vehomzzz


4 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.

like image 86
drrlvn Avatar answered Nov 12 '22 04:11

drrlvn


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$][%?}
like image 7
William Pursell Avatar answered Nov 12 '22 03:11

William Pursell


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.

like image 5
lingjiankong Avatar answered Nov 12 '22 03:11

lingjiankong


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>
like image 3
Jake Avatar answered Nov 12 '22 03:11

Jake