Moving within Line
- First char of the line: 0
- First non-blank char of the line: ^
- First char of the line and put in insert mode: I
- Last char of the line: $
- Last non-blank char of the line: g_
- Last char of the line and put in insert mode: A
- top of the screen: H
- middle of the sceen: M
- bottom of the screen: L
- (mnemonics are High, Medium, Low)
- current line to top, middle and bottom: zz vs zt vs zb
- scroll one line: ctrl+y and ctrl+e -> cursor does not move (with j and k, cursor moves)
- scroll half-page: ctrl+u and ctrl+d
- scroll full-page :ctrl+b and ctrl+f
- Search for word currently on: * -> this will search forwards
- Search for word currently on: # -> this will search backwards
- viw to visually select the word under the cursor.
Searching replacing copy pasting
- % means do this for every line
- s means sed, or search and replace
- g at the end means replace every ipsum with lorem; if you omit this, it only replaces the first.
ye (yank to end of word)
Substitute a word in-place
If you yank the first word with
yiw, you can then replace another word with the first one by typing
If you leave out the i,
yw will also yank the whitespace after your word and when pasting this you get too much spaces. Therefore, use i to select the inner word.
viwp is also very intuitive. Visually select the inner word and then paste it with the yanked.
iw meaning inner word as in word without surrounding spaces.
surround word with ” or “” -> ciw””EscP
Goto the start of the word. Type c i w ” ” Esc P without the spaces in between. This will surround the word with “”. Replace “” with ” for ”.
Word Wise navigation: e vs E, b vs B, w vs W
see here for a very nice implementation: https://github.com/tpope/vim-surround
making vim macros