Tips & Tricks from Vim 101 Hacks
Ctrl + E: Scroll down one line
Ctrl + Y: Scroll up one line
word vs WORD
wordconsists of a sequence of letters, digits and underscores.
WORDconsists of a sequence of non-blank characters, separated with white space.
192.168.1.3 contains 7 words. But the whole
considered as one WORD.
Position cursor at specific location within a line
0 ^ line_content g_ $
0: Go to the starting of current line.
$: Go to the end of current line.
^: To to the first non-blank char of current line.
g_: Go to the last non blank character of current line.
H: First line of current screen. (
M: Middle line of current screen.
L: Last line of current screen.
Redraw screen with current line on Top/Bottom/Middle
||Redraw the screen with current line under the cursor at the top of the screen|
|z-||Redraw the screen with current line under the cursor at the bottom of the screen|
|z.||Redraw the screen with current line under the cursor at the middle of the screen|
Go to Top/Bottom of the File
- Go to the top:
- Go to the bottom:
Vim command line navigation
||Go to the 143rd line of file|
||Go to the first match of the specified search term from top|
|vim +?search-term||Go to the first match of the specified search term from|
|vim -t TAG||Go to the specific tag|
Basic Text Manipulation
Insert or Append Text
|:r FILENAME||Insert another file content into current file after the current line|
|:r! COMMAND||Insert output of a command into current file after the current line|
Paste before or affter the copied Line/Word/Others
:reg => Show all recent register
Recent deleted content will appear in 0 - 9 register. If you would like to paste the word from the register number 3, execute the following:
Or paste clipboard content to editor in normal mode:
Expert Text Manipulation
Sort File Content
:sort # sort visual block :'<,'>!sort :sort! # Sort in descending order :sort i # Ignore case while sorting :sort u # Remove duplicate lines. U stands for unique
Vim Command Line Hacks
# Open file in Readonly mode vim -R filename.txt # Skip loading Plugins Temporarily vim --noplugin filename.txt # Edit multiple files in Tabs vim -p file1 file2 file3
Encrypt File in Vim
Enter encryption key. Next time you open that file, Vim will prompt for the encryption key.
Review the Differences between Files using Vimdiff
vimdiff file1 file2
Default registers and their users
|%||Name of the current file|
|#||Name of the alternate file|
|:||Most recent executed command line|
|/||Last search pattern|
|“||Last used registers|
Search across Multiple Files using vimgrep
:vimgrep jason *.txt # Use :cn to jump to the next match # Use :clist to view all the files that matched the vimgrep search keyword