You are on page 1of 6

VIM CHEATSHEET powered by @Archit

1. Write down a list of different Vim Shortcuts/Commands and mention briefly their usage.

Note: For using commands, make sure that the vim operates in either Escape mode or the
Visual mode. For entering into the Escape mode we need to press the ‘Escape’ key only and
for the Visual mode we need to press the ‘CTRL + q’ key.

Sl No. Commands Description


1 :x Quit vi, writing out modified file to file named in original invocation
2 :wq Quit vi, writing out modified file to file named in original invocation
3 :w Save the file
4 :q Quit or exit
5 :q! Quit vi even though latest changes have not been saved for this vi call
6 j [or down- Move cursor down one line
arrow]
7 k[or up-arrow] Move cursor up one line
8 h [or left-arrow] Move cursor left one line
9 l [or right- Move cursor right one line
arrow]
10 0(zero) Move cursor to start of current line(the one with the arrow)
11 $ Move cursor to end of the current line
12 w Move cursor to beginning of next word
13 b Move cursor back to beginning of preceding word
14 :0<return> or Move cursor to first line in file
1G
15 :n<return>or nG Move cursor to line n in file
16 :$<return>or G Move cursor to last line in file
17 Ctrl + f Move forward one screen
18 Ctrl + b Move backward one screen
19 Ctrl + d Move down(forward) one half screen
20 Ctrl + u Move up(back)one half screen
21 Ctrl + l Redraws the screen
22 Ctrl + r Redraws the screen, removing the deleted lines
23 u Undo whatever you just did(a simple toggle)
24 i Insert text before cursor, until<esc>hit
25 I Insert text at beginning of current line, until<esc>hit
26 a Append text after cursor, until<esc>hit
27 A Append text to end of current line, until<esc>hit
28 o Open and put text in a new line below current line, until<esc>hit
29 O Open and put text in a new line above current line, until<esc>hit
30 r Replace single character under cursor(no <esc>needed
31 R Replace characters, starting with current cursor position, until<esc>hit
32 cw Change the current word with new text, starting with the character
under cursor, until<esc>hit
33 cNw Change N words beginning with the character under cursor,
until<esc>hit
34 c change(replace)the characters in the current line, until<esc>hit
35 cc change(replace)the characters in the current line, stopping when
<esc>hit
36 Ncc or cNc change(replace)the next N lines, starting with the current line, stopping
when <esc>hit
37 x Delete single character under cursor
38 Nx Delete N characters, starting with character under cursor
39 dw Delete the single word beginning with character under cursor
40 dNw Delete N words beginning with character under cursor
41 D Delete the remainder of the line, starting with current cursor position
42 dd Delete entire current line
43 Ndd or dNd Delete N lines beginning with the current line
44 yy Copy (yank, cut) the current line into buffer
45 Nyy oy yNy copy(yank, cut) the next N lines, Including the current line, into the
buffer
46 p put(paste) the lines in the buffer into the text after the current line
47 /string Search forward for occurence of string in text
48 ?string Search backward for occurence of string in text
49 n Move to next occurence of search string
50 N Move to next occurence of search string in opposite direction
51 :.= Returns line number of current line at bottom of screen
52 := Returns the total number of lines at bottom of the screen
53 Ctrl + g Provides the current line number, alongwith the total number of lines, in
the file at the bottom of the screen
54 :ls List all open buffers
55 Ctrl + ws Split windows horizontally
56 Ctrl + wv Split windows vertically
57 Ctrl + ww Switch between windows
58 Ctrl + wq Quit a window
59 :tabnew Creates a new tab
60 gt Show next tab
61 :tabfirst Show first tab
62 :tablast Show last tab
63 :tabm Reaarange tabs
n(position)
64 :tabdo Execute a command in all tabs
%s/foo/bar/g
65 :tab ball Puts all open files in tabs
66 :new abc.txt Edit abc.txt in new window
67 gf Open your files under the cursor
68 gi Restarts the insert mode in the last inset point you used
69 /\c Lets users search for texts in a case sensitive manner
70 :sp Create a new file in Horizontal mode
71 :vsp Creaye a new file in Vertical mode
72 :bn Switch your editor to the next buffer
73 :help Gives relevant information about the command we want to search
[command]
74 :stop Suspend your current vim session
75 :%!fmt Align each line of your current file

2. Write down a list of minimum 50 vimrc commands which may be needed permanently.

For making any changes in vimrc file first copy it some other directory instead of home
directory so that desired changes can be done. After doing that paste the modified vimrc in
place of original vimrc in the home directory.
Sl No. Command Description
1 Set autoindent New lines inherit the indentation of previous lines
2 Set expandtab Convert tabs into spaces
3 Set filetype indent on Enable indentation rules that are file-type specific
4 Set shiftround When shifting lines, round the indentation to the nearest multiple of
“shiftwidth”
5 Set shiftwidth=4 When shifting, indent using four spaces
6 Set smarttab Insert “tabstop” number of spaces when the “tab” key is pressed
7 Set tabstop=4 Indent using four spaces
8 Set hlsearch Enable search highlighting
9 Set ignorecase Ignore case when searching
10 Set incsearch Incremental search that shows partial matches
11 Set smartcase Automatically switch search to case-sensitive when search query
contains an uppercase letter
12 Set complete-=i Limit the files searched for auto-completes
13 Set lazyredraw Don’t update screen during macro and script execution
14 Set display+=lastline Always try to show a paragraph’s last line
15 Set encoding=utf-8 Use an encoding that supports Unicode
16 Set linebreak Avoid wrapping a line in the middle of a word
17 Set scrolloff=1 The number of screen columns to keep to the left and right of the
cursor
18 Syntax enable Enable syntax highlighting
19 Set wrap Enable line wrapping
20 Set laststatus=2 Always display the status bar
21 Set ruler Always show cursor position
22 Set wildmenu Display command line’s tab complete option as a menu
23 Set tabpagemax=50 Maximum number of tab pages that can be opened from the command
line
24 Set colorscheme <color> Change color scheme
25 Set cursorline Highlight the line currently under cursor
26 Set number Show the line numbers on the sidebar
27 Set relativenumber Show the line number on the current line and relative numbers on all
other lines
28 Set noerrorbells Disable beep on errors
29 Set visualbell Flash the screen instead of beeping on errors
30 Set mouse=a Enable mouse for scrolling and resizing
31 Set title Set the window’s title, reflecting the file currently being edited
32 Set background=dark Use colors that suit a dark background
33 Set foldmethod=indent Fold based on indentation levels
34 Set foldnestmax=3 Only fold up to three nested levels
35 Set nofoldenable Disable folding by default
36 Set autoread Automatically re-read files if unmodified inside Vim
37 Swt Allowbackspacing over indentation, line breaks and insertion start
backspace=indent,eol,start
38 Set bakupdir=~/.cache/vim Directory to store backup files
39 Set confirm Display a confirmation dialog when closing an unsaved file.
40 set dir=~/.cache/vim Directory to store swap files
41 Set formatoptions+=j Delete comment characters when joining lines
42 Set hidden Hide files in the background instead of closing them
43 Set history=1000 Increase the undo limit
44 Set nomodeline Ignore file’s mode lines; use vimrc configurations instead
45 Set noswapfiles Disable swap files
46 Set nrformats-=octal Interpret octal as decimal when incrementing numbers
47 Set shell The shell used to execute commands
48 Set spell Enable spell checking
49 Set wildignore+=.pyc,.swp Ignore files matching these patterns when opening files based on a
glob pattern
50 Set autowrite Automatically save before command like :next and :make
3. Install minimum 5 Plugins and describe briefly about each one.

A plugin is a way to extend vim's functionality.


Vim categorizes plugins into "global" plugins (which load and operate unconditionally) and
"filetype" plugins (which only load and operate for specific file types, see :help filetype). Vim
looks for plugins in specific locations, assuming you have not altered the runtime path
(manually or with plugins like Pathogen or Vundle).

The methods that I have used is PlugInstall method. The steps of installation are given
below:
• First of all we need to install ‘vim.plug’ in our home directory, for that we need to
make a directory in our $HOME folder where all the vim files are stored. To know
the location of the vim’s home directory just type ‘:echo $HOME’ in vim, it will give
you the home file path.
• Or we can run the following lines of codes in the windows powershell:
md ~\vimfiles\autoload
$uri = 'https://raw.githubusercontent.com/junegunn/vim-
plug/master/plug.vim'
(New-Object Net.WebClient).DownloadFile(
$uri,

$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSP
ath(
"~\vimfiles\autoload\plug.vim"
)
)
• After creation of home directory, next we need to go to our vimrc and perform the
following steps:
➢ begin the selection with ‘call plug#begin()’
➢ List all the Plug commands (for example: Plug 'morhetz/gruvbox')
➢ ‘call plug#end()’ to update &runtimepath and initialize plugin system
• Now type’:PlugInstall’ in the vimrc and wait for the plugins to finish installing.

Sl No. Plugins Description


1 Gruvbox

2 Grep Plugin to integrate various grep like search tools


with Vim.
The grep plugin integrates grep like utilities (grep,
fgrep, egrep, agrep, findstr, silver searcher (ag),
ripgrep, ack, git grep, sift, platinum searcher and
universal code grep) with Vim and allows you to
search for a pattern in one or more files and jump to
them.
3 Vim-fugitive Fugitive is the premier Vim plugin for Git. Or maybe
it's the premier Git plugin for Vim? Either way, it's
"so awesome, it should be illegal". That's why it's
called Fugitive.

The crown jewel of Fugitive is :Git (or just :G), which


calls any arbitrary Git command. If you know how to
use Git at the command line, you know how to use
:Git. It's vaguely akin to :!git but with numerous
improvements
4 Typescript-vim So, installing Tsuquyomi, your vim gets the
following features provided by TSServer:

Completion (omni-completion)
Navigate to the location where a symbol is defined.
Show location(s) where a symbol is referenced.
Display a list of syntax and semantics errors to Vim
quickfix window.
and so on,,,
5 Ctrlp.vim Full path fuzzy file, buffer, mru, tag, ... finder for Vim.

Written in pure Vimscript for MacVim, gVim and


Vim 7.0+.
Full support for Vim's regexp as search patterns.
Built-in Most Recently Used (MRU) files monitoring.
Built-in project's root finder.
Open multiple files at once.
Create new files and directories.
Extensible.
6 Undotree The plug-in visualizes undo history and makes it
easier to browse and switch between different undo
branches. You might wonder what is undo
"branches"? It's vim feature that allows you to go
back to a state when it is overwritten by a latest edit.
For most editors, if you make a change A, then B,
then go back to A and make change C, normally you
won't be able to go back to B because undo history is
linear. That's not the case for Vim because it
internally keeps all the edit history like a tree
structure, and this plug-in exposes the tree to you so
that you not only can switch back and forth but also
can switch between branches.
7 Supertab Supertab is a vim plugin which allows you to use
<Tab> for all your insert
completion needs (:help ins-completion).
8 verilog_systemverilog.vim Besides some bug corrections, the following features
were added to this set of scripts:
Omni completion.
Configurable syntax folding.
Matchit settings to support Verilog 2001 and
SystemVerilog.
Error format definitions for common Verilog tools.
Commands for code navigation.
9 Nerdtree The NERDTree is a file system explorer for the Vim
editor. Using this plugin, users can visually browse
complex directory hierarchies, quickly open files for
reading or editing, and perform basic file system
operations.

This plugin can also be extended with custom


mappings using a special API. The details of this API
and of other NERDTree features are described in the
included documentation.
10 Syntastic Syntastic is a syntax checking plugin for Vim created
by Martin Grenfell. It runs files through external
syntax checkers and displays any resulting errors to
the user. This can be done on demand, or
automatically as files are saved. If syntax errors are
detected, the user is notified and is happy because
they didn't have to compile their code or execute
their script to find them.

You might also like