Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preferred way to move around in vim (normal mode)

Tags:

vim

I haven't seen this asked on stackoverflow, and this is my biggest pain point in vim:

How do you all navigate within a file? I found myself using the hjkl too much, or too repetitively, and I want to get better at this. This is frustrating when you're on a large monitor.

I installed EasyMotion - and so far it's been good for me - I just want to know if there's something better...

Thanks!

like image 896
Daniel D Avatar asked Oct 06 '11 18:10

Daniel D


2 Answers

It depends on how you want to move around, but generally,

  • A puts you in insert mode at the end of a line
  • I at the beginning
  • o inserts a line below
  • O above

and more powerfully, searching with /<thing you want to jump to> is very handy. In a c file where the functions are formatted

int
funcname()

/^funcname will jump you to the start of the function. There's a bunch more, but this shold be a good start for someone new to vim.

like image 31
Dave Avatar answered Oct 06 '22 00:10

Dave


I like the cheatsheet of Ted Naleid. It's like a reticle so you can easily find the horizontal and vertical movements. Put it on a wall next to your monitor and you will soon pick up new movements on the fly.

The movements that I liked recently are:

  • () and {} which let you hop function wise in source code
  • / and ? + n/N just search, you normally know where you want to go
  • fx and tx - to jump to or before the next character x of course you can do a 2fx to jump to the second occurrence of x, like you can do with all movements
  • % to move between starting and ending parenthesis
like image 51
topek Avatar answered Oct 05 '22 23:10

topek