Skip to content

Instantly share code, notes, and snippets.

@hereisfun
Last active May 2, 2018 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hereisfun/6ea44388948ce590047d0eb185dd0384 to your computer and use it in GitHub Desktop.
Save hereisfun/6ea44388948ce590047d0eb185dd0384 to your computer and use it in GitHub Desktop.
vim config
" vundle 环境设置
set nocompatible
filetype off
call plug#begin('~/.vim/plugged')
"Plugin 'tomasr/molokai'
Plug 'dracula/vim'
Plug 'joshdick/onedark.vim'
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'vim-scripts/L9'
" Plug 'justinmk/vim-dirvish' "directory viewer for vim
Plug 'scrooloose/nerdtree' "文件浏览
Plug 'Xuyuanp/nerdtree-git-plugin', {'on': 'NERDTreeToggle'} "nerdtree的git插件
Plug 'tiagofumo/vim-nerdtree-syntax-highlight' "icon highlight
Plug 'ryanoasis/vim-devicons' "nerdTree icon
Plug 'ap/vim-buftabline' "buffer explorer
Plug 'godlygeek/tabular' "自动对齐
" Plug 'vim-scripts/Tagbar', {'on': 'TagbarToggle'} "结构预览
Plug 'Yggdroot/LeaderF', { 'do': './install.sh' } "结构预览
" Plug 'ctrlpvim/ctrlp.vim' "全局搜索
Plug 'itchyny/lightline.vim' "状态栏
Plug 'tpope/vim-fugitive' "git栏
Plug 'Shougo/vimproc.vim', {'do': 'make'} "async
Plug 'w0rp/ale' "异步语法检查
Plug 'Yggdroot/indentLine' "垂直参考线
Plug 'severin-lemaignan/vim-minimap', {'on': ['Minimap', 'MinimapToggle']} "预览图
" Plug 'airblade/vim-gitgutter' "vim git提示(行号左侧提示)
Plug 'mhinz/vim-signify' "vim git 提示(左侧) :SignifyDiff 左右分屏diff
Plug 'kshenoy/vim-signature' "可视化书签
Plug 'junegunn/goyo.vim', {'on': 'Goyo'} "沉浸模式
Plug 'junegunn/limelight.vim', {'on': 'Limelight'} "专注模式
Plug 'guns/xterm-color-table.vim' "终端色表
Plug 'tpope/vim-surround' "包裹符号
Plug 'jiangmiao/auto-pairs' "删除/插入括号,引号
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Plug 'rking/ag.vim' " enhanced result list
Plug 'ludovicchabant/vim-gutentags' "regenerate tags
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
" Plug 'haskell.vim' "Haskell language
Plug 'leafgarland/typescript-vim', {'for': 'typescript'} "typescript高亮
Plug 'pangloss/vim-javascript', { 'for': ['javascript', 'javascript.jsx'] } "javascript高亮
Plug 'mxw/vim-jsx', { 'for': ['javascript', 'javascript.jsx'] } "react高亮
Plug 'tpope/vim-rails' "rails.vim
Plug 'luochen1990/rainbow' "彩虹括号
Plug 'ternjs/tern_for_vim', { 'for': ['javascript', 'javascript.jsx'] } "JS结构预览
Plug 'neovimhaskell/haskell-vim', {'for': 'haskell'}
Plug 'eagletmt/ghcmod-vim', {'for': 'haskell'} "ghc-mod
Plug 'bitc/lushtags', {'for': 'haskell'} "haskell结构预览
Plug 'vim-scripts/npm.vim' "npm commands
Plug 'mattn/emmet-vim' "emmet
Plug 'wakatime/vim-wakatime'
" 插件列表结束
call plug#end()
filetype plugin indent on
" 让配置变更立即生效
autocmd BufWritePost $MYVIMRC source $MYVIMRC
" 配色方案
"set background=dark
"colorscheme molokai
"colorscheme phd
"colorscheme dracula
"colorscheme onedark
" 颜色变量,方便根据时间修改主题
" let lightlineColor = 'Dracula'
" if !has('gui_running')
set t_Co=256
if has('termguicolors') && !exists('$TMUX')
set termguicolors
end
" colorscheme dracula
colorscheme onedark
let g:onedark_termcolors=16
let lightlineColor = 'onedark'
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\e[5 q\<Esc>\\"
let &t_SR = "\<Esc>Ptmux;\<Esc>\e[4 q\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\e[2 q\<Esc>\\"
" Colors in tmux
"let &t_8f = "<Esc>[38;2;%lu;%lu;%lum"
"let &t_8b = "<Esc>[48;2;%lu;%lu;%lum"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
set background=dark
set timeoutlen=1000 ttimeoutlen=0
"else
" if strftime('%H') >= 21 || strftime('%H') <= 9
" set background=dark
" else
" set background=light
" endif
" colorscheme solarized
" call togglebg#map("<F2>")
" let lightlineColor = 'solarized'
" endif
set guifont=Monaco:h20
" 设置颜色主题
" 根据不同类型加载对应的插件
filetype plugin on
" Leader 键
let mapleader=";"
" 开启语法高亮功能
syntax enable
" 允许用指定语法高亮配色方案替换默认方案
syntax on
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 用浅色高亮当前行
autocmd InsertLeave * se nocul
autocmd InsertEnter * se cul
" 智能对齐
set smartindent
" 自动对齐
set autoindent
" 统一缩进为2
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set shiftround
" 显示行号
set number
" 历史记录数
set history=50
" 搜索逐字符高亮
set hlsearch
set incsearch
" 重绘并清除搜索高亮
nnoremap <silent> <leader>l :<C-u>nohlsearch<CR><C-l>
" 行内替换
set gdefault
" 编码设置
set encoding=UTF-8
set fileencodings=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936,utf-16,big5,euc-jp,latin1
" 语言设置
set langmenu=zn_CN.UTF-8
set helplang=cn
" 在编辑过程中,在右下角显示光标位置的状态行
set ruler
" 总是显示状态行
set laststatus=2
" 在状态行显示目前所执行的命令,未完成的指令片段亦会显示出来
set showcmd
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
" 高亮显示对应的括号
set showmatch
" 对应括号高亮的时间(单位是十分之一秒)
set matchtime=5
" 在切换buffer时自动保存当前文件
set autowrite
" 增强模式中的命令行自动完成操作
set wildmenu
" 字符间插入的像素行数目
set linespace=2
" 折叠方式:manual 手动;syntax 语法;indent 缩进
set foldmethod=manual
" 启动 vim 时关闭折叠代码
set nofoldenable
" 窗口切换快捷键
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
" NERDTree
let NERDChristmasTree=0
let NERDTreeWinSize=20
" CWD 随着 root 的改变而改变
let NERDTreeChDirMode=2
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
let NERDTreeShowBookmarks=1
let NERDTreeWinPos="right"
" disable hijacking netrw
let NERDTreeHijackNetrw = 1
" Automatically open a NERDTree if no files where specified
" autocmd vimenter * if !argc() | NERDTreeToggle | endif
autocmd StdinReadPre * let s:std_in=1
" autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTreeToggle | endif
" Close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" Open a NERDTree
nmap <leader><leader>5 :NERDTreeToggle<CR>
" Focus on NERDTree
nmap <leader><leader>t :NERDTreeFocus<CR>
" Tagbar
" let g:tagbar_width=20
" let g:tagbar_autofocus=1
" let g:tagbar_left = 1
" nmap <F6> :TagbarToggle<CR>
" let g:tagbar_type_typescript = {
" \ 'ctagsbin' : 'tstags',
" \ 'ctagsargs' : '-f-',
" \ 'kinds': [
" \ 'e:enums:0:1',
" \ 'f:function:0:1',
" \ 't:typealias:0:1',
" \ 'M:Module:0:1',
" \ 'I:import:0:1',
" \ 'i:interface:0:1',
" \ 'C:class:0:1',
" \ 'm:method:0:1',
" \ 'p:property:0:1',
" \ 'v:variable:0:1',
" \ 'c:const:0:1',
" \ ],
" \ 'sort' : 0
" \ }
" LeaderF
noremap <leader><leader>f :LeaderfFunction<CR>
" ctrlp
" set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.png,*.jpg,*.jpeg,*.gif " MacOSX/Linux
" let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
" if executable('ag')
" " Use Ag over Grep
" set grepprg=ag\ --nogroup\ --nocolor
" " Use ag in CtrlP for listing files.
" let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" " Ag is fast enough that CtrlP doesn't need to cache
" let g:ctrlp_use_caching = 0
" endif
" tabular
nnoremap <leader>t :Tab/
vnoremap <leader>t :Tab/
" Ale
let g:ale_linters = {
\ 'javascript': ['eslint'],
\ 'typescript': ['tslint', 'tsserver'],
\ 'haskell': ['stack-ghc-mod', 'hint'],
\ 'cpp': ['clang', 'cpplint'],
\ 'c': ['clang', 'cpplint']
\}
let g:ale_echo_cursor = 1
let g:ale_open_list = 1
" only run linter when I want to
let g:ale_lint_on_enter = 0
let g:ale_lint_on_text_changed = 'never'
let g:ale_sign_error = '>>'
let g:ale_sign_warning = '--'
let g:ale_echo_msg_format = '[%linter%] %s'
nnoremap <leader>e :ALELint<cr>
nnoremap <leader><leader>e :ALEToggle<cr>
" nnoremap <leader>an :ALENextWrap<cr>
" nnoremap <leader>ap :ALEPreviousWrap<cr>
" lightline
set laststatus=2 " Always display the status line
let g:lightline = {
\ 'colorscheme': lightlineColor,
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified', 'ale' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'LightlineFugitive',
\ },
\ 'component': {
\ 'ale': '%{LinterStatus()}',
\ },
\ }
function! LightlineFugitive()
if &ft !~? 'vimfiler' && exists('*fugitive#head')
return fugitive#head()
endif
return ''
endfunction
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf(
\ '%dE %dW',
\ all_errors,
\ all_non_errors
\)
endfunction
" minimap
let g:minimap_highlight='WarningMsg'
" json
map <Leader>json :%!python -m json.tool<CR>gg=G
" Compaile and run c program
map <Leader>q :w<CR>:!clang++ % -o %< && ./%< <CR>
" gitgutter
let g:gitgutter_realtime = 0
let g:gitgutter_eager = 0
" JavaScript hightlight
let g:jsx_ext_required = 0
let g:javascript_plugin_jsdoc = 1
let g:javascript_plugin_ngdoc = 1
let g:javascript_plugin_flow = 1
" Haskell ghc-mode
map <leader>ghcw :GhcModTypeInsert<CR>
map <leader>ghcs :GhcModSplitFunCase<CR>
map <leader>ghcq :GhcModType<CR>
map <leader>ghce :GhcModTypeClear<CR>
"open rainbow
let g:rainbow_active = 1
let g:rainbow_conf = {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\ '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'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'css': 0,
\ }
\}
"emmet
let g:user_emmet_mode='inv' "enable in insert, normal, visual mode
"let g:user_emmet_install_global=0
"autocmd FileType html,css EmmetInstall "enable just for html/css
"Goyo
autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!
let g:goyo_with = '50%'
let g:goyo_height = '100%'
let g:limelight_conceal_ctermfg=240
let g:limelight_conceal_guifg='#585858'
nmap <leader>z :Goyo<CR>
" buftabline
:hi! link BufTabLineCurrent PmenuSel
:hi! link BufTabLineActive DiffAdd
let g:buftabline_separators = 1
nmap <leader>1 <Plug>BufTabLine.Go(1)
nmap <leader>2 <Plug>BufTabLine.Go(2)
nmap <leader>3 <Plug>BufTabLine.Go(3)
nmap <leader>4 <Plug>BufTabLine.Go(4)
nmap <leader>5 <Plug>BufTabLine.Go(5)
nmap <leader>6 <Plug>BufTabLine.Go(6)
nmap <leader>7 <Plug>BufTabLine.Go(7)
nmap <leader>8 <Plug>BufTabLine.Go(8)
nmap <leader>9 <Plug>BufTabLine.Go(9)
nmap <leader>0 <Plug>BufTabLine.Go(10)
" OCaml config
set rtp^="/Users/fung/.opam/system/share/ocp-indent/vim"
" OCaml merlin
if executable('ocamlmerlin') && has('python')
let s:ocamlmerlin = substitute(system('opam config var share'), '\n$', '', '''') . "/ocamlmerlin"
execute "set rtp+=".s:ocamlmerlin."/vim"
execute "set rtp+=".s:ocamlmerlin."/vimbufsync"
endif
" haskell vim
let g:haskell_indent_if = 0
" hightlight for nerd font
let s:purple = "834F79"
let s:lightPurple = "834F79"
let g:NERDTreeExtensionHighlightColor = {} " this line is needed to avoid error
let g:NERDTreeExtensionHighlightColor['hs'] = s:lightPurple " sets the color of hs files to purple
let g:NERDTreeHighlightCursorline = 0 " lag issue
" for fzf.vim
" [warning] overide LeaderF's default key binding
noremap <leader>f :GFiles<CR>
noremap <leader>a :Ag!<CR>
" Command for git grep
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
command! -bang -nargs=* GGrep
\ call fzf#vim#grep(
\ 'git grep --line-number '.shellescape(<q-args>), 0,
\ { 'dir': systemlist('git rev-parse --show-toplevel')[0] }, <bang>0)
" Override Colors command. You can safely do this in your .vimrc as fzf.vim
" will not override existing commands.
command! -bang Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0)
" Augmenting Ag command using fzf#vim#with_preview function
" * fzf#vim#with_preview([[options], preview window, [toggle keys...]])
" * For syntax-highlighting, Ruby and any of the following tools are required:
" - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php
" - CodeRay: http://coderay.rubychan.de/
" - Rouge: https://github.com/jneen/rouge
"
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key
" :Ag! - Start fzf in fullscreen and display the preview window above
" the option '--delimiter : --nth 4..' is trying to match the filename while
" searching file contents
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Similarly, we can apply it to fzf#vim#grep. To use ripgrep instead of ag:
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Likewise, Files command with preview window
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
" for ctags
set tags=./.tags;,.tags
" for vim-gutentags
" gutentags 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']
" 所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'
" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
" 配置 ctags 的参数
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
" 检测 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
silent! call mkdir(s:vim_tags, 'p')
endif
" 仅对线上仓库包含的文件生成tags
let g:gutentags_file_list_command = {
\ 'markers': {
\ '.git': 'git ls-files',
\ },
\ }
" deoplete
let g:deoplete#enable_at_startup = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment