-
-
Save sabarnix/497663f8937f1955633568ce9e0405ed to your computer and use it in GitHub Desktop.
Vim handy commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Copy/duplicate current line (on the next line) | |
- In normal mode, | |
:t. | |
2. Duplicate line on line 7 | |
- In normal mode, | |
:t 7 | |
3. Save changed file as sudo which was opened as a user with less access | |
:w !sudo tee % | |
Explanation | |
:w – write | |
!sudo – call shell sudo command | |
tee – the output of write (:w) command is redirected using tee | |
% – current file name | |
4. undo | |
- Normal mode | |
press 'u' | |
5. redo | |
- Normal mode | |
ctrl + 'r' | |
6. Search and replace | |
- Normal mode | |
:%s/foo/bar/gc | |
Change each(g) 'foo' to 'bar', but ask for confirmation(c) first. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment