" ## Ussage
" install vim-plug( https://github.com/junegunn/vim-plug )
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" Run: PlugInstall
" General settings --------------------{{{
set encoding=utf-8
let mapleader=','
syntax enable "https://niuge6.com/?p=280
set tabstop=4 "https://niuge6.com/?p=282
set shiftwidth=4 "https://niuge6.com/?p=282
set softtabstop=0 " 关闭softtabstop 永远不要将空格和tab混合输入 "https://niuge6.com/?p=282
set expandtab "https://niuge6.com/?p=282
set nu
set foldmethod=syntax
set nofoldenable " disable folding
set mouse=a " 支持鼠标
" Always show statusline
set laststatus=2
" Use 256 colours (Use this setting only if your terminal supports j
set t_Co=256 "https://niuge6.com/?p=286
let &t_8f="\
let &t_8b="\
set termguicolors "https://niuge6.com/?p=286
set backspace=2 " 删除键的问题
set colorcolumn=80 " max line 80 https://niuge6.com/?p=289
set cursorline " 高亮光标所在行
" search
set ignorecase " https://niuge6.com/?p=309
set incsearch " https://niuge6.com/?p=306
set hlsearch "https://niuge6.com/?p=311
set smartcase " https://niuge6.com/?p=309
set linebreak
set wildignore+=.swp,.pyc
set nocompatible " be iMproved
filetype on "https://niuge6.com/?p=329
filetype plugin on "https://niuge6.com/?p=329
filetype indent on "https://niuge6.com/?p=329
set autoindent "https://niuge6.com/?p=337
set smartindent "https://niuge6.com/?p=337
set shiftround "https://niuge6.com/?p=335
" 文件编码的猜测顺序
set fileencodings=ucs-bom,utf-8,cp936,gb18030,gb2312,big5,euc-jp,euc-kr,latin1
" }}}
" https://superuser.com/questions/302186/vim-scrolls-very-slowly-when-a-line-is-too-long
" Syntax coloring lines that are too long just slows down the world
set synmaxcol=600 "https://niuge6.com/?p=342
set scrolloff=3 "https://niuge6.com/?p=340
" Key bindings --------------------{{{
nnoremap
nnoremap
nnoremap
" ,作为了leader key, 将\映射成反向查找
noremap \ , "https://niuge6.com/?p=326
" use q to exit help window
autocmd FileType help noremap
"
" from: https://github.com/liuchengxu/dotfiles/blob/master/vimrc#L74
for s:i in range(1, 9)
execute 'nnoremap
endfor "https://niuge6.com/?p=320
" }}}
" Plugins --------------------{{{
call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree'
Plug 'mattn/webapi-vim'
Plug 'mattn/gist-vim'
Plug 'airblade/vim-gitgutter' " git diff
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdcommenter' " Quick comment
Plug 'ruanyl/vim-gh-line' " 在Bitbucket或github快速打开当前代码行
Plug 'ctrlpvim/ctrlp.vim' " 模糊查找
"https://niuge6.com/?p=397
" 多光标编辑
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
"https://niuge6.com/?p=347
Plug 'tpope/vim-fugitive' " git插件 (Blame)
Plug 'godlygeek/tabular' " 自动根据某个符号对其,用于json 字典 表格等
Plug 'tweekmonster/startuptime.vim' " Vim start up time debug (figure out which script is slow)
Plug 'dyng/ctrlsf.vim' " Ascyn use rg to find
Plug 'majutsushi/tagbar' " show tags of codes
Plug 'spacewander/openresty-vim'
Plug 'kien/rainbow_parentheses.vim' " Rainbow Parentheses
Plug 'cespare/vim-toml'
Plug 'stephpy/vim-yaml'
Plug 'nvie/vim-flake8'
Plug 'Vimjas/vim-python-pep8-indent' " auto indent ()
Plug 'slashmili/alchemist.vim'
" javascript, react, jsx, etc
Plug 'pangloss/vim-javascript'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'mattn/emmet-vim' " zen coding
Plug 'elixir-editors/vim-elixir' " Elixir
Plug 'mzlogin/vim-markdown-toc'
Plug 'gabrielelana/vim-markdown'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'benmills/vimux'
Plug 'flazz/vim-colorschemes'
Plug 'nathangrigg/vim-beancount'
Plug 'tyru/open-browser.vim' " preview plantuml
Plug 'aklt/plantuml-syntax'
Plug 'weirongxu/plantuml-previewer.vim'
Plug 'kana/vim-textobj-user'
Plug 'laixintao/vim-textobj-ipmac'
" On-demand lazy load
Plug 'liuchengxu/vim-which-key', { 'on': ['WhichKey', 'WhichKey!'] }
Plug 'LnL7/vim-nix'
Plug 'martinda/Jenkinsfile-vim-syntax'
call plug#end()
" }}}
set background=dark
colorscheme molokai
let g:airline_theme='wombat'
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:airline_powerline_fonts = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.colnr = ' ㏇:'
let g:gist_open_browser_after_post = 1
" Vim WhichKey --------------------{{{
nnoremap
" }}}
" https://github.com/mzlogin/vim-markdown-toc
let g:vmt_list_item_char = '-'
" vim 8 / neovim HEAD runtime: when ft==python, cms:=#\ %s
" " -- when g:NERDSpaceDelims==1, then NERDComment results in double space
let g:NERDCustomDelimiters = {
\ 'python': { 'left': '#', 'right': '' }
\ }
" NerdComment
let g:NERDSpaceDelims = 1
let g:NERDDefaultAlign = 'left'
nnoremap
nnoremap
" CtrlSF
nmap
vmap
vmap
nmap
nnoremap
nnoremap
inoremap
nnoremap
let g:ctrlsf_follow_symlinks = 0
let g:ctrlsf_auto_focus = {
\ "at": "start",
\ }
" CLang --------------------{{{
" Register ccls C++ lanuage server.
" au User lsp_setup call lsp#register_server({
" \ 'name': 'ccls',
" \ 'cmd': {server_info->['ccls']},
" \ 'root_uri': {server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'compile_commands.json'))},
" \ 'whitelist': ['c', 'cpp', 'objc', 'objcpp', 'cc'],
" \ })
" }}}
" Elixir --------------------{{{
augroup elixir_lang
autocmd!
" See https://github.com/elixir-editors/vim-elixir/issues/121
autocmd BufRead,BufNewFile .ex,.exs set filetype=elixir
autocmd BufRead,BufNewFile *.eex set filetype=eelixir
augroup end
" }}}
nnoremap
nnoremap
" Rainbow Parenthese --------------------{{{
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['gray', 'RoyalBlue3'],
\ ['black', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ['red', 'firebrick3'],
\ ]
let g:rbpt_max = 16
" }}}
" NerdTree Settings --------------------{{{ "整段的解释都在:https://niuge6.com/?p=385
augroup nerdtree_settings
autocmd!
" NERDDTree快捷键
map
map
nnoremap
" 是否显示隐藏文件
let NERDTreeShowHidden=1
" 设置宽度
let NERDTreeWinSize=30
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1
" 忽略以下文件的显示
let NERDTreeIgnore=['.pyc','\~$',
\ '.swp',
\ '.o',
\ '.DSStore',
\ '.orig$',
\ '@neomake',
\ '.coverage.',
\ 'pycache$[[dir]]',
\ '.pytest_cache$[[dir]]',
\ '.git$[[dir]]',
\ '.idea[[dir]]',
\ '.vscode[[dir]]',
\ 'htmlcov[[dir]]',
\ 'test-reports[[dir]]',
\ '.egg-info$[[dir]]']
" 显示书签列表
let NERDTreeShowBookmarks=1
" 改变nerdtree的箭头
" let g:NERDTreeDirArrowExpandable = '?'
" let g:NERDTreeDirArrowCollapsible = '?'
" vim不指定具体文件打开是,自动使用nerdtree
autocmd StdinReadPre let s:std_in=1
autocmd VimEnter if argc() == 0 && !exists("s:std_in") | NERDTree |endif
" 当vim打开一个目录时,nerdtree自动使用
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif
" 打开新的窗口,focus在buffer里而不是NerdTree里
autocmd VimEnter * :wincmd l
" 当vim中没有其他文件,值剩下nerdtree的时候,自动关闭窗口
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
augroup END
" }}} "整段的解释都在:https://niuge6.com/?p=385
" Prompt for a command to run
nnoremap
" Close vim tmux runner opened by VimuxRunCommand
nnoremap
nnoremap
"}}}
" InsertMode Quick Edit --------------------{{{
" use emacs shortcut in INSERT mode
imap
imap
imap
imap
augroup relative_numbser
autocmd!
autocmd InsertEnter :set norelativenumber
autocmd InsertLeave :set relativenumber
augroup END
" }}}
" ShortCuts --------------------{{{
augroup shortcuts
autocmd!
" alias Vres to resize screen
command! -nargs=? Vres vertical res
onoremap in( :
augroup END
" }}}
" Iabbrev --------------------{{{
augroup iabbrevs
autocmd!
" long comment
autocmd FileType python,coffee :iabbrev
:iab
augroup END
" }}}
" Lisp --------------------{{{
augroup lisp_lang
autocmd!
" for scheme
let g:lisp_rainbow=1 "(这个是设置括号的颜色)
autocmd FileType scheme RainbowParenthesesToggle
augroup END
" }}}
" Javascript-like Language --------------------{{{
" enable zen coding for jsx
let g:user_emmet_settings = {
\ 'javascript.jsx' : {
\ 'extends' : 'jsx',
\ },
}
augroup javascript_lang
autocmd!
autocmd BufNewFile,BufRead *.html setlocal nowrap
autocmd FileType javascript set filetype=javascript.jsx
command! -nargs=0 Prettier :CocCommand prettier.formatFile
autocmd FileType coffee,html,css,xml,yaml,js,javascript,dot,gv,typescriptreact,typescript set sw=2 ts=2
autocmd FileType coffee,html,css,xml,yaml,js,javascript,dot,gv,typescriptreact,typescript set foldmethod=indent
augroup end
" }}}
" JSON --------------------{{{
augroup json_lang
autocmd!
autocmd BufNewFile,BufRead *.html setlocal nowrap
autocmd FileType json set sw=2 ts=2
augroup end
" }}}
" Python --------------------{{{
augroup python_lang
autocmd FileType python nnoremap
augroup end
" }}}
" Golang --------------------{{{
augroup go_lang
" update gopls: go install golang.org/x/tools/gopls@latest
"
autocmd FileType go nnoremap
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
" goimports
let g:goimports = 0
nmap i :CocCommand editor.action.organizeImport
augroup end
" }}}
" VimScript file settings --------------------{{{
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal foldmethod=marker
" edit vimrc
:nnoremap
:nnoremap
autocmd FileType vim :iabbrev
augroup END
" }}} }}}
" Custome functions --------------------{{{
function! FoldColumnToggle()
if &foldcolumn
setlocal foldcolumn=0
else
setlocal foldcolumn=4
endif
endfunction
nnoremap
let g:quickfix_is_open = 0
function! QuickFixToggle()
if g:quickfix_is_open
cclose
let g:quickfix_is_open = 0
else
copen
let g:quickfix_is_open = 1
endif
endfunction
function! MoveToPrevTab()
"there is only one window
if tabpagenr('$') == 1 && winnr('$') == 1
return
endif
"preparing new window
let l:tab_nr = tabpagenr('$')
let l:cur_buf = bufnr('%')
if tabpagenr() != 1
close!
if l:tab_nr == tabpagenr('$')
tabprev
endif
sp
else
close!
exe "0tabnew"
endif
"opening current buffer in new window
exe "b".l:cur_buf
endfunc
function! MoveToNextTab()
"there is only one window
if tabpagenr('$') == 1 && winnr('$') == 1
return
endif
"preparing new window
let l:tab_nr = tabpagenr('$')
let l:cur_buf = bufnr('%')
if tabpagenr() < tab_nr
close!
if l:tab_nr == tabpagenr('$')
tabnext
endif
sp
else
close!
tabnew
endif
"opening current buffer in new window
exe "b".l:cur_buf
endfunc
nnoremap mt :call MoveToNextTab()
nnoremap mT :call MoveToPrevTab()
function! FormatMongodoc2Python() range
" 将mongo复制过来的doc修改成Python的代码
let l:delete_lines = []
for line in range(a:firstline, a:lastline)
let l:oldline = getline(line)
if l:oldline =~ "updated_at" || l:oldline =~ "ObjectId"
let l:delete_lines = add(l:delete_lines, line)
else
let l:oldline = substitute(l:oldline, ' :', ':', "g") " 删除:前面的空格
let l:oldline = substitute(l:oldline, 'true', 'True', "g") " true替换
call setline(line, l:oldline)
endif
" execute line 'delete _'
endfor
for line in l:delete_lines
execute line 'delete _'
endfor
endfunction
nnoremap
" ]p to paste into a newline
" [p to paste into the line upon cursor
" https://github.com/tpope/vim-unimpaired/blob/master/plugin/unimpaired.vim#L343
function! s:putline(how, map) abort
let [body, type] = [getreg(v:register), getregtype(v:register)]
if type ==# 'V'
exe 'normal! "'.v:register.a:how
else
call setreg(v:register, body, 'l')
exe 'normal! "'.v:register.a:how
call setreg(v:register, body, type)
endif
silent! call repeat#set("\
endfunction
nnoremap
nnoremap
" }}}
" .tmux.conf --------------------{{{
augroup filetype_tmux_conf
autocmd!
autocmd FileType tmux setlocal foldmethod=marker
autocmd FileType tmux :iabbrev
augroup END
" }}}
" graphviz --------------------{{{
augroup graphviz
autocmd BufNewFile,BufRead .dot,.gz nnoremap
autocmd BufNewFile,BufRead .dot,.gz nnoremap
function! CompileGraphviz()
execute ":w"
execute "Compile dot file and then open it."
execute ":silent !dot -Tsvg -o %:r.svg %"
execute "redraw!"
endfunction
function! OpenGraphviz()
call CompileGraphviz()
execute ":silent !open %:r.svg"
execute "redraw!"
endfunction
augroup END
" }}}
" nginx --------------------{{{
augroup nginx
autocmd BufRead,BufNewFile nginx.conf* set filetype=nginx
augroup END
" }}}
" clang --------------------{{{
map
" }}}
autocmd BufNewFile,BufRead .mapping set ft=json
autocmd BufNewFile,BufRead .sls set ft=yaml
autocmd BufNewFile,BufRead .coffee set ft=coffee
autocmd BufNewFile,BufRead .toml set ft=TOML
autocmd SwapExists * let v:swapchoice = "o"
let g:ctrlp_custom_ignore = 'node_modules|DS_Store|git|test-reports|htmlcov\'
augroup vagrant
au!
au BufRead,BufNewFile Vagrantfile set filetype=ruby
augroup END
let g:gh_gitlab_domain= "gitlab.alipay-inc.com"
" TextEdit might fail if hidden is not set.
set hidden
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
" coc snippets --------------------{{{
" Use
imap
" Use
vmap
" Use
let g:coc_snippet_next = '
" Use
let g:coc_snippet_prev = '
" Use
imap
" Formatting selected code.
xmap
nmap
" }}}
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap
" other plugin before putting this into your config.
inoremap
\ pumvisible() ? "\
\
\ coc#refresh()
inoremap
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use
inoremap
" Use <C-g>u
means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
" :verbose imap <CR>
.
if exists('*complete_info')
inoremap
else
inoremap
endif
" Use [g
and ]g
to navigate diagnostics
" Use :CocDiagnostics
to get all diagnostics of current buffer in location list.
nmap
nmap
" Quick fix
nmap
" GoTo code navigation.
nmap
nmap
nmap
nmap
" Use K to show documentation in preview window.
nnoremap
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('
else
call CocAction('doHover')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: <leader>aap
for current paragraph
xmap
nmap
" Remap keys for applying codeAction to the current buffer.
nmap
" Apply AutoFix to problem on the current line.
nmap
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if
omap if
xmap af
omap af
xmap ic
omap ic
xmap ac
omap ac
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
nmap
xmap
" Add :Format
command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add :Fold
command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold',
" Add :OR
command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see :h coc-status
for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap
" Manage extensions.
nnoremap
" Show commands.
nnoremap
" Find symbol of current document.
nnoremap
" Search workspace symbols.
nnoremap
" Do default action for next item.
nnoremap
" Do default action for previous item.
nnoremap
" Resume latest coc list.
nnoremap
" vim textobject, for lines
" so that you can copy lines without a newline
vnoremap al :
omap al :normal val
vnoremap il :
omap il :normal vil
" copy the current file path
nmap
"https://niuge6.com/?p=350
nnoremap
转载请注明:牛哥678 » vimrc: laixintao