Vim Tips and Tricks

Published:
4 minute read

Vim Configuration

  • Copy the content of the file .vimrc to your ~/.vimrc
  • After completing Vundle setup, install your desired plugins, then launch vim and run :PluginInstall

Plugin for Vim-Markdown-Preview

Add Plugin 'JamshedVesuna/vim-markdown-preview' to your .vimrc. Launch vim and run :PluginInstall

There are some requirements, and you have to install pip first:

sudo apt-get install python-pip python3-pip --yes
sudo python3 -m pip install pip --upgrade --force-reinstall
sudo python -m pip install pip --upgrade --force-reinstall

Install grip (for GitHub flavoured markdown) with the following:

sudo pip install grip

Put let vim_markdown_preview_github=1 in your .vimrc file

Install xdotool with:

sudo apt-get install xdotool

Vim commands (summary)

#CommandDescription
1iinsert mode
2x,Xdelete one char
3o,Oinsert new line and go to insert mode
4Jjoin the current line with its next one
5rreplace one character
6aappend
7uundo
8ddelete (dw, dd, d$, d^, ..)
9Ggo to line (10G, 1G, G)
10yyank/copy (yy, yw, y$, ..)
11p,Ppaste
12/xsearch for x (n, N)
13$end of line
14^start of line
15.repeat
16%swap to closing/opening bracket
17vvisual mode, enter, and then run command
18split/HexploreHorizontal split/explore[1]
19Vsplit/Vexplorevertical split/explore
20!run OS commands
21!!run OS commands and write the output
22s/a/breplace a by b
23:%s/a/b/greplace a by b in entire file
24:12,20s/a/b/greplace a by b in lines 12-20
25:15,23s/^/\/\//gcomment lines 15-23
26:15,23s/\/\/uncomment lines 15-23
27gg=GAuto Indent the source file

Some note about #18:

  • To change between windows -> Ctrl+w, up/down/left/right
  • To open current file in split horizontal view -> Ctrl+w, s
  • To open current file in split vertical view -> Ctrl+w, v

Some other useful plugins

  • Directory tree
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree

Vimrc file

~/.vimrc possible contents:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" Plugin 'Valloric/YouCompleteMe'

Plugin 'JamshedVesuna/vim-markdown-preview'

Plugin 'godlygeek/tabular'

Plugin 'plasticboy/vim-markdown'

" All of your Plugins must be added before the following line
Plugin 'Valloric/YouCompleteMe'

call vundle#end()            " required
filetype plugin indent on    " required

" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
set tabstop=4       " The width of a TAB is set to 4.
                    " Still it is a \t. It is just that
                    " Vim will interpret it to be having
                    " a width of 4.

set shiftwidth=4    " Indents will have a width of 4

set softtabstop=4   " Sets the number of columns for a TAB

set noexpandtab     " Expand TABs to spaces
set smarttab
set smartindent
set cindent
set autoindent
set showmatch
set history=1000
set undolevels=1000
set visualbell
set noerrorbells
set foldmethod=indent
set foldlevel=99
set number
set tags=tags       " This is to use ctags
set mouse=a

colorscheme ron

let vim_markdown_preview_github=1

" clang-format can be found at this address:
" https://github.com/rhysd/vim-clang-format
"
" follow instruction to install clang-format 
" and then uncomment these lines:
" let g:clang_format#code_style = 'google'
" let g:clang_format#style_options = {
"     \ 'TabWidth' : 4,
"     \ "ColumnLimit' : 100,
"     \ 'IndentWidth' : 4,
"     \ 'IndentCaseLabels' : 'true',
"     \ 'NamespaceIndentation' : 'All',
"     \ 'Standard' : 'Auto'}