Five minutes tutorial to be a VIMer!
Hold on, I am indeed a follower of EMACS cult :) but VIM was the first editor I learned. Why do I need to learn to use an editor, one might say. Surely, writing in Microsoft or Google Doc, we don't have to. Why is VIM special? Let's dive into it.
Magic mode
Once you open VIM, you are in a magic mode called normal mode
officially. I
prefer to call it magic mode
where every keystroke is magic, which is why you
can't type like the normal. To type like the normal, you need to enter the
insert mode
from magic mode
by pressing magical key such as i
. Then you need
to use Ctrl+[
or ESC
to go back to magic mode
. What can I benefit from magic
mode
? Why do I need to learn the abnormal behavior? Short answer is making
editing more efficient. Oh, btw, you can exit VIM only from magic mode
by
pressing :q
.
Fast movement
In magic mode
, you can move by words with b
, w
, e
, B
, W
, E
keys; move by
sentence with (
and )
; move by paragraph with {
and }
; find chars linewise
with f
, F
, t
, T
. no longer use arrow key instead using h
, j
, k
, l
which all
located right in the center of QWERTY
keyboard layout; If you use another
different keyboard layout eg DVORAK
, you have the absolute control to
customize the key map.
Key mapping
A good editor should be extendable and customized, so is VIM
.
My minimal vim configuration
let mapleader=" "
let maplocalleader = ','
syntax on
set number
set relativenumber
set cursorline
set wrap
set showcmd
set wildmenu
set autochdir
set hlsearch
exec "nohlsearch"
set incsearch
set ignorecase
set smartcase
set nocompatible
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on
set mouse=a
set encoding=utf-8
let &t_ut=''
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set list
set listchars=tab:▸\ ,trail:▫
set scrolloff=5
set tw=0
set indentexpr=
set backspace=indent,eol,start
set foldmethod=indent
set foldlevel=99
noremap H ^
noremap L $
map _ %
nnoremap <Leader>bb :ls<CR>:b<Space>
noremap <LEADER>ee :e $MYVIMRC<CR>
noremap <C-S> :w<cr>
inoremap <C-S> <ESC>:w<cr>
noremap Q :q<CR>
noremap R :source $MYVIMRC<CR>
inoremap <C-b> <left>
inoremap <C-j> <down>
inoremap <C-k> <up>
inoremap <C-f> <right>
inoremap <c-a> <home>
inoremap <c-e> <end>
inoremap <c-d> <del>
inoremap <c-x><c-a> <c-a>
inoremap <c-x><c-b> <c-e>
map sl :set splitright<CR>:vsplit<CR>
map sk :set nosplitright<CR>:vsplit<CR>
map sh :set nosplitbelow<CR>:split<CR>
map sj :set splitbelow<CR>:split<CR>
map sv <C-w>t<C-w>H
map sh <C-w>t<C-w>K