Have you ever heard about Vim before? Many people say that it's a powerfull text editor. I started to use this tool couple months ago and i enjoy it. I'm not a hardcore Vim user that knows all commands or good setup, but i just want to share how do i setup my Vim.
The Basic Tweak
I assume you guys already know (at least) about how to use Vim, like navigation, searching, etc, you can googling "Vim cheat sheet" to get an overview of all the commands. Here is the very basic setup:
set autoread
set backspace=indent,eol,start
set clipboard=unnamed
set cmdheight=2
syntax enable
set encoding=utf8
set expandtab
set ffs=unix,dos,mac
set foldmethod=indent
set foldlevel=99
set history=500
set incsearch
set laststatus=2
set list
set listchars=tab:>·,trail:~,extends:>,precedes:<,space:.
set mouse=nicr
set magic
set nocompatible
set number
set hidden
set ruler
set scrolloff=3
set shiftwidth=2
set smarttab
set synmaxcol=200
set tabstop=2
set wrap
filetype plugin indent on
As you can see, there are a bunch of set
command for each configuration settings, you can read the notes for each settings i set or you can check on Vim website for more details about the settings.
Try to copy and paste in your empty .vimrc
file if you're on *nix
system or _vimrc
on Windows, then try re-open your vim and edit a file, you'll see (at least) there's color on the text and dots for each spaces. It actually does a lot than you think since i just mention about color and dots, that's why i write a note for each settings so you can read it :D.
Let's move to the next phase, we'll set some shortcuts to interact inside Vim.
let mapleader = ","
let maplocalleader = ","
set termguicolors
nnoremap <leader>N :setlocal number!<cr>
nnoremap <leader>ss :w<cr>
nnoremap <leader>q :q!<cr>
nnoremap <leader>qa :qa!<cr>
let $MYVIMRC="/home/you_username/.vimrc"
nnoremap <leader>rv :source<Space>$MYVIMRC<cr>
nnoremap <leader>ev :tabnew $MYVIMRC<cr>
noremap <Leader>Y
noremap <Leader>P
imap <leader>q <Esc>
inoremap jj <Esc>
nnoremap <leader> z
nnoremap <leader>l :bn<cr>
nnoremap <leader>h :bp<cr>
nnoremap <leader>0 :bf<cr>
nnoremap <leader>9 :bl<cr>
nnoremap <leader>dd :bd<cr>
nnoremap tn :tabnew<Space>
nnoremap tk :tabnext<CR>
nnoremap tj :tabprev<CR>
nnoremap th :tabfirst<CR>
nnoremap tl :tablast<CR>
nnoremap tc :tabclose<CR>
command W w !sudo tee % > /dev/null
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>
vnoremap < <gv
vnoremap > >gv
" comma-1 insert "!
nnoremap <leader>1 :norm i!<cr>
vnoremap <leader>1 :norm i!<cr>
" comma-' insert """ commenting
nnoremap <leader>' :norm i
vnoremap <leader>' :norm i
" comma-3 insert "#
nnoremap <leader>3 :norm i#<cr>
vnoremap <leader>3 :norm i#<cr>
" comma-- insert "--
nnoremap <leader>- :norm i--<cr>
vnoremap <leader>- :norm i--<cr>
nnoremap <leader>6 :norm ^x<cr>
vnoremap <leader>6 :norm ^x<cr>
noremap Y y$
I set mapleader
with commad ( , )
, you can change it if you want. So, those shortcuts help me a lot to interact inside Vim, for example, i can press , + ev
to directly edit my .vimrc
file on new buffer and press , + ss
to save a file. It's easy right? But you might want to use :verbose imap <your_key>
to check is there a conflict for each key-mappings that has been set.
And the last phase for the basic setup is just a miscellaneous setup, you can read the notes for a little information.
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=.git\*,.hg\*,.svn\*
else
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
endif
set wildmode=list:longest
set path+=**
set wildmenu
set wildmode=list:longest,full
set lazyredraw
let g:netrw_banner=0
let g:netrw_browse_split=4
let g:netrw_altv=1
let g:netrw_liststyle=3
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
if $COLORTERM == 'gnome-terminal'
set t_Co=256
endif
set background=dark
if has("gui_running")
set guioptions-=T
set guioptions-=e
set t_Co=256
set guitablabel=%M\ %t
set cursorcolumn!
set guicursor=n-v-c:block-Cursor-blinkon0
set guicursor+=ve:ver35-Cursor
set guicursor+=o:hor50-Cursor
set guicursor+=i-ci:ver25-Cursor
set guicursor+=r-cr:hor20-Cursor
set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
endif
set directory=~/.vim/dirs/tmp
set backup
set backupdir=~/.vim/dirs/backups
set undofile
set undodir=~/.vim/dirs/undos
set viminfo+=n~/.vim/dirs/viminfo
if !isdirectory(&backupdir)
call mkdir(&backupdir, "p")
endif
if !isdirectory(&directory)
call mkdir(&directory, "p")
endif
if !isdirectory(&undodir)
call mkdir(&undodir, "p")
endif
This setup is actually not from my own experiment, but i do a lot of searching and pick one by one setup that i found and combine it. For now, let's stop here just for the basic setup, i'll continue on part 2 article for the complete setup.
I hope it is useful for you, and you can grab all phase configs from here.