Sasha
Sasha

Reputation:

Go to the end of the C++ function in Vim

If I am in the middle of the function, I would like go to the very end of it in vim. I run into this problem as we sometimes have function of 500+ lines long (don't ask why).

I use vim, gvim.

Upvotes: 20

Views: 7466

Answers (6)

Solomon Xie
Solomon Xie

Reputation: 1

I found that @Ana Betts's answer is the most helpful after gone through nearly an hour of "research" . I tried to add some buffer mappings to make perfection:

autocmd BufReadPre *.js nnoremap <buffer> [[ []%0
autocmd BufReadPre *.js nnoremap <buffer> ]] ][%0

And this to your .vimrc and type ]] or ]] to see magic happen :)

Upvotes: 0

Shree
Shree

Reputation: 4747

SHIFT+5 toggles between { and }. You can use it to identify the top most block of code.

Upvotes: 1

Phil H
Phil H

Reputation: 20151

Make sure you're using :split and code folding to your advantage - keep a folded view at the top of the screen, unfold a function, split, edit the function, close the split window, collapse the fold.

Upvotes: 2

Paul
Paul

Reputation: 13238

][ goes to the next '}' in the first column.

Read :help 29.3 to find out more about moving through a program.

Upvotes: 31

jthompson
jthompson

Reputation: 7286

You can use the "]}" command. You may have to repeat it depending on how nested you are.

Upvotes: 22

Ana Betts
Ana Betts

Reputation: 74702

][ or [] will do this for you.

Upvotes: 11

Related Questions