Vim's modes enable Vim to have sane keyboard shortcuts instead of Cmd + Shift + whatever the hell next. In Normal mode, w jumps to the next word. In Visual mode, w highlights from current cursor position to the next word. In Insert mode, well w types out the w character.
j goes down instead of up - is this an arbitrary decision? I think not? My intuition says it's down instead of up, and k is up instead of down, because we go down much more often then go up, and it makes sense to let the stronger middle finger do that.
Navigating up with k skips to start of paragraph?? This surprised me. I also got annoyed quickly not being able to move up a line by hitting k or h (left), which you can do in a normal text processor. I'm sure there is a way to do this I don't know about... Yes! b (move back one word, which is like the reverse of w) does something like that.
Motions are commands that you use in Normal mode for navigating faster. There must be a way to go back on cursor position up to the previous line, or something paradigm-shifting to do something similar...
e - end of next word
ge - end of previous word
w - next word
W - next WORD
f{character} - find next occurrence of character in same line
F{character} - find previous occurrence of character in same line
t{character} - till next occurrence of character in same line, but not further
T{character} - reverse of t{character}
; - next character search (e.g. fd then ; means fdfd)
, - previous character search (e.g. fd thhen , means fdFd)
0 - move to first character of a line
$ - move to last character of a line
^ - move to first non-blank character of a line
g_ - move to last non-blank character of a line
} - jump one paragraph down
{ - jump one paragraph up
Ctrl D - jump half page Down
Ctrl U - jump half page Up
/{pattern} + Enter - jump to next occurrence of pattern (regex OK)
?{pattern} + Enter - jump to previous occurrence of pattern
n - jump one occurrence in direction of previous command
N - jump one occurrence in opposite direction of previous command
gg - jump to top of file
G - jump to bottom of file
{line}gg - jump to specific file line
* - jump to next occurrence of word under cursor
# - jump to previous occurrence of word under cursor
Vim apparently doesn't just let you navigate around like you're wading around a bunch of text; it's able to let you navigate around taking into account the semantic meaning of the text.
For example, here's a very typical snippet of JavaScript:
const users = [
{ id: 1, name: "foo" },
{ id: 2, name: "bar" },
];
const userIds = users.map((u) => u.id);% - jump to end/start/end/start of nearest enclosing {} or [] or ()
gd - go to definition
In VS Code > User settings JSON, add this:
"vim.smartRelativeLine": true
With this I'm able to jump to very specific lines with {count}{command} pattern, like 21j brings me 21 lines down to the exact line I want. The cool part is that the 21 line number is relative to my current cursor position!
u - undo
Ctrl r - redo