Skip to content
Rohit Farmer edited this page Jun 21, 2019 · 4 revisions

General VIM Usage

Leader

In this vimrc ',' a comma is the leader.

Delete

dd to delete the current line.
3dd to delete 3 lines starting from your cursor line.

Undo and Redo

u undo
ctr r redo

Search

/searchterm to search. m to navigate to the next position. M to navigate to the previous position.
%s/searchterm/replaceterm/g search and replace globally. If you don't use g then it will only replace the first instance only. Use c with g for vim to ask you every time it replaces the next search term.

Indentations

ctrl + t, ctrl + d Indent current line forward, backwards (insert mode).
shift >>, shift << Indent current line/block forward, backwards (normal mode and visual mode).

Tab Windows

vim -p test.py test.R opens multiple files in their respective tabs.
more information at https://vim.fandom.com/wiki/Using_tab_pages

Navigating Tab Windows

<leader>tnew To open new tab window.
<leader>to To only keep the current tab and close the rest.
<leader>tc To close the current tab.
<leader>tm To move to the next tab.
<leader>tn To move to the next tab.
<leader>tp To move to the previous tab.

Split Screen

Split Screen Vertically

ctrl + w v or :vsplit
ctrl + w w To navigate in between the split screens.
ctrl + w l To move to the left screen.
ctrl + w h To move to the right screen.

Split Screen Horizontally

:split or ctrl + w s
ctrl + w j To move to the bottom screen.
ctrl + w k To move to the top screen.

Open Multiple Files in Split Screens

vim -o file1 file2 Opens files in horizontal split screens.
vim -O file1 file2 Opens files in vertical split screens.