Reputation: 3677
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!
Upvotes: 12
Views: 7267
Reputation: 18979
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:
Upvotes: 24
Reputation: 4212
I use b
and w
to move left and right respectively on a single line. For up and down, I use Ctrl+u
and Ctrl+d
respectively. IMO Ctrl+u
and Ctrl+d
are better than Ctrl+b
and Ctrl+f
because they scroll half window at a time so that you don't loose context.
I haven't really used any plugin for moving around in vim so far.
Forgot to mention two other important keystrokes, $
and ^
to move to end of line and start of line respectively.
Upvotes: 10
Reputation: 11687
Read http://www.viemu.com/a-why-vi-vim.html and run vimtutor, also :help motion.txt will be usefull. I recommend also staying in normal mode all the time - as described in article above. Generally, learning vim is learning piano - you have to practice much.
Upvotes: 0
Reputation: 438
Mostly I use the following (in order of frequency):
Most all of these can be augmented with a count before the command.
Upvotes: 5
Reputation: 196606
I don't really see much to add in terms of general enlightenment but I use (ranked by how often I use them):
w and b
to move by one word to the right and to the left.
/ and ?
to search for a word or pattern to the bottom or to the top.
G and gg
to jump to the bottom and the top of the buffer.
<C-f> and <C-b>
to jump to the next and previous screen.
* and #
to jump to next and previous occurence of the word under the cursor.
f and F
to jump before a character to the right or to the left.
t and T
to jump on a character to the right or to the left.
Ho! and
$ and ^
a lot, too, to jump to the end and the beginning of a line.
Upvotes: 1
Reputation: 79185
Several move commands:
b B e E f F ge gE gj gk go G h H j k l L M n N t T w W { } / ? ^ $ # * ` ' | %
Learn them, plus all commands starting with [
like [{
which is very useful when editing C-style code…
See :help index.txt
for reference.
Upvotes: 8
Reputation: 11162
It depends on how you want to move around, but generally,
A
puts you in insert mode at the end of a lineI
at the beginningo
inserts a line below O
aboveand 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.
Upvotes: 4
Reputation: 12535
Simple documentation:
http://vim.wikia.com/wiki/Moving_around
Regular movement:
hjkl/arrow keys/page up/page down
%
will switch between open/ending braces
gg/G move to top/bottom
Folding:
For collapsing large blocks of code, you can use folding.
http://vimdoc.sourceforge.net/htmldoc/fold.html
Search:
To jump to something in particular type /searchstring
(use with set inc
for jumping to matches while typing)
*
to search forward for the same word the cursor is on
#
same but search backward
You can also use marks.
http://vim.wikia.com/wiki/Using_marks
I also use ctags and jumping to find stuff across multiple files.
http://vimdoc.sourceforge.net/htmldoc/tagsrch.html
I've never needed anything else.
Upvotes: 2