I just want to jump to from one function to the next in .c/.cpp files. How do I do that?
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.
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$][%?}
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With