Skip to content

Instantly share code, notes, and snippets.

@ZhengRui
Last active January 23, 2017 09:24
Show Gist options
  • Save ZhengRui/b4c2f23970ff1cce6c26afdafe3c5f5a to your computer and use it in GitHub Desktop.
Save ZhengRui/b4c2f23970ff1cce6c26afdafe3c5f5a to your computer and use it in GitHub Desktop.
ubuntu14.04 vim and neovim configuration
" add for vundle
set nocompatible
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'bling/vim-airline'
Plugin 'altercation/vim-colors-solarized'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'mattn/emmet-vim'
Plugin 'sukima/xmledit'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'majutsushi/tagbar'
Plugin 'fatih/vim-go'
Plugin 'bitc/vim-bad-whitespace'
Plugin 'ap/vim-css-color'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'luochen1990/rainbow'
Plugin 'kien/ctrlp.vim'
Plugin 'jeetsukumaran/vim-buffergator'
Plugin 'Glench/Vim-Jinja2-Syntax'
Plugin 'pangloss/vim-javascript'
Plugin 'Raimondi/delimitMate'
call vundle#end()
filetype plugin indent on
set encoding=utf-8
execute pathogen#infect()
set background=dark
set t_Co=256
set colorcolumn=80
set cursorline
let g:solarized_termcolors=16
let g:solarized_termtrans=0
call togglebg#map("<F5>")
colorscheme solarized
" trivial settings
syntax on
set ts=4
set backspace=indent,eol,start
set autoindent
set smartindent
set nu hlsearch is expandtab
set sw=4
set shiftround
set smarttab
set showmatch
set ignorecase
set smartcase
set ruler
set timeoutlen=1000
hi CursorLineNr ctermbg=15 ctermfg=5
imap jk <Esc>
let mapleader=" "
" Whitespace settings
set list listchars=tab:▸\ ,eol:¬,trail:∙
fun! ToggleWhitespace()
ToggleBadWhitespace
if &list
set nolist
else
set list listchars=tab:▸\ ,eol:¬,trail:∙
endif
endfun
nmap <Leader>tw :cal ToggleWhitespace()<cr>
" Invisible character colors
hi NonText ctermfg=236
hi SpecialKey ctermfg=236
" disable arrow keys
" noremap <Up> <NOP>
" noremap <Down> <NOP>
" noremap <Left> <NOP>
" noremap <Right> <NOP>
" noremap h <NOP>
" noremap l <NOP>
" insert mode controlenhancements
imap <c-f> <Right>
imap <c-b> <Left>
" copy to X11 buffer
set clipboard=unnamed
" for buffer operations
set hidden
au BufRead,BufNewFile *.md set filetype=markdown
" after PluginInstall of ycm, you need to compile it, check github page
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf = 0
" let g:ycm_error_symbol = '✗'
" let g:ycm_waring_symbol = '!'
" for switching between splits
set splitbelow
set splitright
set wmh=0
nmap <c-j> <c-w>j
nmap <c-k> <c-w>k
nmap <c-h> <c-w>h
nmap <c-l> <c-w>l
nmap <Leader>sv :vsplit<cr>
nmap <Leader>sh :split<cr>
nmap <Leader>= :resize +5<cr>
nmap <Leader>- :resize -5<cr>
nmap <Leader>] :vertical resize -5<cr>
nmap <Leader>[ :vertical resize +5<cr>
" for vim-airline, need to install
" powerline prepatched fonts so that
" arrow display correctly
set laststatus=2
let g:airline_powerline_fonts = 1
let g:airline_theme = "powerlineish"
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
" disable conceal for tex files
let g:tex_conceal = ""
" Tagbar coolness
nmap <Leader>tt :TagbarToggle<cr>
let g:tagbar_left = 0
let g:tagbar_width = 20
" NERDTree
" au VimEnter * NERDTree " open NERDTree when vim starts
let g:NERDTreeShowBookmarks = 1
let g:NERDTreeWinSize = 20
nmap <Leader>tn :NERDTreeToggle<cr>
" nerdcommenter add spacedelims
let g:NERDSpaceDelims = 1
" easy motion MADNESS
let g:EasyMotion_smartcase = 1
let g:EasyMotion_startofline = 0 " keey cursor column when JK motion
nmap <Leader><Leader>j <Plug>(easymotion-j)
nmap <Leader><Leader>k <Plug>(easymotion-k)
nmap <Leader><Leader>h <Plug>(easymotion-linebackward)
nmap <Leader><Leader>l <Plug>(easymotion-lineforward)
" repeat last easymotion madness
nmap <Leader><Leader>. <Plug>(easymotion-repeat)
" rainbow parentheses beautifulness
let g:rainbow_active = 1
let g:rainbow_conf = {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['darkblue', 'darkgreen', 'darkyellow', '133'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'lisp': {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'css': 0,
\ }
\}
" CtrlP
nmap <Leader>p :CtrlP<cr>
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](\.(git|hg|svn)|\_site)$',
\ 'file': '\v\.(exe|so|dll|class|png|jpg|jpeg)$',
\}
let g:ctrlp_working_path_mode = 'ra'
nmap <Leader>bb :CtrlPBuffer<cr>
nmap <Leader>bm :CtrlPMixed<cr>
nmap <Leader>bs :CtrlPMRU<cr>
" Ignore some defaults
set wildignore=*.o,*.obj,*~,*.pyc
set wildignore+=.env
set wildignore+=.env[0-9]+
set wildignore+=.git,.gitkeep
set wildignore+=.tmp
set wildignore+=.coverage
set wildignore+=*DS_Store*
set wildignore+=.sass-cache/
set wildignore+=__pycache__/
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=.tox/**
set wildignore+=.idea/**
set wildignore+=*.egg,*.egg-info
set wildignore+=*.png,*.jpg,*.gif
set wildignore+=*.so,*.swp,*.zip,*/.Trash/**,*.pdf,*.dmg,*/Library/**,*/.rbenv/**
set wildignore+=*/.nx/**,*.app
" Buffergator
" Use the right side of the screen
let g:buffergator_viewport_split_policy = 'R'
" I want my own keymappings...
let g:buffergator_suppress_keymaps = 1
" Looper buffers
let g:buffergator_mru_cycle_loop = 1
" Go to the previous buffer open
nmap <Leader>h :BuffergatorMruCyclePrev<cr>
" Go to the next buffer open
nmap <Leader>l :BuffergatorMruCycleNext<cr>
" View the entire list of buffers open
nmap <Leader>bl :BuffergatorOpen<cr>
" Shared bindings from Solution #1 from earlier
nmap <Leader>T :enew<cr>
nmap <Leader>bq :bp <BAR> bd #<cr>
" js syntax highlighting
let javascript_enable_domhtmlcss = 1
" BreakLine: Return TRUE if in the middle of {} or () in INSERT mode
fun BreakLine()
if (mode() == 'i')
return ((getline(".")[col(".")-2] == '{' && getline(".")[col(".")-1] == '}') ||
\(getline(".")[col(".")-2] == '(' && getline(".")[col(".")-1] == ')'))
else
return 0
endif
endfun
" Remap <Enter> to split the line and insert a new line in between if
" BreakLine return True
inoremap <expr> <CR> BreakLine() ? "<CR><ESC>O" : "<CR>"
" clear search buffer
nmap <silent> ,/ :nohlsearch<cr>
" use w!! to save root privileges files after opened them already
cmap w!! w !sudo tee % >/dev/null
" add for vundle
set nocompatible
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'bling/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'altercation/vim-colors-solarized'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'mattn/emmet-vim'
Plugin 'sukima/xmledit'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'majutsushi/tagbar'
Plugin 'fatih/vim-go'
Plugin 'bitc/vim-bad-whitespace'
Plugin 'ap/vim-css-color'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'luochen1990/rainbow'
Plugin 'kien/ctrlp.vim'
Plugin 'jeetsukumaran/vim-buffergator'
Plugin 'Glench/Vim-Jinja2-Syntax'
Plugin 'pangloss/vim-javascript'
Plugin 'Raimondi/delimitMate'
call vundle#end()
filetype plugin indent on
set encoding=utf-8
execute pathogen#infect()
set background=dark
set t_Co=256
set colorcolumn=80
set cursorline
let g:solarized_termcolors=16
let g:solarized_termtrans=0
call togglebg#map("<F5>")
colorscheme solarized
" trivial settings
syntax on
set ts=4
set backspace=indent,eol,start
set smartindent
set copyindent
set nu hlsearch is expandtab
set sw=4
set shiftround
set smarttab
set showmatch
set ignorecase
set smartcase
set ruler
set timeoutlen=1000
hi CursorLineNr ctermbg=15 ctermfg=5
imap jk <Esc>
let mapleader=" "
" Whitespace settings
set list listchars=tab:▸\ ,eol:¬,trail:∙
fun! ToggleWhitespace()
ToggleBadWhitespace
if &list
set nolist
else
set list listchars=tab:▸\ ,eol:¬,trail:∙
endif
endfun
nmap <Leader>tw :cal ToggleWhitespace()<cr>
" Invisible character colors
hi NonText ctermfg=236
hi SpecialKey ctermfg=236
" disable arrow keys
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
" noremap h <NOP>
" noremap l <NOP>
" insert mode controlenhancements
imap <c-f> <Right>
imap <c-b> <Left>
" copy to X11 buffer
set clipboard=unnamed
" for buffer operations
set hidden
au BufRead,BufNewFile *.md set filetype=markdown
" after PluginInstall of ycm, you need to compile it, check github page
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf = 0
" let g:ycm_error_symbol = '✗'
" let g:ycm_waring_symbol = '!'
" for switching between splits
set splitbelow
set splitright
set wmh=0
nmap <c-j> <c-w>j
nmap <c-k> <c-w>k
nmap <c-h> <c-w>h
nmap <c-l> <c-w>l
nmap <Leader>sv :vsplit<cr>
nmap <Leader>sh :split<cr>
nmap <Leader>= :resize +5<cr>
nmap <Leader>- :resize -5<cr>
nmap <Leader>] :vertical resize -5<cr>
nmap <Leader>[ :vertical resize +5<cr>
" for vim-airline, need to install
" powerline prepatched fonts so that
" arrow display correctly
set laststatus=2
let g:airline_powerline_fonts = 1
let g:airline_theme = "powerlineish"
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
" disable conceal for tex files
let g:tex_conceal = ""
" Tagbar coolness
nmap <Leader>tt :TagbarToggle<cr>
let g:tagbar_left = 0
let g:tagbar_width = 20
" NERDTree
" au VimEnter * NERDTree " open NERDTree when vim starts
let g:NERDTreeShowBookmarks = 1
let g:NERDTreeWinSize = 20
nmap <Leader>tn :NERDTreeToggle<cr>
" nerdcommenter add spacedelims
let g:NERDSpaceDelims = 1
" easy motion MADNESS
let g:EasyMotion_smartcase = 1
let g:EasyMotion_startofline = 0 " keey cursor column when JK motion
nmap <Leader><Leader>j <Plug>(easymotion-j)
nmap <Leader><Leader>k <Plug>(easymotion-k)
nmap <Leader><Leader>h <Plug>(easymotion-linebackward)
nmap <Leader><Leader>l <Plug>(easymotion-lineforward)
" repeat last easymotion madness
nmap <Leader><Leader>. <Plug>(easymotion-repeat)
" rainbow parentheses beautifulness
let g:rainbow_active = 1
let g:rainbow_conf = {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['darkblue', 'darkgreen', 'darkyellow', '133'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'lisp': {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'css': 0,
\ }
\}
" CtrlP
nmap <Leader>p :CtrlP<cr>
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](\.(git|hg|svn)|\_site)$',
\ 'file': '\v\.(exe|so|dll|class|png|jpg|jpeg)$',
\}
let g:ctrlp_working_path_mode = 'ra'
nmap <Leader>bb :CtrlPBuffer<cr>
nmap <Leader>bm :CtrlPMixed<cr>
nmap <Leader>bs :CtrlPMRU<cr>
" Ignore some defaults
set wildignore=*.o,*.obj,*~,*.pyc
set wildignore+=.env
set wildignore+=.env[0-9]+
set wildignore+=.git,.gitkeep
set wildignore+=.tmp
set wildignore+=.coverage
set wildignore+=*DS_Store*
set wildignore+=.sass-cache/
set wildignore+=__pycache__/
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=.tox/**
set wildignore+=.idea/**
set wildignore+=*.egg,*.egg-info
set wildignore+=*.png,*.jpg,*.gif
set wildignore+=*.so,*.swp,*.zip,*/.Trash/**,*.pdf,*.dmg,*/Library/**,*/.rbenv/**
set wildignore+=*/.nx/**,*.app
" Buffergator
" Use the right side of the screen
let g:buffergator_viewport_split_policy = 'R'
" I want my own keymappings...
let g:buffergator_suppress_keymaps = 1
" Looper buffers
let g:buffergator_mru_cycle_loop = 1
" Go to the previous buffer open
nmap <Leader>h :BuffergatorMruCyclePrev<cr>
" Go to the next buffer open
nmap <Leader>l :BuffergatorMruCycleNext<cr>
" View the entire list of buffers open
nmap <Leader>bl :BuffergatorOpen<cr>
" Shared bindings from Solution #1 from earlier
nmap <Leader>T :enew<cr>
nmap <Leader>bq :bp <BAR> bd #<cr>
" js syntax highlighting
let javascript_enable_domhtmlcss = 1
" BreakLine: Return TRUE if in the middle of {} or () in INSERT mode
fun BreakLine()
if (mode() == 'i')
return ((getline(".")[col(".")-2] == '{' && getline(".")[col(".")-1] == '}') ||
\(getline(".")[col(".")-2] == '(' && getline(".")[col(".")-1] == ')'))
else
return 0
endif
endfun
" Remap <Enter> to split the line and insert a new line in between if
" BreakLine return True
inoremap <expr> <CR> BreakLine() ? "<CR><ESC>O" : "<CR>"
" clear search buffer
nmap <silent> ,/ :nohlsearch<cr>
" use w!! to save root privileges files after opened them already
cmap w!! w !sudo tee % >/dev/null
" Neovim specific settings
" exit terminal mode
tnoremap jk <C-\><C-n>
" directly go to insert mode when swtich to terminal window
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment