Skip to content

Instantly share code, notes, and snippets.

@weaming
Last active June 27, 2019 02:05
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 weaming/ca58fd98302ec5cba6dcb6df1208fd4b to your computer and use it in GitHub Desktop.
Save weaming/ca58fd98302ec5cba6dcb6df1208fd4b to your computer and use it in GitHub Desktop.
" vim:foldmethod=marker:foldlevel=0
" Install Plugin Manager:
" curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" The Default Config File Location Is:
" ~/.config/nvim/init.vim
" If you're using Windows 10, config file is located in:
" ~\AppData\Local\nvim\init.vim
" Check Neovim Health: :CheckHealth
" Essentital features for vim: https://dougblack.io/words/a-good-vimrc.html
" Learn How To Use Help: http://vim.wikia.com/wiki/Learn_to_use_help
" Press Ctrl-] to follow the link (jump to the quickref topic)
" Learn Vimscript:
" http://www.skywind.me/blog/archives/2193 http://andrewscala.com/vimscript/
" ============================================
" ## 变量
"
" * `let`命令用来对变量进行初始化或者赋值。
" * `unlet`命令用来删除一个变量。
" * `unlet!`命令同样可以用来删除变量,但是会忽略诸如变量不存在的错误提示。
" * `set`
" * `set`is for setting_options_,`let`for assigning a value to a_variable_.
" * `set wrap&` 设置默认值
" * `set nowrap` unset
" * `set wrap!` toggle
"
" 默认情况下,如果一个变量在函数体以外初始化的,那么它的作用域是全局变量;而如果它是在函数体以内初始化的,那它的作用于是局部变量。同时你可以通过变量名称前加冒号前缀明确的指明变量的作用域:
" :help internal-variables
"
" * g:var – 全局
" * a:var – 函数参数
" * l:var – 函数局部变量
" * b:var – buffer 局部变量
" * w:var – window 局部变量
" * t:var – tab 局部变量
" * s:var – 当前脚本内可见的局部变量
" * v:var – Vim 预定义的内部变量
" * $:var - 环境变量
" * &:option - Vim 内部的设置值
" * @<register-name> - 寄存器内的值,:reg 查看所有寄存器值
" ## 字符串比较
"
" * `<string>`==`<string>`: 字符串相等
" * `<string>`!=`<string>`: 字符串不等
" * `<string>`=~`<pattern>`: 匹配 pattern
" * `<string>`!~`<pattern>`: 不匹配 pattern
" * `<operator>#`: 匹配大小写
" * `<operator>?`: 不匹配大小写
" * 注意:设置选项`ignorecase`会影响 == 和 != 的默认比较结果,可以在比较符号添加 ? 或者 # 来明确指定大小写是否忽略。
" * `<string>`.`<string>`: 字符串连接
"
" ## Operators
"
" let var -= 2
" let var += 2
" let var .= 'string'
"
" ## String Functions
"
" strlen(var)
" len(var)
" strchars(var)
" split("one two three")
" split("one,two,three", ",")
" join(['a', 'b'], ",")
" tolower('Hello')
" toupper('Hello')
"
" ## Functions
"
" function! myplugin#hello()
" call s:Initialize()
" echo "Results: " . s:Initialize()
"
" ## Commands
"
" command! Save :set fo=want tw=80 nowrap
" command! Save call <SID>foo()
" -nargs=0,1,?,*,+
"
" ## Execute a Command
"
" execute "vsplit"
" execute "e " . fnameescap(filename)
"
" ## Key strokes
"
" normal G
" normal! G
" execute "normal! gg/foo\<cr>dd"
"
" ## Get file names
"
" :help expand
"
" ## Silencing
"
" :help silent
"
" ## Settings
"
" set number
" set nonumber
" set number!
" set numberwidth=5
" set guioptions+=e
"
" ## Echo
"
" echo "hello"
" echon "hello"
" echoerr "hello"
" echomsg "hello"
" echohl
"
" ## Built-ins
"
" has("feature") :help feature-list
" executable("python3")
" globpath(&rtp, "syntax/c.vim")
"
" exists("$ENV")
" exists(":command")
" exists("variable")
" exists("+option")
" exists("g:...")
"
" ## Prompts
"
" let result = confirm("Sure?")
" execute "confirm q"
" :help confirm
"
" ## Mapping
"
" [nvixso](nore)map (<buffer>) (<silent>) (<nowait>)
"
" ## About <SID>
"
" But when a mapping is executed from outside of the script, it doesn't know in which script the function was defined.
" To avoid this problem, use "<SID>" instead of "s:". The same translation is done as for mappings.
" This makes it possible to define a call to the function in a mapping."
"
" ## Boolean
"
" 0 is false, 1 is true, str will be convert to number (like in JavaScript)
" &&
" ||
" if <a> | <b> | endif
" a ? b : c
"
" ## Identify Operators
"
" a is b
" a isnot b
"
" ## Lists
"
" let mylist = [1, two, 3, "four"]
" let first = mylist[0]
" let last = mylist[-1]
" let second = get(mylist, 1)
" let second = get(mylist, 1, "NONE")
"
" let shortlist = mylist[2:-1]
" let shortlist = mylist[2:] " same as above
" let shortlist = mylist[2:2] " one item
"
" len(mylist)
" empty(mylist)
" sort(mylist)
" let sortedlist = sort(copy(mylist))
"
" let longlist = mylist + [5,6,7]
" let mylist += [5,6,7]
" add(mylist, 4)
"
" ## Map, Filter
"
" call map(files, "bufname(v:val)") " use v:val for value
" call filter(files, 'v:val != ""')
"
" ## Dict
"
" let colors = {
" \ "apple": "red",
" \ "banana": "yellow",
" }
" echo colors["apple"]
" echo get(colors, "apple")
" remove(colors, "apple")
" has_key(colors, "apple")
" empty(colors)
" keys(colors)
" len(colors)
" max(colors)
" min(colors)
" count(dict, 'x') ???
" string(dict)
" map(dict, '<>> " . v:val')
"
" echo keys(g:)
" let extend(s:fruits, {...})
"
" ## Casting
"
" str2float('3.14')
" str2nr('3.14')
" float2nr(3.14)
"
" ## Numbers and Floats
"
" 1000
" 0xff
" 0755
" 3.14
" 3.14e4
"
" ## Math functions
"
" sqrt(100)
" floor(3.14)
" ceil(3.14)
" abs(-3.14)
" sin cos tan
" sinh cosh tanh
" asin acos atan
"
" ## 另外
"
" * Vim 可以创建有序列表,无序hash表
" * let mylist = [1, 2, ['a', 'b']]
" * let mydict = {'blue': "#0000ff", 'foo': {999: "baz"}}
" * 没有布尔类型,整数 0 被当作假,其他被当作真。字符串在比较真假前会被转换成整数,大部分字符串都会被转化为 0,除非以非零开头的字符串才会转化成非零。
" * VimScript 的变量属于动态弱类型
" * `let Myfunc = function("strlen")` 函数引用
" * if..elseif..else..endif
" * for..in, 可以进行列表模式匹配解构变量
" * while..endwhile
" * try..catch..finally..endtry
" * function! 覆盖函数定义,否则会报错
" * function 定义的后面加 dict,可以将字典内部暴露为 self 关键字,这像是其他语言的单例模式
" * 使用 deepcopy 创建新的类实例
" * `call <function>` 调用函数
" * 强制创建一个全局函数(使用感叹号),参数使用`...`这种不定长的参数形式时,a:1 表示`...`部分的第一个参数,a:2 表示第二个,如此类推,a:0 用来表示`...`部分一共有多少个参数
" * 有一种特殊的调用函数的方式,可以指明该函数作用的文本区域是从当前缓冲区的第几行到第几行,按照`1,3call Foobar()`的格式调用一个函数的话,该函数会在当前文件的第一行到第三行每一行执行一遍,再这个例子中,该函数总共被执行了三次
" * 如果你在函数声明的参数列表后添加一个`range`关键字,那函数就只会被调用一次,这时两个名为`a:firstline`和`a:lastline`的特殊变量可以用在该函数内部使用
" ============================================
" https://devhints.io/vimscript
" http://learnvimscriptthehardway.stevelosh.com/
" VIM Setting Articles:
" [Vim After 15 Years](https://statico.github.io/vim3.html)
set runtimepath^=~/.config/nvim runtimepath+=~/.config/nvim/after
let &packpath = &runtimepath
" Neovim Settings:
" Run: `:CheckHealth` to check if neovim works well
" Providers: https://neovim.io/doc/user/provider.html
" Setup Python Executalbe Path:
" run `conda create -n python python=2.7`
" let g:python_host_prog = $HOME.'/anaconda3/bin/python2.7'
" let g:python3_host_prog = $HOME.'/anaconda3/bin/python3.6'
let g:python_host_prog = '/usr/local/bin/python2'
let g:python3_host_prog = '/usr/local/bin/python3'
let g:ruby_host_prog = '/usr/local/bin/neovim-ruby-host'
let $PYTHONPATH = '.'
" Disable Python2 Support:
" let g:loaded_python_provider = 1
" Disable Python3 Support:
" let g:loaded_python3_provider = 1
" Plugins {{{
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.config/nvim/plugged')
" Plugin Install Examples:
" " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
" Plug 'junegunn/vim-easy-align'
" " Any valid git URL is allowed
" Plug 'https://github.com/junegunn/vim-github-dashboard.git'
" " On-demand loading
" Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" " Using a non-master branch
" Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
" " Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
" Plug 'fatih/vim-go', { 'tag': '*' }
" " Plugin options
" Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
" " Plugin outside ~/.vim/plugged with post-update hook
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" gruvbox主题
Plug 'morhetz/gruvbox'
set background=dark
"颜色对比度[soft/medium/hard]
let g:gruvbox_contrast_dark="medium"
Plug 'liuchengxu/space-vim-dark'
" 显示CSS颜色
Plug 'ap/vim-css-color'
" Ale: https://github.com/w0rp/ale {{
" https://github.com/w0rp/ale/blob/master/supported-tools.md
Plug 'w0rp/ale'
let g:ale_sign_column_always = 1
let g:ale_lint_on_enter = 1
let g:ale_open_list = 1
let g:ale_lint_delay = 500
let g:ale_list_window_size = 5
let g:ale_sign_warning = 'W'
let g:ale_sign_error = 'E'
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 0
let g:ale_linters = {
\ 'python': ['autopep8', 'pylint'],
\ 'javascript': ['eslint'],
\ 'go': ['gofmt', 'revive', 'go vet'],
\ 'yaml': ['yamllint'],
\}
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 ? 'OK' : printf(
\ '%dW %dE',
\ all_non_errors,
\ all_errors
\)
endfunction
set statusline=%<%f%h%m%r\ %{LinterStatus()}%=%b\ 0x%B\ %l,%c%V\ %P
" }}
" Python: {
" https://github.com/mindriot101/vim-yapf
Plug 'mindriot101/vim-yapf'
nnoremap <a-y> :Yapf --style facebook<CR>
" https://github.com/ambv/black
Plug 'ambv/black'
nnoremap <a-f> :Black<CR>
" Jinja2:
" https://github.com/lepture/vim-jinja
Plug 'lepture/vim-jinja'
" Isort:
" https://github.com/fisadev/vim-isort
Plug 'fisadev/vim-isort'
let g:vim_isort_map = '<C-i>'
let g:vim_isort_python_version = 'python3'
" bind to run current file
au FileType python nnoremap <buffer> <leader>r :!PYTHONPATH=$(git rev-parse --show-toplevel 2>/dev/null \|\| echo .) /usr/bin/env python %<cr>
" }
" Ruby:
Plug 'vim-ruby/vim-ruby'
" Nim: {
Plug 'zah/nim.vim'
fun! JumpToDef()
if exists("*GotoDefinition_" . &filetype)
call GotoDefinition_{&filetype}()
else
exe "norm! \<C-]>"
endif
endf
" Jump to tag
nnoremap <M-g> :call JumpToDef()<cr>
inoremap <M-g> <esc>:call JumpToDef()<cr>i
" }
" Search File: {
" A Command Line Fuzzy Finder: https://github.com/junegunn/fzf
" https://github.com/junegunn/fzf#search-syntax
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
nnoremap <a-l> :FZF<CR>
nnoremap <c-f> :Ag<CR>
" MRU: https://github.com/pbogut/fzf-mru.vim
Plug 'pbogut/fzf-mru.vim'
noremap <a-r> :FZFMru<CR>
" Ag: https://github.com/mileszs/ack.vim
Plug 'mileszs/ack.vim'
if executable('ag')
" ag: https://github.com/ggreer/the_silver_searcher
" brew install the_silver_searcher
" let g:ackprg = 'ag --nogroup --nocolor --column'
let g:ackprg = 'ag --vimgrep'
endif
autocmd FileType * nnoremap <buffer> gu :LAck! -t -w '<cword>'<cr>
" }
" Code Explore: {
" A Tree Explorer Plugin: https://github.com/scrooloose/nerdtree
Plug 'scrooloose/nerdtree'
noremap <F8> :NERDTreeToggle<CR>
noremap <a-g> :NERDTreeFind<CR>
let NERDTreeHighlightCursorline=1
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$' ]
" close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
Plug 'kshenoy/vim-signature'
" Displays Tags: https://github.com/majutsushi/tagbar
Plug 'majutsushi/tagbar'
" Fix On Mac: brew install ctags
nnoremap <F9> :TagbarToggle<CR>
" Vim Motions On Speed: https://github.com/easymotion/vim-easymotion
Plug 'easymotion/vim-easymotion'
" <leader>f{char} to move to {char}
map <leader>f <Plug>(easymotion-bd-f)
nmap <leader>f <Plug>(easymotion-overwin-f)
" s{char}{char} to move to {char}{char}
nmap <leader>s <Plug>(easymotion-overwin-f2)
" Move to line
map <leader>L <Plug>(easymotion-bd-jk)
nmap <leader>L <Plug>(easymotion-overwin-line)
" Move to word
map <leader>c <Plug>(easymotion-bd-w)
nmap <leader>c <Plug>(easymotion-overwin-w)
" VIM highlight on the fly: https://github.com/t9md/vim-quickhl
Plug 't9md/vim-quickhl'
nmap <Space>m <Plug>(quickhl-manual-this)
xmap <Space>m <Plug>(quickhl-manual-this)
nmap <Space>M <Plug>(quickhl-manual-reset)
xmap <Space>M <Plug>(quickhl-manual-reset)
" }
" Complete and Lint: {
" YouCompleteMe: http://valloric.github.io/YouCompleteMe/
" ./install.py --go-completer --js-completer --rust-completer --clang-completer
" rustup toolchain add nightly; rustup component add rust-src
" how to debug: `:YcmDebugInfo` to print YouCompleteMe debug information
Plug 'Valloric/YouCompleteMe'
" echo `rustc --print sysroot`/lib/rustlib/src/rust/src
let g:ycm_rust_src_path = $HOME."/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src"
if (len($VIRTUAL_ENV) > 0)
let g:ycm_python_binary_path = $VIRTUAL_ENV.'/bin/python'
else
let g:ycm_python_binary_path = g:python3_host_prog
endif
" }
" Go:
" https://github.com/fatih/vim-go
" Install tool dependencies: :GoInstallBinaries
" let $GOROOT = system("go env GOROOT")
Plug 'fatih/vim-go'
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_fmt_command = "goimports"
let g:go_fmt_options = {
\ 'goimports': '-local bitbucket.16financial.net',
\ }
set mmp=5000
" Rust: {
" https://github.com/rust-lang/rust.vim
Plug 'rust-lang/rust.vim'
" Format: rustup component add rustfmt-preview
" will not populate errors, see https://github.com/rust-lang/rust.vim/issues/109
let g:rustfmt_autosave = 1
let g:rustfmt_emit_files = 1
au FileType rust nnoremap <buffer> <a-f> :RustFmt<cr>
" webapi lib to support rust playgen integration
Plug 'mattn/webapi-vim'
let g:rust_clip_command = 'pbcopy'
" https://github.com/racer-rust/vim-racer
Plug 'racer-rust/vim-racer'
" let g:racer_cmd = "/path/to/racer/bin"
let g:racer_experimental_completer = 1
au FileType rust nnoremap <buffer> gd <Plug>(rust-def)
au FileType rust nnoremap <buffer> gs <Plug>(rust-def-split)
au FileType rust nnoremap <buffer> gx <Plug>(rust-def-vertical)
au FileType rust nnoremap <buffer> <leader>gd <Plug>(rust-doc)
" }
" TypeScript: {
" TS syntax highlight and custom indent
Plug 'leafgarland/typescript-vim'
let g:typescript_compiler_binary = 'tsc'
let g:typescript_compiler_options = ''
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow
" }
" LanguageClient: {
" https://github.com/autozimu/LanguageClient-neovim
Plug 'autozimu/LanguageClient-neovim', { 'branch': 'next', 'do': 'bash install.sh', }
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
" LanguageServers:
" https://github.com/palantir/python-language-server
" https://github.com/rust-lang/rls
" https://github.com/mads-hartmann/bash-language-server
" https://github.com/sourcegraph/javascript-typescript-langserver
" yarn global add javascript-typescript-langserver
let g:LanguageClient_serverCommands = {
\ 'python': ['/usr/local/bin/pyls'],
\ 'rust': ['~/.cargo/bin/rls'],
\ 'sh': ['bash-language-server', 'start'],
\ 'javascript': ['javascript-typescript-stdio'],
\ 'javascript.jsx': ['tcp://127.0.0.1:2089'],
\ }
" nnoremap <F5> :call LanguageClient_contextMenu()<CR>
" Or map each action separately
nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
" }
" Elixir:
" https://github.com/elixir-editors/vim-elixir
Plug 'elixir-editors/vim-elixir'
" https://github.com/slashmili/alchemist.vim
Plug 'slashmili/alchemist.vim'
"let g:alchemist#elixir_erlang_src = "/usr/local/share/src"
" Crystal:
" https://github.com/rhysd/vim-crystal
Plug 'rhysd/vim-crystal'
let g:crystal_auto_format = 1
" Slim-lang template engine in crystal https://github.com/elorest/vim-slang
Plug 'elorest/vim-slang'
" AppleScript:
Plug 'vim-scripts/applescript.vim'
" Dart:
" https://github.com/dart-lang/dart-vim-plugin
Plug 'dart-lang/dart-vim-plugin'
" Haskell:
Plug 'neovimhaskell/haskell-vim'
let g:haskell_enable_quantification = 1 " to enable highlighting of `forall`
let g:haskell_enable_recursivedo = 1 " to enable highlighting of `mdo` and `rec`
let g:haskell_enable_arrowsyntax = 1 " to enable highlighting of `proc`
let g:haskell_enable_pattern_synonyms = 1 " to enable highlighting of `pattern`
let g:haskell_enable_typeroles = 1 " to enable highlighting of type roles
let g:haskell_enable_static_pointers = 1 " to enable highlighting of `static`
let g:haskell_backpack = 1 " to enable highlighting of backpack keywords
" Fish:
Plug 'dag/vim-fish'
" FrontEnd: {
Plug 'mattn/emmet-vim'
" Only Enable in html, css
let g:user_emmet_install_global = 0
autocmd FileType html,css EmmetInstall
" let g:user_emmet_leader_key='<c-y>'
" Vue:
" https://github.com/posva/vim-vue
Plug 'posva/vim-vue'
autocmd FileType vue syntax sync fromstart
" Stylus:
" https://github.com/iloginow/vim-stylus
Plug 'iloginow/vim-stylus'
" convert stylus to css, then you can copy it
noremap <a-s> :%!stylus -p<CR>
noremap <a-S> :%!stylus -C<CR>
" JS Beatutify:
" Plug 'maksimr/vim-jsbeautify'
" autocmd FileType javascript noremap <buffer> <a-f> :call JsBeautify()<cr>
" " autocmd FileType json noremap <buffer> <a-f> :call JsonBeautify()<cr>
" autocmd FileType jsx noremap <buffer> <a-f> :call JsxBeautify()<cr>
" autocmd FileType html noremap <buffer> <a-f> :call HtmlBeautify()<cr>
" autocmd FileType css noremap <buffer> <a-f> :call CSSBeautify()<cr>
" Prettier:
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'branch': 'release/1.x',
\ 'for': [
\ 'javascript',
\ 'typescript',
\ 'css',
\ 'less',
\ 'scss',
\ 'json',
\ 'graphql',
\ 'markdown',
\ 'vue',
\ 'lua',
\ 'php',
\ 'ruby',
\ 'html',
\ 'swift' ] }
autocmd FileType typescript,javascript,css,less,scss,graphql,markdown,vue,lua,php,ruby,html,swift nmap <buffer> <a-f> <Plug>(Prettier)
" CoffeeScript: https://github.com/kchmck/vim-coffee-script
Plug 'kchmck/vim-coffee-script'
let coffee_indent_keep_current = 1
" }
" Edit Helper: (
" https://github.com/godlygeek/tabular
Plug 'godlygeek/tabular'
nmap <Leader>= :Tabularize /=<CR>
vmap <Leader>= :Tabularize /=<CR>
nmap <Leader>: :Tabularize /:\zs<CR>
vmap <Leader>: :Tabularize /:\zs<CR>
nmap <Leader>, :Tabularize /,<CR>
vmap <Leader>, :Tabularize /,<CR>
nmap <Leader>- :Tabularize /-><CR>
vmap <Leader>- :Tabularize /-><CR>
nmap <Leader># :Tabularize /#<CR>
vmap <Leader># :Tabularize /#<CR>
" https://github.com/Chiel92/vim-autoformat
Plug 'Chiel92/vim-autoformat'
" A Vim alignment plugin: https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'
" Comment Stuff Out: https://github.com/tpope/vim-commentary
Plug 'tpope/vim-commentary'
" Quoting Parenthesizing Made Simple: https://github.com/tpope/vim-surround
Plug 'tpope/vim-surround'
" use example:
" add ]: ysiw]
" replace " with <p>: cs"<p>
" replace ] with "{ ": cs]{
" replace ] with "{" : cs]}
" https://github.com/jiangmiao/auto-pairs
Plug 'jiangmiao/auto-pairs'
" Replace:
" https://github.com/tpope/vim-abolish
Plug 'tpope/vim-abolish'
Plug 'alvan/vim-closetag'
let g:closetag_filenames = '*.html,*.xhtml,*.phtml,*.vue'
" )
" Misc: {{
Plug 'elzr/vim-json'
let g:vim_json_syntax_conceal = 0
Plug 'mogelbrod/vim-jsonpath'
au FileType json noremap <buffer> <silent> <expr> <leader>p jsonpath#echo()
au FileType json noremap <buffer> <silent> <expr> <leader>g jsonpath#goto()
" markdown tagbar: https://github.com/lvht/tagbar-markdown
Plug 'lvht/tagbar-markdown'
" markdown table: https://github.com/dhruvasagar/vim-table-mode
" using the plugin in the on-the-fly mode use :TableModeToggle mapped to <Leader>tm by default
Plug 'dhruvasagar/vim-table-mode'
let g:table_mode_corner='|'
" You can visually select multiple lines and call `:Tableize` on it
" or alternatively use the mapping <Leader>tt defined by the g:table_mode_tableize_map option
" <Leader>tdd delete row
" <Leader>tdc delete column
" i| or a| for manipulating table cells
" Nginx
Plug 'chr4/nginx.vim'
" au BufRead,BufNewFile *.conf set ft=nginx
" Toml
Plug 'cespare/vim-toml'
" Moon: http://moonscript.org/
Plug 'leafo/moonscript-vim'
" Indent lines
Plug 'Yggdroot/indentLine'
" Git: https://github.com/tpope/vim-fugitive
Plug 'tpope/vim-fugitive'
" Protobuf:
" highlight https://github.com/uarun/vim-protobuf
Plug 'uarun/vim-protobuf'
autocmd FileType proto nnoremap <buffer> gd :LAck! --proto '(enum\|message) <cword> ?{'<cr>
" Browse GitHub Events In Vim: https://github.com/junegunn/vim-github-dashboard
Plug 'junegunn/vim-github-dashboard'
" let g:github_dashboard = { 'username': 'you', 'password': 'secret' }
let g:github_dashboard = { 'username': 'weaming', 'password': '41afa9b7fabcbfbe66fe25568da9e306a20286bf' }
" With authentication
" :GHDashboard
" :GHDashboard USER
" :GHActivity
" :GHActivity USER
" :GHActivity USER/REPO
" Without authentication (60 calls/hour limit, only public activities)
" :GHDashboard! USER
" :GHActivity! USER
" :GHActivity! USER/REPO
" Wakatime: https://github.com/wakatime/vim-wakatime
" key: 13003dd6-2510-480a-b17a-a8500cdd0799
Plug 'wakatime/vim-wakatime'
let g:wakatime_PythonBinary = 'python'
" Narrow Region: https://github.com/chrisbra/NrrwRgn
Plug 'chrisbra/NrrwRgn'
" Latex:
Plug 'lervag/vimtex'
let g:tex_flavor='latex'
" XeTeX is an extension to the TeX engine that allows the use of open type fonts installed to the operating system.
" luatex is an implementation of the TeX engine that has the lua programming language embedded in it.
" https://tex.stackexchange.com/questions/36/differences-between-luatex-context-and-xetex
let g:vimtex_compiler_latexmk_engines = {
\ '_' : '-xelatex',
\ 'pdflatex' : '-pdf',
\ 'dvipdfex' : '-pdfdvi',
\ 'lualatex' : '-lualatex',
\ 'xelatex' : '-xelatex',
\ 'context (pdftex)' : '-pdf -pdflatex=texexec',
\ 'context (luatex)' : '-pdf -pdflatex=context',
\ 'context (xetex)' : '-pdf -pdflatex=''texexec --xtx''',
\}
let g:vimtex_view_method='skim'
let g:vimtex_quickfix_mode=0
" set conceallevel=0
" let g:tex_conceal='abdmg'
let g:tex_conceal='' " disable conceal
" Snippets:
Plug 'sirver/ultisnips'
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
" Words Completion:
if has('unix')
set dictionary+=/usr/share/dict/words
else
set dictionary+=~/AppData/Local/nvim/words
endif
set complete+=k
" Shell: https://github.com/Shougo/deol.nvim
Plug 'Shougo/deol.nvim'
" tnoremap <ESC> <C-\><C-n>
nnoremap <c-z> :vnew<cr>:Deol -command=/bin/zsh <cr>
" }}
call plug#end()
" }}}
" post plug#end
call ale#linter#Define('go', {
\ 'name': 'revive',
\ 'output_stream': 'both',
\ 'executable': 'revive',
\ 'read_buffer': 0,
\ 'command': 'revive -config ' . $HOME . '/.config/revive.toml' . ' %t',
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})
" Basic {{{
set termguicolors
filetype plugin indent on
" colorscheme gruvbox
colorscheme space-vim-dark
set relativenumber number
" 去掉欢迎界面
set shortmess=atI
" 语法高亮开启
syntax on
" autocmd FileType json set syntax=off
autocmd BufEnter * :syntax sync fromstart
" 显示括号配对情况
set showmatch
" 匹配括号显示时长
set matchtime=2
set cursorline
set cursorcolumn
" visual autocomplete for command menu
set wildmenu
" }}}
" Global leader and other keys {{{
" 设置 leader 为 ,
let mapleader=","
let maplocalleader=","
" leader*2 ==> esc [i,v]
vnoremap <leader><leader> <ESC>
" jk ==> esc [i]
inoremap jk <esc>l
" ; ==> :
nnoremap ; :
" @@ ==> 邮箱
" iabbrev @@ garden.yuen@gmail.com
"Go to the head and end
noremap Q ^
noremap E $
" }}}
" Status line {{{
" 显示按键
set showcmd
" 显示模式状态
set showmode
set ruler
" 高度
set cmdheight=2
set visualbell
"显示特殊字符,其中Tab使用高亮~代替,尾部空白使用高亮点号代替
"set list
" 按键超时
set timeout timeoutlen=800
" }}}
" Encoding {{{
" 设置gvim内部编码,默认不更改
set encoding=utf-8
" 设置当前文件编码,可以更改,如:gbk(同cp936)
set fileencoding=utf-8
" 设置支持打开的文件的编码
set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1
" 文件格式,默认 ffs=dos,unix
set fileformat=unix "设置新(当前)文件的<EOL>格式,可以更改,如:dos(windows系统常用)
set fileformats=unix,dos,mac "给出文件的<EOL>格式类型
" Text tabs
" 空格代替tab
set expandtab
" >>命令缩进的大小=4
set shiftwidth=4
set tabstop=4
set softtabstop=4
"为不同的文件类型设置不同的空格数替换TAB
autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp,markdown set autoindent
autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp,markdown set shiftwidth=4
autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp,markdown set tabstop=4
autocmd FileType php,python,c,java,perl,shell,bash,vim,ruby,cpp,markdown set softtabstop=4
autocmd FileType javascript,html,css,xml,vue,yaml,elixir,stylus,jinja,ruby,crystal set autoindent
autocmd FileType javascript,html,css,xml,vue,yaml,elixir,stylus,jinja,ruby,crystal set shiftwidth=2
autocmd FileType javascript,html,css,xml,vue,yaml,elixir,stylus,jinja,ruby,crystal set tabstop=2
autocmd FileType javascript,html,css,xml,vue,yaml,elixir,stylus,jinja,ruby,crystal set softtabstop=2
autocmd FileType raml setlocal filetype=yaml
" 指定按一次backspace就删除shiftwidth宽度
set smarttab
" 按照 C 语言的语法,自动地调整缩进的长度
set cindent
" 自动地将当前行的缩进拷贝到新行,也就是"自动对齐”
set noautoindent
" 自动闭合缩进
set smartindent
" reload file
autocmd BufEnter,FocusGained * checktime
" }}}
" Folding {{{
" 启动时开启的折叠层数
set foldlevel=5
"折叠方式有 indent, marker, syntax,这里是indent
set foldmethod=indent
"read set config for each file
set modelines=1
set foldlevelstart=10
nnoremap <space> za
" }}}
" VIM CONFIG FILE {{{
" leader+ev ==> 编辑当前所使用的Vim配置文件 [n]
nnoremap <leader>ev <esc>:tabnew $MYVIMRC<cr>
" leader+sv ==> 载入当前所使用的Vim配置文件 [n]
"nnoremap <leader>sv :source $MYVIMRC<cr>
" }}}
" Tabs {{{
nnoremap <leader>h :tabfirst<cr>
nnoremap <leader>l :tablast<cr>
nnoremap <leader>j :tabnext<cr>
nnoremap <leader>k :tabprev<cr>
"move current tab to, default last
nnoremap <leader>m :tabm
"nnoremap <leader>bt :bufdo tab split<cr>
" Ctrl+t/n ==> 新建tab
nnoremap <C-n> :tabnew<CR>
nnoremap <C-c> :tabedit %<CR>
" }}}
" Function keys on keyboard {{{
" F3 切换绝对/相对行号
" F4 显示可打印字符开关
" F5 粘贴模式paste_mode开关,用于有格式的代码粘贴
" F6 语法开关,关闭语法可以加快大文件的展示
" F7 换行开关
"
" F8 开关NERDTree
" F9 开关Tagbar
" F10重新载入vim配置
nnoremap <F10> :source $MYVIMRC<cr>
function! NumberToggle()
if(&relativenumber == 1)
set norelativenumber number
else
set relativenumber
endif
endfunction
nnoremap <F3> :call NumberToggle()<cr> " 切换绝对/相对行号
nnoremap <F4> :set list! list?<CR>
set pastetoggle=<F5> "插入模式粘贴不会自动缩进避免混乱
nnoremap <F6> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR>
nnoremap <F7> :set wrap! wrap?<CR>
" }}}
" EDIT {{{
" copy text to system clipboard
set clipboard=unnamed
" leader+a ==> select All [n]
nnoremap <leader>sa ggVG
" leader+y ==> 将选中文本块复制至系统剪贴板 [n,v]
vnoremap <leader>y "+y
nnoremap <leader>y V"+y
" leader+p ==> 将系统剪贴板内容粘贴至 vim [n,v,i]
nnoremap <leader>p "+p
vnoremap <leader>p "+p
nnoremap <leader>o "0p
" leader+a ==> 复制所有至公共剪贴板 [n]
nnoremap <leader>a <esc>ggVG"+y<esc>
" < or > ==> 调整缩进后自动选中,方便再次操作 [v]
vnoremap < <gv
vnoremap > >gv
" Search
" magic and very-magic: http://vim.wikia.com/wiki/Simplifying_regular_expressions_using_magic_and_no-magic
nnoremap / /\v
" When 'ignorecase' and 'smartcase' are both on,
" if a pattern contains an uppercase letter, it is case sensitive, otherwise, it is not.
set ignorecase
set smartcase
" c+u 转换当前单词为大写 [i]
inoremap <c-u> <esc>viwU<esc>ea
" leader+['/"/`] ==> 为word添加引号 [n]
nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
nnoremap <leader>` viw<esc>a`<esc>hbi`<esc>lel
nnoremap <leader>* viw<esc>a*<esc>hbi*<esc>lel
" simple align current file [n]
nnoremap <leader>= mzgg=G`z
" add ; after line
nnoremap <a-;> mzA;<esc>`zmz
" add , after line
nnoremap <a-,> mzA,<esc>`zmz
" add new blank
nnoremap <C-i><C-j> mzo<esc>`z
nnoremap <C-i><C-k> mzO<esc>`z
function! TwiddleCase(str)
if a:str ==# toupper(a:str)
let result = tolower(a:str)
elseif a:str ==# tolower(a:str)
let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
else
let result = toupper(a:str)
endif
return result
endfunction
vnoremap ~ y:call setreg('', TwiddleCase(@"), getregtype(''))<CR>gv""Pgv
" }}}
" Predefined register {{{
" add "" for line
nnoremap <leader>x" I""<esc>x$pj
" remove text after :
nnoremap <leader>x: 0f:Dj
" remove text after =
nnoremap <leader>x= 0f=Dj
" proto lines to json list
nnoremap <leader>xp I""<esc>xeplC,<esc>j
" }}}
" Windows {{{
" leader+q ==> 关闭当前分割窗口 [n,i]
nnoremap <a-q> <esc>:q<cr>
inoremap <a-q> <esc>:q<cr>
vnoremap <a-q> <esc>:q<cr>
" Swap top/bottom or left/right split
" Ctrl+W R
" Break out current window into a new tabview
" Ctrl+W T
" Close every window in the current tabview but the current one
" Ctrl+W o
nnoremap <silent> <Leader>_ :exe "resize " . (winheight(0) * 2/3)<CR>
nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "vertical resize " . (winwidth(0) * 2/3)<CR>
nnoremap <silent> <Leader>= :exe "vertical resize " . (winwidth(0) * 3/2)<CR>
" Ctrl + H 光标移动[插入模式]、切换左窗口[Normal模式]
inoremap <c-h> <left>
noremap <c-h> <c-w><c-h>
" Ctrl + L 光标移动[插入模式]、切换右窗口[Normal模式]
inoremap <c-l> <right>
noremap <c-l> <c-w><c-l>
" Ctrl + J 光标移动[插入模式]、切换下窗口[Normal模式]
inoremap <c-j> <down>
noremap <c-j> <c-w><c-j>
" Ctrl + K 光标移动[插入模式]、切换上窗口[Normal模式]
inoremap <c-k> <up>
noremap <c-k> <c-w><c-k>
" }}}
" SAVING {{{
" leader+w ==> 保存当前窗口内容 [n]
nnoremap <leader>w :w<CR>
" leader+w ==> 插入模式保存
"保存所有窗口内容并退出
"nnoremap <leader>WQ :wa<CR>:q<CR>
" leader+W ==> 无权限保存时sudo [n]
nnoremap <leader>W :w !sudo tee %<CR>
" leader+Q ==> 不做任何保存&退出 vim [n]
nnoremap <leader>Q :q!<CR>
nnoremap <leader>q :q<CR>
vnoremap <leader>q <esc>:q<CR>
" }}}
" AUTOCMD {{{
function! RemoveSpace()
silent! %s/\s\+$//g
silent! %s/\r$//g
:nohlsearch
endfunction
function! BeforeSave()
call RemoveSpace()
endfunction
augroup savefile
"clear existed command group with the same name
autocmd!
" 文件保存时,清除尾部多余空格
autocmd BufWritePre,FileAppendPre,FileWritePre,FilterWritePre * :call BeforeSave()
" 文件保存时,替换Tab为4个空格
"autocmd BufWritePre *.* retab! 4
" html文件读取或创建时不换行
autocmd BufNewFile,BufRead *.html setlocal nowrap
augroup END
" Auto close location list before closing buffer
augroup CloseLoclistWindowGroup
autocmd!
autocmd QuitPre * if empty(&buftype) | lclose | endif
augroup END
" }}}
" Auto groups {{{
augroup configgroup
autocmd!
autocmd VimEnter * highlight clear SignColumn
autocmd FileType python setlocal commentstring=#\ %s
autocmd BufEnter *.zsh-theme setlocal filetype=zsh
autocmd BufEnter Makefile setlocal noexpandtab
augroup END
" Hilight Cusor Word: https://stackoverflow.com/questions/1551231/highlight-variable-under-cursor-in-vim-like-in-netbeans
" see all avaliable colors
" : so $VIMRUNTIME/syntax/hitest.vim
autocmd CursorMoved * exe printf('match QuickScopePrimary /\V\<%s\>/', escape(expand('<cword>'), '/\'))
" }}}
" Backups {{{
set backup
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set backupskip=/tmp/*,/private/tmp/*
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set writebackup
" }}}
" New File: {{{
autocmd BufRead,BufNewFile *.{md,markdown} set filetype=markdown
autocmd BufNewFile *.sh,*.py,*.rb exec ":call SetTitle()"
function! SetTitle()
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
call append(line("."), "\# File Name : ".expand("%"))
call append(line(".")+1, "\# Author : weaming")
call append(line(".")+2, "\# Mail : garden.yuen@gmail.com")
call append(line(".")+3, "\# Created : ".strftime("20%y-%m-%d %H:%M:%S"))
call append(line(".")+4, "")
call append(line(".")+5, "")
endif
if &filetype == 'python'
call setline(1, "\#!/usr/bin/env python3")
call setline(2, "\# coding: utf-8")
call setline(3, "\"\"\"")
call setline(4, "Author : weaming")
call setline(5, "Created Time : ".strftime("20%y-%m-%d %H:%M:%S"))
call setline(6, "\"\"\"")
call setline(7, "")
endif
if &filetype == 'ruby'
call setline(1, "\#!/usr/bin/env ruby")
call setline(2, "\# Author : weaming")
call setline(3, "\# Created Time : ".strftime("20%y-%m-%d %H:%M:%S"))
call setline(4, "")
endif
endfunc
" }}}
" Call System Funtions: {{{
" nnoremap <a-j> :%!python -m json.tool<CR>
" pip install pretty-format-json
autocmd FileType json nnoremap <buffer> <a-f> :%!pretty_format_json<CR>
" pip3 install pretty-format-json or cargo install rs-cjy
autocmd FileType csv,json,yaml nnoremap <buffer> <a-l> :%!DATETIME_FORMAT='\%Y-\%m-\%d \%X' yaml_json<CR>
" autocmd FileType csv,json,yaml nnoremap <buffer> <a-c> :%!csv_json<CR>
autocmd FileType csv,json,yaml nnoremap <buffer> <a-c> :%!PRETTY=1 csv-json<CR>
" markdown
autocmd FileType markdown nnoremap <buffer> <a-f> :%!markdown-tabs-24.py /dev/stdin<CR>
" brew install tabular
" nnoremap <a-l> :%!tabular -f /dev/stdin -t yaml<CR>
" nnoremap <a-c> :%!tabular -f /dev/stdin -t csv<CR>
" data_convert.py
nnoremap <a-x> :%!data_convert keys-to-dict<CR>
" pip3 install generate-json-schema2
nnoremap <a-h> :%!generate-json-schema -f /dev/stdin<CR>
" nnoremap <a-h> :%!JSON_SCHEMA_VERSION="http://json-schema.org/draft-07/schema\#" generate-json-schema -f /dev/stdin<CR>
" pip3 install sqlparse
" au FileType sql nnoremap <buffer> <a-f> :%!sqlformat /dev/stdin -k upper -r<cr>
" scripts/python/sqlfmt.py
au FileType sql nnoremap <buffer> <a-f> :%!sqlfmt.py /dev/stdin<cr>
" example usage of scripts/python/parse-variable-style.py
nnoremap <c-a-t> :%!parse-variable-style SPACE_SEPARATOR TITLE<cr>
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment