Skip to content

VIM

Basic actions

To permanently apply the following, you can put them in the ~/.vimrc file in your home directory.

To display line numbers:

:set number

To remove line numbers:

:set nonumber

Save the file:

:w

Exit the file:

:q

Comment from line 1 to 8:

:1,8s/^/#

Uncomment from line 1 to 8:

:1,8s/^#/

Clipboard

Cut:

dd

Copy:

yy

Paste:

p

Paste before:

P

Editing

Append:

:a

Insert:

:i

Undo changes:

:u

Redo changes:

Ctrl + r

Search:

/$STRING_TO_SEARCH_FOR

Search a specific string:

/\<$STRING_TO_SEARCH_FOR\>

Search ignoring the case:

/$STRING_TO_SEARCH_FOR\c

Search and replace

:s/$STRING_TO_SEARCH_FOR/$STRING_TO_REPLACE_WITH/

Search and replace an entire file

:%s/$STRING_TO_SEARCH_FOR/$STRING_TO_REPLACE_WITH/

Go to specific line number:

:$LINE_NUMBER

Got to the first line:

gg

Got to the last line:

G

Go page up:

Ctrl + u

Go page down:

Ctrl + d

Go to the end of the current word:

e

Go to the beginning of the next word:

w

Go to the beginning of the previous word:

b

Go to the start of the line after whitespaces:

^

Go to the end of the line:

$

Navigate blocks of code:

# Move one code block up
Shift-{
# Move one code block down
Shift-}

Overall basic setup

Create a ~/.vimrc file:

set number
syntax enable
set laststatus=2
colorscheme default

Miscellaneous

Set password protection to a file:

vim -x $PATH_TO_THE_FILE

Vim plugins

vim-plug

vim-plug for Vim available here. Installed using the ~/.vimrc file provided in the overall basic setup section.

For automatic plugin install, add this to your ~/.vimrc file:

" Install vim-plug if not found
if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs),'!isdirectory(v:val.dir)'))
  \| PlugInstall --sync | source $MYVIMRC
\| endif

call plug#begin()
" The default plugin directory will be as follows:
"   - Vim (Linux/macOS): '~/.vim/plugged'

" Make sure you use single quotes

Plug 'junegunn/vim-plug'

" Initialize plugin system
call plug#end()