vehomzzz
vehomzzz

Reputation: 44678

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

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

Upvotes: 8

Views: 3098

Answers (6)

Mansour
Mansour

Reputation: 39

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

Upvotes: 0

lingjiankong
lingjiankong

Reputation: 366

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.

Upvotes: 6

Jake
Jake

Reputation: 2236

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>

Upvotes: 3

William Pursell
William Pursell

Reputation: 212674

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$][%?}

Upvotes: 7

drrlvn
drrlvn

Reputation: 8447

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.

Upvotes: 10

p4bl0
p4bl0

Reputation: 3906

Take a look at exuberant-ctags it works with Emacs, and your "vim" thing ;-)

Upvotes: 1

Related Questions