Vim pro tips
Copy (yank)#
- yy - Yank the current line, including the newline character.
- 3yy - Yank three lines, starting from the line where the cursor is positioned.
- y$ - Yank everything from the cursor to the end of the line.
- y^ - Yank everything from the cursor to the start of the line.
- yw - Yank to the start of the next word.
- yiw - Yank the current word.
- y% - Yank to the matching character. By default supported pairs are (), {}, and []. Useful to copy text between matching brackets.
Cut (Delete)#
- dd - Delete the current line, including the newline character.
- 3dd - Delete three lines, starting from the line where the cursor is positioned,
- d$ - Delete everything from the cursor to the end of the line.
Paste#
To put the yanked or deleted text, move the cursor to the desired location and press p to put (paste) the text after the cursor or P to put (paste) before the cursor.
Find and Replace - https://linuxize.com/post/vim-find-replace/#
1 | |
Replace first occurrence of foo with bar in the current line
1 | |
Replace all occurrences of foo with bar in the current line
1 | |
Replace all occurrences of foo with bar in the file
1 | |
You can also use any non-alphanumeric single byte character as a delimiter, which is helpful if you need to look for /
1 | |
If you want to confirm every replacement, use c as a flag. The following command will ask for each replacement on the current line
1 | |
By default it is case sensitive. Use i as a flag to make it insensitive. The following will replace all occurences of Foo with bar, but including foo, FOO, fOo, etc.
1 | |
Last update:
2023-05-28 13:02:55