20

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.

Milan Babuškov
  • 59,775
  • 49
  • 126
  • 179

6 Answers6

31

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

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

Paul
  • 13,042
  • 3
  • 41
  • 59
  • I found your solution more generic than the accepted solution, because the accepted solution didn't work for me in JavaScript. – Rafid Jan 24 '11 at 09:24
  • Although thinking about it, if it goes to the next '}' in the first column, then it might find difficulty with nested functions. – Rafid Jan 24 '11 at 09:25
22

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

jthompson
  • 7,178
  • 2
  • 34
  • 33
  • 1
    the OP may also want to investigate the '%' command, which jumps to the opening or closing brace/paren/bracket that is paired with whatever is under the cursor. – rmeador Mar 23 '09 at 19:45
  • Yes, % is useful as well but not for a quick jump out of a large function. – jthompson Mar 23 '09 at 19:46
  • 5
    You might also be interested in [[ and ]], they take you to the beginning of a function or the start of the next function. – Amjith Mar 24 '09 at 14:40
11

][ or [] will do this for you.

Ana Betts
  • 73,868
  • 16
  • 141
  • 209
2

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.

Phil H
  • 19,928
  • 7
  • 68
  • 105
  • This one is also good, but to be honest, I didn't like folding in Vim so far, I just feel it is hard, probably I need to spend some time reading about it, which I don't have unfortunately. Do you have any quick suggestion to make me like it? :-) – Rafid Jan 24 '11 at 09:27
1

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

Shree
  • 4,627
  • 6
  • 37
  • 49
0

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 :)