Skip to content

Instantly share code, notes, and snippets.

@sabarnix
Forked from mithildeeva/Vim
Created July 12, 2019 10:57
Show Gist options
  • Save sabarnix/497663f8937f1955633568ce9e0405ed to your computer and use it in GitHub Desktop.
Save sabarnix/497663f8937f1955633568ce9e0405ed to your computer and use it in GitHub Desktop.
Vim handy commands
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