-
-
Save mithildeeva/ddb0a7ff746be88cf286fc1d9e2ec097 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. | |
7. Edit multiple lines together. Eg. : add character 'asd' in the beginning of each line | |
https://stackoverflow.com/questions/9549729/vim-insert-the-same-characters-across-multiple-lines | |
- Normal mode | |
- move cursor to first line to edit | |
- enable VISUAL BLOCK mode (ctrl + v) | |
- press I (capital i) for insert mode | |
- edit the single line | |
- press esc (changes will reflect on all line selected in VISUAL Block mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment