Vim

Publish Date: Apr 25, 2017    Last Update: Oct 31, 2018

1. Basic use

## most basic 
h, j, k, l    character navigation
w, e, b       word navigation
0, $          go to the beginning/end of a line
/             to search, n for next result, N for prev result
x, r          x to del a charater, and r to replace a character
.             to repeat last action

## useful
*, #          find the next/prev word under cursor
%             go to matching parentheses
{}            jump to next paragraph
<C-o>         jump to previous location (file)
ggVG=         quick formating
gq            format selected line (visual mode)

## split screen
:new          create a new screen 
:split        (horizontally) split the current file into two screens
:vsplit       vertically split the current file into two screens
ctrl+w        choose
:qall         close all screens
:3split       the new screen will have 3 rows
ctrl+w +      increase the height of the screen
:only         only keep the current window 

## spell checking
:set spell    turn on spell check
:set nospell  turn off spell check
]s            move to next error
[s            move to previous error 
zg            add the current word to the dictionary 
zug           undo adding to the dictionary
z=            open the spelling suggestions

2. vimrc

I use vundle to manage all the plugins. My vimrc file is hosted on github, and available upon request. Currently I use the following plugins:

  1. nerdtree
  2. vim-indent-guides
  3. goyo
  4. vim-gitgutter
  5. vim-easymotion
  6. vim-fugitive
  7. vim-syntastic
  8. neocomplete.vim
  9. lightline.vim
  10. vim-markdown
  11. vim-colorshcemes
  12. ack.vim
  13. vim-markdown-preview

My vimrc file is shown below. I current use github to store all my vim configurations and might open-source it in the future.

" description:    vim config file
" author:         Bruce / yuan@bruceyli.com
" date:           2018-03-19

" -----------------------------------------------------------
" setup Vundle 
set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'

" -----------------------------------------------------------
" basic config
set spell   " enable spell checking
set number  " line number
set cc=80   " a colored line at 80
set tw=79   " maximum line width is 79
set ts=2    " tab as two spaces
set et      " tab as spaces
set sw=2    " shift width 2 
set fo+=mB  " for chinese line break
set sts=2   " make space feel like tabs
set backspace=indent,eol,start
set nobackup
set nowritebackup

" -----------------------------------------------------------
" global keyboard mapping
" <L><L>w - highlight all words below
" <L><L>f - search a single character
" <L>ig   - indent guides
" <L>tm   - enable table mode
" <L>tdd  - delete a row of a table
" <L>tdc  - delete a column of a table
" ge      - open the link
" gx      - open the link in browser
" ]] / [[ - go to next/previous header
" ][ / [] - go to next/previous sibling header
" ]c / ]u - go to current/parent header
" }/{     - jump to next previous paragraph
" <C-o>   - jump to previous visited file
" <C-p>   - open markdown preview

" splitting
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
set splitbelow
set splitright

" -----------------------------------------------------------
" user plugins 
" 1 - file manager
    Plugin 'scrooloose/nerdtree'

" 2 - indent help
    Plugin 'nathanaelkane/vim-indent-guides'

" 3 - focus mode
    Plugin 'junegunn/goyo.vim'

" 4 - git status
    Plugin 'airblade/vim-gitgutter'

" 5 - easy move
    Plugin 'easymotion/vim-easymotion'

" 6 - git wrapper
    Plugin 'tpope/vim-fugitive'

" 7 - syntax checking
    Plugin 'vim-syntastic/syntastic'

" 8 - auto compelte
    Plugin 'Shougo/neocomplete.vim'

" 9 - status bar
    Plugin 'itchyny/lightline.vim'
    
" 10 - markdown
    Plugin 'plasticboy/vim-markdown'

" 11 - colorscheme
    Plugin 'flazz/vim-colorschemes'

" 12 - ack.vim
    Plugin 'mileszs/ack.vim'

" 13 - markdown preview
    Plugin 'JamshedVesuna/vim-markdown-preview'

" 14 - grammar check
    Plugin 'rhysd/vim-grammarous'

" 15 - table-mode
    Plugin 'dhruvasagar/vim-table-mode'

" -----------------------------------------------------------
" post config

call vundle#end()
filetype plugin indent on
colorscheme sierra
set shell=/bin/bash
syntax on

" -----------------------------------------------------------
" plugin config

" nerdtree
    let NERDTreeAutoDeleteBuffer = 1
    let NERDTreeMinimalUI = 1
    let g:NERDTreeDirArrowExpandable = '+'
    let g:NERDTreeDirArrowCollapsible = '-'
    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" syntax
    set statusline+=%#warningmsg#
    set statusline+=%{SyntasticStatuslineFlag()}
    set statusline+=%*
    
    let g:syntastic_always_populate_loc_list = 1
    let g:syntastic_auto_loc_list = 1
    let g:syntastic_check_on_open = 1
    let g:syntastic_check_on_wq = 0
    
    let g:syntastic_python_checkers = ['flake8']
    let g:syntastic_python_flake8_args = '--ignore="E265,E111"'

" status bar
    let g:lightline = {
          \ 'colorscheme': 'wombat',
          \ }
    set laststatus=2

" markdown
    let g:vim_markdown_folding_level = 1
    let g:vim_markdown_math = 1
    let g:vim_markdown_frontmatter = 1
    let g:vim_markdown_toc_autofit = 1
    let g:vim_markdown_no_extensions_in_markdown = 0
    let g:vim_markdown_autowrite = 1

" markdown-preview
    let vim_markdown_preview_temp_file = 0
    let vim_markdown_preview_hotkey = '<C-p>'
    let vim_markdown_preview_use_xdg_open = 1
    let vim_markdown_preview_github = 1

" vim-table-mode
    let g:table_mode_corner='|'
    let g:table_mode_delimiter = ' '