VIM Notes
VIM notes
-
Default starting mode of vim is NORMAL mode.
-
Open file:
vim <filename>
-
Enter command line mode:
-
::q- quit:q!- quit without saving:v- visual mode:w- save a fileZZ- save[if modified] and exit
Modify settings, save or quit file Features such as find and replace or help menu Press ESC to exit from insert mode and go to normal mode
-
-
Enter visual mode:
-
:vApply commands on selection of text Similar to clicking and dragging with mouse to highlight text Press ESC to exit from insert mode and go to normal mode
-
Navigation:
- `h - up
- `j - down
- `k - left
- `l - right
- `$ - end of line
0- beginning of lineCTRL + u- half page upCTRL + d- half page down:1- go to line number 1:2- go to line number 2:5- go to line number 5:set number- dispaly line numbering:set nonumber- hide line numberingv- Enter Visual mode
-
Arrow keys Highlight text in Visual mode
y- Yank (copy) selectionc- Change (cut) selectiond- Delete selectionp- Paste selection. Esc to enter normal mode to paste.ESC- Enter normal mode
-
-
Enter normal mode:
escUsed to read file/ navigating file Default at starting Accepts invisible commands
-
Enter insert mode:
iEdit text normally in this mode Press ESC to exit from insert mode and go to normal mode
OTHERS : -
i- Insert mode. Esc to normal mode. -o- Insert new line below -O- Insert new line above -I- Insert at beginning of line -A- Insert (append) at end of line -x- Delete character -dd- Delete line -2dd- Delete two lines -5x- Delete 5 characters -dG- Delete from cursor to end of file -d$- Delete from cursor to end of line -dgg- Delete from cursor to beginning of file -yy- Yank (copy) a line -
Information:
- Read about vim modes :
:h vim-modes
- Read about vim modes :
-
Build Efficiency
u- Undo (from normal mode)CTRL + r- Redo (from normal mode)/searchterm- Search for search-term. Add \c for case insensitive.n- Next instance of search-termN- Previous instance of search-term:%s/replaceme/withme/g- Replace "replaceme" with "withme" in the entire file:%s/replaceme/withme/gc- Replace "replaceme" with "withme" and prompt:set paste- Disable auto-indent upon paste:set nopaste- Re-enable auto-indent upon paste?searchterm- Search backwards in file for searchterm.- Repeat last change
-
VIMDIFF:
- Vimdiff
vimdiff <file1> <file2>- Compare file1 (left) and file2 (right)
]c- Go to next diff[c- Go to previous diffdp- Diff putdo- Diff get:diffupdate- Rescan files for changesCtrl + ww- Switch between split windows
- Vimdiff