The poor soul who is using VIM for the first time will be found pressing up and down arrows and executing key repeats, moving horribly inefficiently through any body of code.
He will be scrolling or paging (btw:
^f
moves forward one page, ^b
moves backward one page) and searching with his poor eyeballs through piles of code.This poor soul is slow and clueless, and probably considers VIM to be a really bad version of windows notepad instead of seeing it as the powerful tool it is.
By the way, the arrow keys don't always work for vim, but don't blame vim.
It's actually an issue with the way your terminal is set up. Vim can't tell that your arrow keys are arrow keys. If you have the problem, you have more research to do.
To use VIM well, it is essential that you learn how to move well.
Do not search and scroll.
Do not use your eyes to find text.
They have computers for that now.
Here are a handful of the most important movement commands. The best way to move is by searching:
/ | search forward: will prompt for a pattern |
? | search backward: will prompt for a pattern |
n | repeat last search (like dot for searches!) |
N | repeat last search but in the opposite direction. |
tx | Move "to" letter 'x' (any letter will do), stopping just before the 'x'. Handy for change/delete commands. |
fx | "Find" letter 'x' (any letter will do), stopping on the letter 'x'. Also handy for change/delete commands |
If you're not searching, at least consider jumping
gg | Move to beginning of file |
G | Move to end of file |
0 | Jump to the very start of the current line. |
w | Move forward to the beginning of the next word. |
W | Move forward to the beginning of the next space-terminated word (ignore punctuation). |
b | Move backward to the beginning of the current word, or backward one word if already at start. |
B | Move backward to the beginning of the current space-terminated word, ignoring punctuation. |
e | Move to end of word, or to next word if already at end. |
E | Move to end of space-terminated word, ignoring punctuation |
The following commands are handy, and are even sensible and memorable if you know regex:
^ | Jump to start of text on the current line. Far superior to leaning on left-arrow or h key. |
$ | Jump to end of the current line. Far superior to leaning on right-arrow or k key. |
Here is some fancy movement
% | move to matching brace, paren, etc |
} | Move to end of paragraph (first empty line). |
{ | Move to start of paragraph. |
( | Move to start of sentence (separator is both period and space). |
) | Move to start of next sentence (separator is both period and space). |
'' | Move to location of your last edit in the current file. |
]] | Move to next function (in c/java/c++/python) |
[[ | Move to previous function/class (in c/java/c++/python) |
Finally, if you can't move by searching, jumping, etc, you can still move with the keyboard, so put your mouse down.
h | move cursor to the left |
l | move cursor to the right |
k | move cursor up one line |
j | move cursor down one line |
^f | move forward one page |
^b | move backward one page |
You want to use the option
hls
(for "highlight search") in your vimrc. You will learn about that soon enough.In the short term you can type "
:set hls
" and press enter.
No comments:
Post a Comment