From c0d82c312ce0df8866fa9f1bcdaf626fdfb3e709 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 14 Aug 2019 23:46:16 +0800 Subject: [PATCH] Clean Nvim config --- init.vim | 927 ++++++++++++++++++++++++++----------------------------- 1 file changed, 433 insertions(+), 494 deletions(-) diff --git a/init.vim b/init.vim index 58f2079..59051d5 100644 --- a/init.vim +++ b/init.vim @@ -9,6 +9,8 @@ " |___/ " " " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" The ascii art above is generated using service provided on this webpage: +" http://tinyurl.com/y6szckgd "{ Header and Licence "{{ header info @@ -20,7 +22,7 @@ " not recommend downloading this file and replace your own init.vim. Good " configurations are built over time and take your time to polish. " Author: jdhao (jdhao@hotmail.com). Blog: https://jdhao.github.io -" Update: 2019-07-13 20:56:51+0800 +" Update: 2019-08-14 16:05:14+0800 "}} "{{ License: MIT License @@ -48,62 +50,63 @@ "} "{ Variable -"{{ builtin variables -" path to Python 3 interpreter (must be an absolute path), make startup -" faster. see https://neovim.io/doc/user/provider.html. Change this variable +"{{ Builtin variables +" Path to Python 3 interpreter (must be an absolute path), make startup +" faster. See https://neovim.io/doc/user/provider.html. Change this variable " in accordance with your system. if executable('python') " The output of `system()` function contains a newline character which - " should be removed. + " should be removed. See + " https://vi.stackexchange.com/questions/2867/how-do-you-chomp-a-string-in-vim if has('win32') " for Windows let g:python3_host_prog=substitute(system('where python'), '.exe\n\+$', '', 'g') elseif has('unix') " for Linux and Mac let g:python3_host_prog=substitute(system('which python'), '\n\+$', '', 'g') endif else - echoerr 'Python executable is not found, either you have not installed Python - \ or you have not set the Python executable path correctly' + echoerr 'Python executable not found! You must install Python and set its PATH!' endif -" set custom mapping (use `:h mapleader` for more info) +" Custom mapping (see `:h mapleader` for more info) let mapleader = ',' "}} -"{{ disable loading certain plugin -" do not load netrw by default since I do not use it, see +"{{ Disable loading certain plugins +" Do not load netrw by default since I do not use it, see " https://github.com/bling/dotvim/issues/4 let g:loaded_netrwPlugin = 1 -" do not load tohtml.vim +" Do not load tohtml.vim let g:loaded_2html_plugin = 1 -" do not load zipPlugin.vim, gzip.vim and tarPlugin.vim (all these plugins are +" Do not load zipPlugin.vim, gzip.vim and tarPlugin.vim (all these plugins are " related to compressed files) let g:loaded_zipPlugin = 1 let loaded_gzip = 1 let g:loaded_tarPlugin = 1 -" do not use builtin matchit.vim and matchparen.vim +" Do not use builtin matchit.vim and matchparen.vim let loaded_matchit = 1 let g:loaded_matchparen = 1 "}} "} "{ Custom functions +" Remove trailing white space, see https://vi.stackexchange.com/a/456/15292 function! s:StripTrailingWhitespaces() abort - " remove trailing white space, see https://goo.gl/sUjgFi - let l:save = winsaveview() " vint: next-line -ProhibitCommandRelyOnUser -ProhibitCommandWithUnintendedSideEffect - keeppatterns %s/\s\+$//e + keeppatterns %s/\v\s+$//e call winrestview(l:save) endfunction -function! Cabbrev(key, value) abort - " create command alias safely, see https://bit.ly/2ImFOpL - " the following two functions are taken from answer below on SO - " https://stackoverflow.com/a/10708687/6064933 +" Remove trailing whitespace +nnoremap :call StripTrailingWhitespaces() +" Create command alias safely, see https://bit.ly/2ImFOpL. +" The following two functions are taken from answer below on SO: +" https://stackoverflow.com/a/10708687/6064933 +function! Cabbrev(key, value) abort execute printf('cabbrev %s (getcmdtype() == ":" && getcmdpos() <= %d) ? %s : %s', \ a:key, 1+len(a:key), Single_quote(a:value), Single_quote(a:key)) endfunction @@ -112,10 +115,9 @@ function! Single_quote(str) abort return "'" . substitute(copy(a:str), "'", "''", 'g') . "'" endfunction +" Check the syntax group in the current cursor position, +" see http://tinyurl.com/yyzgswxz and http://tinyurl.com/y3lxozey function! s:SynGroup() abort - " check the syntax group in the current cursor position, - " see http://tinyurl.com/yyzgswxz and http://tinyurl.com/y3lxozey - if !exists('*synstack') return endif @@ -123,41 +125,36 @@ function! s:SynGroup() abort endfunction nnoremap st :call SynGroup() +" Check if a colorscheme exists in runtimepath. +" The following two functions are inspired by https://stackoverflow.com/a/5703164/6064933. function! HasColorscheme(name) abort - " the following two functions are from - " https://stackoverflow.com/a/5703164/6064933 (with adaptation) - " check if a colorscheme exists in runtimepath - - let l:pat = 'colors/'.a:name.'.vim' + let l:pat = 'colors/' . a:name . '.vim' return !empty(globpath(&runtimepath, l:pat)) endfunction +" Check if an Airline theme exists in runtimepath. function! HasAirlinetheme(name) abort - " check if an Airline theme exists in runtimepath - - let l:pat = 'autoload/airline/themes/'.a:name.'.vim' + let l:pat = 'autoload/airline/themes/' . a:name . '.vim' return !empty(globpath(&runtimepath, l:pat)) endfunction +" Generate random integers in the range [Low, High] in pure vimscrpt, +" adapted from https://stackoverflow.com/a/12739441/6064933 function! RandInt(Low, High) abort - " generate random integer in the range [Low, High] in pure vimscrpt, - " adapted from http://tinyurl.com/y2o6rj3o - - let l:milisec = str2nr(matchstr(reltimestr(reltime()), '\v\.\zs\d+')) + let l:milisec = str2nr(matchstr(reltimestr(reltime()), '\v\.\zs\d+'), 10) return l:milisec % (a:High - a:Low + 1) + a:Low endfunction -set foldcolumn=0 +" Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292 function! VimFolds(lnum) - " custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292 - + " get content of current line and the line below let l:cur_line = getline(a:lnum) let l:next_line = getline(a:lnum+1) if l:cur_line =~# '^"{' - return '>' . (matchend(l:cur_line, '"{*')-1) + return '<' . (matchend(l:cur_line, '"{*') - 1) else - if l:cur_line ==# '' && (matchend(l:next_line, '"{*')-1) == 1 + if l:cur_line ==# '' && (matchend(l:next_line, '"{*') - 1) == 1 return 0 else return '=' @@ -165,99 +162,105 @@ function! VimFolds(lnum) endif endfunction +" Custom fold text, adapted from https://vi.stackexchange.com/a/3818/15292 +" and https://vi.stackexchange.com/a/6608/15292 function! MyFoldText() - " custom fold text, adapted from https://vi.stackexchange.com/a/3818/15292 - " and https://vi.stackexchange.com/a/6608/15292 - let line = getline(v:foldstart) let nucolwidth = &foldcolumn + &number * &numberwidth let windowwidth = winwidth(0) - nucolwidth - 3 - let foldedlinecount = v:foldend - v:foldstart + let folded_line_num = v:foldend - v:foldstart " expand tabs into spaces let chunks = split(line, "\t", 1) let line = join(map(chunks[:-2], 'v:val . repeat(" ", &tabstop - strwidth(v:val) % &tabstop)'), '') . chunks[-1] - let line = strpart(line, 0, windowwidth - 2 - len(foldedlinecount)) - " let fillcharcount = windowwidth - len(line) - len(foldedlinecount) - 80 - let fillcharcount = &textwidth - len(line) - len(foldedlinecount) - 8 - return line . '...'. repeat('-', fillcharcount) . ' (' . foldedlinecount . ' L)' + let line = strpart(line, 0, windowwidth - 2 - len(folded_line_num)) + let fillcharcount = &textwidth - len(line) - len(folded_line_num) - 8 + return line . '...'. repeat('-', fillcharcount) . ' (' . folded_line_num . ' L)' endfunction "} "{ Builtin options and settings -" changing fillchars for folding, so there is no garbage charactes +" Changing fillchars for folding, so there is no garbage charactes set fillchars=fold:\ ,vert:\| -" paste mode toggle, it seems that neovim's bracketed paste mode +" Paste mode toggle, it seems that Neovim's bracketed paste mode " does not work very well for nvim-qt, so we use good-old paste mode set pastetoggle= -" split window below/right when creating horizontal/vertical windows +" Split window below/right when creating horizontal/vertical windows set splitbelow splitright -" Time in milliseconds to wait for a mapped sequence to complete +" Time in milliseconds to wait for a mapped sequence to complete, " see https://goo.gl/vHvyu8 for more info -set timeoutlen=800 +set timeoutlen=500 -" for CursorHold events +" For CursorHold events set updatetime=2000 -" clipboard settings, always use clipboard for all delete, yank, change, put +" Clipboard settings, always use clipboard for all delete, yank, change, put " operation, see https://goo.gl/YAHBbJ set clipboard+=unnamedplus -set noswapfile " disable creating swapfiles, see https://goo.gl/FA6m6h +" Disable creating swapfiles, see https://goo.gl/FA6m6h +set noswapfile -" general tab settings +" General tab settings set tabstop=4 " number of visual spaces per TAB set softtabstop=4 " number of spaces in tab when editing set shiftwidth=4 " number of spaces to use for autoindent set expandtab " expand tab to spaces so that tabs are spaces -set showmatch " highlight matching bracket -set matchpairs+=<:>,「:」 " matching pairs of characters +" Set matching pairs of characters and highlight matching brackets +set matchpairs+=<:>,「:」 +set showmatch -" show line number and relative line number +" Show line number and relative line number set number relativenumber -" ignore case in general, but become case-sensitive when uppercase present +" Ignore case in general, but become case-sensitive when uppercase is present set ignorecase smartcase -" encoding settings for vim +" File and script encoding settings for vim set fileencoding=utf-8 set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1 -scriptencoding utf-8 " set the script encoding (`:h :scriptencoding`) +scriptencoding utf-8 -" line will break at predefined characters +" Break line at predefined characters set linebreak -" character to show before the lines that have been soft-wrapped +" Character to show before the lines that have been soft-wrapped set showbreak=↪ -" list all items and start selecting matches +" List all items and start selecting matches in cmd completion set wildmode=list:full -set cursorline " whether to show the line cursor is in -set colorcolumn=80 " set a ruler at column 80, see https://goo.gl/vEkF5i -set signcolumn=yes " always show sign column +" Show current line cursor is in +set cursorline +" Set a ruler at column 80, see https://goo.gl/vEkF5i +set colorcolumn=80 -set scrolloff=5 " minimum lines to keep above and below cursor +" Minimum lines to keep above and below cursor when scrolling +set scrolloff=3 -" use mouse to select window and resizing window, etc +" Use mouse to select window and resizing window, etc if has('mouse') - set mouse=a " enable mouse in several mode - set mousemodel=popup " set the behaviour of mouse + " Enable mouse in several mode + set mouse=nv + " Set the behaviour of mouse + set mousemodel=popup endif -" do not show mode on command line since vim-airline can show it +" Do not show mode on command line since vim-airline can show it set noshowmode -set fileformats=unix,dos " fileformats to use for new file +" Fileformats to use for new files +set fileformats=unix,dos -set concealcursor=c " the mode in which cursorline text can be concealed +" The mode in which cursorline text can be concealed +set concealcursor=nc -" the way to show the result of substitution in real time for preview +" The way to show the result of substitution in real time for preview set inccommand=nosplit " ignore files or folders when globbing @@ -271,88 +274,99 @@ set wildignore+=*.aux,*.bbl,*.blg,*.brf,*.fls,*.fdb_latexmk,*.synctex.gz,*.pdf " Ask for confirmation when handling unsaved or read-only files set confirm -" use visual bells to indicate errors, do not use errorbells +" Use visual bells to indicate errors, do not use errorbells set visualbell noerrorbells -set foldlevel=0 " the level we start to fold +" The level we start to fold +set foldlevel=0 -set history=500 " the number of command and search history to keep +" The number of command and search history to keep +set history=500 -" use list mode and customized listchars -set list listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:+ ",trail:·,eol:¬ +" Use list mode and customized listchars +set list listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:+ -set autowrite " auto write the file based on some condition +" Auto write the file based on some condition +set autowrite -" show hostname, full path of file and lastmod time on the window title. +" Show hostname, full path of file and last-mod time on the window title. " The meaning of the format str for strftime can be found in " http://tinyurl.com/l9nuj4a. The function to get lastmod time is drawn from " http://tinyurl.com/yxd23vo8 set title -set titlestring=%{hostname()}\ \ %F\ \ \ %{strftime('%Y-%m-%d\ %H:%M',getftime(expand('%')))} +set titlestring=%{hostname()}\ \ %{expand('%:p')}\ \ %{strftime('%Y-%m-%d\ %H:%M',getftime(expand('%')))} -set undofile " persistent undo even after you close and file and reopen it +" Persistent undo even after you close a file and re-open it +set undofile -" do not show "match xx of xx" and other messages during auto-completion +" Do not show "match xx of xx" and other messages during auto-completion set shortmess+=c -set completeopt+=noinsert " auto select the first completion entry -set completeopt+=menuone " show menu even if there is only one item -set completeopt-=preview " disable the preview window, see also https://goo.gl/18zNPD +" Completion behaviour +set completeopt+=noinsert " Auto select the first completion entry +set completeopt+=menuone " Show menu even if there is only one item +set completeopt-=preview " Disable the preview window -" settings for popup menu -set pumheight=15 " maximum number of items to show in popup menu -set pumblend=10 " pesudo-blend effect for popup menu +" Settings for popup menu +set pumheight=15 " Maximum number of items to show in popup menu +set pumblend=5 " Pesudo blend effect for popup menu -" scan files given by `dictionary` option +" Scan files given by `dictionary` option set complete+=k,kspell complete-=w complete-=b complete-=u complete-=t -set showtabline=2 " whether to show tabline to see currently opened files +" Dictionary files for different systems +let g:MY_DICT = stdpath('config') . '/dict/words' +let &dictionary = &dictionary . ',' . g:MY_DICT -" align indent to next multiple value of shiftwidth, for its meaning, +set spelllang=en,cjk " Spell languages + +" Align indent to next multiple value of shiftwidth, for its meaning, " see http://tinyurl.com/y5n87a6m set shiftround -set virtualedit=block " virtual edit is useful for visual block edit +" Virtual edit is useful for visual block edit +set virtualedit=all -" correctly break multi-byte characters such as CJK, +" Correctly break multi-byte characters such as CJK, " see http://tinyurl.com/y4sq6vf3 set formatoptions+=mM -" dictionary files for different systems -let g:MY_DICT = stdpath('config') . '/dict/words' -let &dictionary = &dictionary . ',' . g:MY_DICT -set spelllang=en,cjk " spell languages - -" tilde ~ is an operator (thus must be followed by motions like `e` or `w`) +" Tilde (~) is an operator, thus must be followed by motions like `e` or `w`. set tildeop "} "{ Custom key mappings -" save key strokes (now we do not need to press shift to enter command mode) -" vim-sneak has also mapped ;, so using the below mapping will break the map +" Save key strokes (now we do not need to press shift to enter command mode). +" Vim-sneak has also mapped `;`, so using the below mapping will break the map " used by vim-sneak nnoremap ; : +xnoremap ; : -" quick way to open command window +" Quicker way to open command window nnoremap q; q: -" quicker in insert mode, you must pick a rarely used character -" combination +" Quicker in insert mode inoremap jk -" paste non-linewise text above or below current cursor, +" Turn the word under cursor to upper case +inoremap viwUea + +" Turn the current word into title case +inoremap b~lea + +" Paste non-linewise text above or below current cursor, " see https://stackoverflow.com/a/1346777/6064933 nnoremap p m`op`` nnoremap P m`Op`` -" shortcut for faster save and quit +" Shortcut for faster save and quit nnoremap w :update -" saves the file if modified and quit +" Saves the file if modified and quit nnoremap q :x -" quit all opened buffers +" Quit all opened buffers nnoremap Q :qa -" navigation in the location and quickfix list +" Navigation in the location and quickfix list nnoremap [l :lpreviouszv nnoremap ]l :lnextzv nnoremap [L :lfirstzv @@ -362,19 +376,18 @@ nnoremap ]q :cnextzv nnoremap [Q :cfirstzv nnoremap ]Q :clastzv -" close location list or quickfix list if they are present, +" Close location list or quickfix list if they are present, " see https://goo.gl/uXncnS nnoremap \x :windo lclose cclose -" close a buffer and switching to another buffer, do not close the +" Close a buffer and switching to another buffer, do not close the " window, see https://goo.gl/Wd8yZJ nnoremap \d :bprevious bdelete # -" toggle search highlight, see https://goo.gl/3H85hh +" Toggle search highlight, see https://goo.gl/3H85hh nnoremap hl (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" -" Disable arrow key in vim, see https://goo.gl/s1yfh4 -" disable arrow key in normal and insert mode (use faster way!) +" Disable arrow key in vim, see https://goo.gl/s1yfh4. nnoremap nnoremap nnoremap @@ -384,7 +397,7 @@ inoremap inoremap inoremap -" insert a blank line below or above current line (do not move the cursor) +" Insert a blank line below or above current line (do not move the cursor), " see https://stackoverflow.com/a/16136133/6064933 nnoremap oo 'm`' . v:count1 . 'o``' nnoremap OO 'm`' . v:count1 . 'O``' @@ -393,94 +406,94 @@ nnoremap OO 'm`' . v:count1 . 'O``' " nnoremap OO @='m`O``' " the following two mappings work, but if you change double quote to single, it -" work not work +" will not work " nnoremap oo @="m`o\Esc>``" " nnoremap oo @="m`o\e``" -" insert a space after current character +" Insert a space after current character nnoremap ah -" yank from current cursor position to end of line (make it consistant with -" the behavior of D, C) +" Yank from current cursor position to the end of the line (make it +" consistent with the behavior of D, C) nnoremap Y y$ -" move cursor based on physical lines not the actual lines. +" Move the cursor based on physical lines, not the actual lines. nnoremap j (v:count == 0 ? 'gj' : 'j') nnoremap k (v:count == 0 ? 'gk' : 'k') -nnoremap $ g$ nnoremap ^ g^ nnoremap 0 g0 -" do not include white space character when using $ in visual mode, +" Do not include white space characters when using $ in visual mode, " see https://goo.gl/PkuZox -vnoremap $ g_ +xnoremap $ g_ -" jump to matching pairs easily in normal mode -nmap % +" Jump to matching pairs easily in normal mode +nnoremap % -" go to start or end of line easier +" Go to start or end of line easier nnoremap H ^ -nnoremap L $ +xnoremap H ^ +nnoremap L g_ +xnoremap L g_ -" resize windows using and h,j,k,l, inspiration from +" Resize windows using and h,j,k,l, inspiration from " https://goo.gl/vVQebo (bottom page). -" If you enable mouse support, shorcut below may not be necessary +" If you enable mouse support, shorcuts below may not be necessary. nnoremap < nnoremap > nnoremap - nnoremap + -" fast window switching, inspiration from +" Fast window switching, inspiration from " https://stackoverflow.com/a/4373470/6064933 nnoremap h nnoremap l nnoremap j nnoremap k -" continuous visual shifting (does not exit Visual mode), `gv` means +" Continuous visual shifting (does not exit Visual mode), `gv` means " to reselect previous visual area, see https://goo.gl/m1UeiT -vnoremap < >gv +xnoremap < >gv -" when completion menu is shown, use to select an item -" and do not add an annoying newline, otherwise, is just what it is, -" for more info , see https://goo.gl/KTHtrr and https://goo.gl/MH7w3b +" When completion menu is shown, use to select an item +" and do not add an annoying newline. Otherwise, is what it is. +" For more info , see https://goo.gl/KTHtrr and https://goo.gl/MH7w3b inoremap ((pumvisible())?("\"):("\")) -" use to close auto-completion menu +" Use to close auto-completion menu inoremap ((pumvisible())?("\"):("\")) -" edit and reload init.vim quickly +" Edit and reload init.vim quickly nnoremap ev :edit $MYVIMRC nnoremap sv :silent update $MYVIMRC source $MYVIMRC \ echomsg "Nvim config successfully reloaded!" -nnoremap :call StripTrailingWhitespaces() - -" reselect the text that has just been pasted +" Reselect the text that has just been pasted nnoremap v `[V`] -" use sane regex expression (see `:h magic` for more info) +" Use sane regex expression (see `:h magic` for more info) nnoremap / /\v -" find and replace (like Sublime Text 3) +" Find and replace (like Sublime Text 3) nnoremap :%s/ +xnoremap :s/ -" change current working directory locally and print cwd after that +" Change current working directory locally and print cwd after that, " see https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file nnoremap cd :lcd %:p:h:pwd -" use Esc to quit builtin terminal +" Use Esc to quit builtin terminal tnoremap -" toggle spell checking (autosave does not play well with z=, so we disable it +" Toggle spell checking (autosave does not play well with z=, so we disable it " when we are doing spell checking) nnoremap :set spell! :AutoSaveToggle inoremap :set spell! :AutoSaveToggle -" decrease indent level in insert mode with shift+tab +" Decrease indent level in insert mode with shift+tab inoremap < key +" Automatically save current file and execute it when pressing the key " it is useful for small script augroup filetype_auto_build_exec autocmd! @@ -498,7 +511,7 @@ augroup filetype_auto_build_exec \ -o %<&&./%< augroup END -" do not use smart case in command line mode +" Do not use smart case in command line mode, " extracted from https://goo.gl/vCTYdK augroup dynamic_smartcase autocmd! @@ -506,87 +519,77 @@ augroup dynamic_smartcase autocmd CmdLineLeave : set smartcase augroup END -" set textwidth for text file types +" Set textwidth for text file types augroup text_file_width autocmd! - " sometimes, automatic filetype detection is not right, so we need to + " Sometimes, automatic filetype detection is not right, so we need to " detect the filetype based on the file extensions autocmd FileType text,tex setlocal textwidth=79 autocmd BufNewFile,BufRead *.md,*.MD,*.markdown setlocal textwidth=79 augroup END -" do not use number and relative number for terminal inside nvim augroup term_settings autocmd! - " donot use number and relatiev number for terminal + " Do not use number and relative number for terminal inside nvim autocmd TermOpen * setlocal norelativenumber nonumber - " go to insert mode by default to start typing command + " Go to insert mode by default to start typing command autocmd TermOpen * startinsert augroup END -" start insert mode when open the command window -augroup cmd_mode_settings - autocmd! - autocmd CmdwinEnter [:] startinsert -augroup END - -" more accurate syntax highlighting? (see `:h syn-sync`) +" More accurate syntax highlighting? (see `:h syn-sync`) augroup accurate_syn_highlight autocmd! autocmd BufEnter * :syntax sync fromstart augroup END -" Return to last edit position when opening a file (see ':h line()') +" Return to last edit position when opening a file augroup resume_edit_position autocmd! autocmd BufReadPost * \ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit' - \ | execute "normal! g`\"zvzz" + \ | execute "normal! g`\"zvzz" \ | endif augroup END augroup vim_script_setting autocmd! - " set the folding related options for vim script. Setting folding option in - " modeline is annoying in that the modeline get executed each time the window - " focus is lost (see http://tinyurl.com/yyqyyhnc) + " Set the folding related options for vim script. Setting folding option + " in modeline is annoying in that the modeline get executed each time the + " window focus is lost (see http://tinyurl.com/yyqyyhnc) autocmd FileType vim set foldmethod=expr foldlevel=0 foldlevelstart=-1 autocmd FileType vim set foldexpr=VimFolds(v:lnum) foldtext=MyFoldText() - " autocmd FileType vim set foldexpr=VimFolds(v:lnum) " Simply set formatoptions without autocmd does not work for vim filetype " because the options are overruled by vim's default ftplugin for vim " script unfortunately. The following way to use autocmd seems quick and " dirty and may not even work (I do this because I don't want to - " split my vim config). For more discussions, see + " split my vim config). For more discussions, see " http://tinyurl.com/yyznar7r and http://tinyurl.com/zehso5h - " some format options when editting text file - " donot insert comment leader after hitting o or O + " Some format options when editting text files. + " Disable inserting comment leader after hitting o or O autocmd FileType vim setlocal formatoptions-=o - - " donot insert comment leader after hitting in insert mode + " Disable inserting comment leader after hitting in insert mode autocmd FileType vim setlocal formatoptions-=r - " use :help command for keyword when pressing `K` in vim file, + " Use :help command for keyword when pressing `K` in vim file, " see `:h K` and https://bre.is/wC3Ih-26u autocmd FileType vim setlocal keywordprg=:help augroup END -" display a message when the current file is not utf-8 encoded -" note that we need to use `unsilent` command here because of this issue: +" Display a message when the current file is not in utf-8 format. +" Note that we need to use `unsilent` command here because of this issue: " https://github.com/vim/vim/issues/4379 augroup non_utf8_file_warn autocmd! autocmd BufRead * if &fileencoding != 'utf-8' - \ | unsilent echomsg 'file not in utf-8 format!' | endif + \ | unsilent echomsg 'File not in UTF-8 format!' | endif augroup END -" automatically reload the file if it is changed outside of Nvim -" see https://unix.stackexchange.com/a/383044/221410. -" It seems that checktime command does not work in command line windows. we -" need to check if we are in command line window before executing this -" command. See also http://tinyurl.com/y6av4sy9 +" Automatically reload the file if it is changed outside of Nvim, see +" https://unix.stackexchange.com/a/383044/221410. It seems that `checktime` +" command does not work in command line. We need to check if we are in command +" line before executing this command. See also http://tinyurl.com/y6av4sy9. augroup auto_read autocmd! autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * @@ -597,23 +600,23 @@ augroup END "} -"{ Plugin install part +"{ Plugin installation part "{{ Vim-plug Install and plugin initialization -" auto-install vim-plug on different systems. -" For Windows, only Windows 10 with curl command installed are tested (after -" Windows 10 build 17063, source: http://tinyurl.com/y23972tt) -" The following script to install vim-plug are adapted from vim-plug -" wiki tips: https://github.com/junegunn/vim-plug/wiki/tips#tips +" Auto-install vim-plug on different systems if it does not exist. +" For Windows, only Windows 10 with curl installed are supported (after +" Windows 10 build 17063, source: http://tinyurl.com/y23972tt). +" The following script to install vim-plug is adapted from vim-plug +" wiki: https://github.com/junegunn/vim-plug/wiki/tips#tips if !executable('curl') - echomsg 'You have to install curl to install vim-plug or install vim-plug - \ yourself following the guide on vim-plug git repository' + echomsg 'You have to install curl to install vim-plug. Or install ' + \ . 'vim-plug yourself following the guide on vim-plug git repo' else - let g:VIM_PLUG_PATH = stdpath('config') . '/autoload/plug.vim' + let g:VIM_PLUG_PATH = expand(stdpath('config') . '/autoload/plug.vim') if empty(glob(g:VIM_PLUG_PATH)) echomsg 'Installing Vim-plug on your system' - silent execute '!curl -fLo ' . g:VIM_PLUG_PATH . ' --create-dirs - \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' + silent execute '!curl -fLo ' . g:VIM_PLUG_PATH . ' --create-dirs ' + \ . 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' augroup plug_init autocmd! @@ -623,8 +626,8 @@ else endif "}} -"{{ autocompletion related plugins -" set up directory to install all the plugins depending on the platform +"{{ Autocompletion related plugins +" Set up directory to install all the plugins depending on the platform if has('win32') let g:PLUGIN_HOME=expand('~/AppData/Local/nvim/plugged') else @@ -632,70 +635,66 @@ else endif call plug#begin(g:PLUGIN_HOME) -" settings for deoplete +" Auto-completion Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } -" snippet engine and snippet template -Plug 'SirVer/ultisnips' -Plug 'honza/vim-snippets' - -" for insert mode completion -Plug 'ervandew/supertab' - -" python source for deoplete +" Python source for deoplete Plug 'zchee/deoplete-jedi', { 'for': 'python' } -" vim source for deoplete +" Vim source for deoplete Plug 'Shougo/neco-vim', { 'for': 'vim' } -" for English word auto-completion +" English word auto-completion Plug 'deathlyfrantic/deoplete-spell' + +" Insert mode completion +Plug 'ervandew/supertab' "}} -"{{ python-related plugins +"{{ Python-related plugins " Python completion, goto definition etc. Plug 'davidhalter/jedi-vim', { 'for': 'python' } -" python syntax highlighting and more +" Python syntax highlighting and more Plug 'numirias/semshi', { 'do': ':UpdateRemotePlugins', 'for': 'python' } -" python indent (follows the PEP8 style) +" Python indent (follows the PEP8 style) Plug 'Vimjas/vim-python-pep8-indent', {'for': 'python'} -" python code folding +" Python code folding Plug 'tmhedberg/SimpylFold', { 'for': 'python' } "}} -"{{ search related plugins -" super fast movement with vim-sneak +"{{ Search related plugins +" Super fast movement with vim-sneak Plug 'justinmk/vim-sneak' -" improve vim incsearch +" Improve vim incsearch Plug 'haya14busa/is.vim' -" show match number for incsearch +" Show match number for incsearch Plug 'osyo-manga/vim-anzu' -" stay after pressing * and search selected text +" Stay after pressing * and search selected text Plug 'haya14busa/vim-asterisk' -" another grep tool (similar to Sublime Text Ctrl+Shift+F) +" Another grep tool (similar to Sublime Text Ctrl+Shift+F) " TODO: worth trying and exploring Plug 'dyng/ctrlsf.vim' -" a grep tool +" A greping tool Plug 'mhinz/vim-grepper', { 'on': ['Grepper', '(GrepperOperator)'] } -" file search, tag search and more +" File search, tag search and more if has('win32') Plug 'Yggdroot/LeaderF' else Plug 'Yggdroot/LeaderF', { 'do': './install.sh' } endif -" another similar plugin is command-t +" Another similar plugin is command-t " Plug 'wincent/command-t' -" only use fzf for Linux and Mac since fzf does not work well for Windows +" Only use fzf for Linux and Mac since fzf does not work well for Windows if has('unix') " fuzzy file search and more Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } @@ -703,19 +702,16 @@ if has('unix') endif "}} -"{{ color, theme, look -" fancy and cute start screen -Plug 'mhinz/vim-startify' - +"{{ UI: Color, theme etc. " A list of colorscheme plugin you may want to try. Find what suits you. -" Plug 'morhetz/gruvbox' Plug 'lifepillar/vim-gruvbox8' Plug 'sjl/badwolf' Plug 'ajmwagar/vim-deus' -Plug 'lifepillar/vim-solarized8' +Plug 'sainnhe/vim-color-desert-night' +Plug 'YorickPeterse/happy_hacking.vim' +" Plug 'lifepillar/vim-solarized8' " Plug 'sickill/vim-monokai' " Plug 'whatyouhide/vim-gotham' -" Plug 'arcticicestudio/nord-vim' " Plug 'rakr/vim-one' " Plug 'kaicataldo/material.vim' @@ -724,46 +720,49 @@ Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' "}} -"{{ plugin to deal with URL -" highlight URLs inside vim +"{{ Plugin to deal with URL +" Highlight URLs inside vim Plug 'itchyny/vim-highlighturl' -" For Windows and Mac, we can open URL in browser. For Linux, it may not be -" possible since we maybe in a server which disables GUI +" For Windows and Mac, we can open an URL in the browser. For Linux, it may +" not be possible since we maybe in a server which disables GUI. if has('win32') || has('macunix') " open URL in browser Plug 'tyru/open-browser.vim' endif "}} -"{{ navigation and tags plugin -" file explorer for vim +"{{ Navigation and tags plugin +" File explorer for vim Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] } -" only install these plugins if ctags are installed on the system +" Only install these plugins if ctags are installed on the system if executable('ctags') " plugin to manage your tags Plug 'ludovicchabant/vim-gutentags' - " show file tags in vim window Plug 'majutsushi/tagbar', { 'on': ['TagbarToggle', 'TagbarOpen'] } endif "}} -"{{ file editting plugin -" automatic insertion and deletion of a pair of characters +"{{ File editting plugin +" Snippet engine and snippet template +Plug 'SirVer/ultisnips' +Plug 'honza/vim-snippets' + +" Automatic insertion and deletion of a pair of characters Plug 'jiangmiao/auto-pairs' -" comment plugin +" Comment plugin Plug 'scrooloose/nerdcommenter' -" multiple cursor plugin like Sublime Text? +" Multiple cursor plugin like Sublime Text? " Plug 'mg979/vim-visual-multi' -" title character case +" Title character case Plug 'christoomey/vim-titlecase' -" autosave files on certain events +" Autosave files on certain events Plug '907th/vim-auto-save' " graphcial undo history, see https://github.com/mbbill/undotree @@ -772,100 +771,100 @@ Plug '907th/vim-auto-save' " another plugin to show undo history is: http://tinyurl.com/jlsgjy5 " Plug 'simnalamburt/vim-mundo' +" Manage your yank history if has('win32') || has('macunix') - " manage your yank history Plug 'svermeulen/vim-yoink' endif -" show marks in sign column for quicker navigation +" Show marks in sign column for quicker navigation Plug 'kshenoy/vim-signature' -" another good plugin to show signature +" Another good plugin to show signature " Plug 'jeetsukumaran/vim-markology' -" handy unix command inside Vim (Rename, Move etc.) +" Handy unix command inside Vim (Rename, Move etc.) Plug 'tpope/vim-eunuch' -" repeat vim motions +" Repeat vim motions Plug 'tpope/vim-repeat' -" show the content of register in preview window +" Show the content of register in preview window " Plug 'junegunn/vim-peekaboo' + +" IME toggle for Mac if has('macunix') - " IME toggle for Mac Plug 'rlue/vim-barbaric' endif "}} -"{{ linting, formating -" auto format tools -Plug 'sbdchd/neoformat' +"{{ Linting, formating +" Auto format tools +" Plug 'sbdchd/neoformat' " Plug 'Chiel92/vim-autoformat' -" syntax check and make +" Syntax check and make Plug 'neomake/neomake' -" another linting plugin +" Another linting plugin " Plug 'w0rp/ale' "}} -"{{ git related plugins -" show git change (change, delete, add) signs in vim sign column +"{{ Git related plugins +" Show git change (change, delete, add) signs in vim sign column Plug 'mhinz/vim-signify' -" another similar plugin +" Another similar plugin " Plug 'airblade/vim-gitgutter' -" git command inside vim +" Git command inside vim Plug 'tpope/vim-fugitive' -" git commit browser +" Git commit browser Plug 'junegunn/gv.vim', { 'on': 'GV' } "}} -"{{ plugins for markdown writing -" distraction free writing +"{{ Plugins for markdown writing +" Distraction free writing Plug 'junegunn/goyo.vim', { 'for': 'markdown' } -" only light on your cursor line to help you focus +" Only light on your cursor line to help you focus Plug 'junegunn/limelight.vim', {'for': 'markdown'} -" markdown syntax highlighting +" Markdown syntax highlighting Plug 'vim-pandoc/vim-pandoc-syntax', { 'for': 'markdown' } -" another markdown plugin +" Another markdown plugin Plug 'plasticboy/vim-markdown', { 'for': 'markdown' } -" If we are on Win or Mac, preview the markdown in system default browser. -if has('win32') || has('macunix') - " markdown previewing - Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug'] } -endif - -" faster footnote generation +" Faster footnote generation Plug 'vim-pandoc/vim-markdownfootnotes', { 'for': 'markdown' } -" vim tabular plugin for manipulate tabular, required by markdown plugins +" Vim tabular plugin for manipulate tabular, required by markdown plugins Plug 'godlygeek/tabular' -" markdown JSON header highlight plugin +" Markdown JSON header highlight plugin Plug 'elzr/vim-json', { 'for': ['json', 'markdown'] } + +" Markdown previewing (only for Mac and Windows) +if has('win32') || has('macunix') + Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug'] } +endif "}} -"{{ text object plugins -" additional powerful text object for vim, this plugin should be studied +"{{ Text object plugins +" Additional powerful text object for vim, this plugin should be studied " carefully to use its full power Plug 'wellle/targets.vim' " Plugin to manipulate characer pairs quickly Plug 'tpope/vim-surround' -" add indent object for vim (useful for languages like Python) +" Add indent object for vim (useful for languages like Python) Plug 'michaeljsmith/vim-indent-object' -" create custom text object (needed by vim-text-object-entire) +" Create custom text object (needed by vim-text-object-entire) Plug 'kana/vim-textobj-user' -" text object for entire buffer, add `ae` and `ie` +" Text object for entire buffer, add `ae` and `ie` Plug 'kana/vim-textobj-entire' "}} @@ -882,11 +881,11 @@ if ( has('macunix') || has('win32') ) && executable('latex') endif "}} -"{{ tmux related plugins +"{{ Tmux related plugins " Since tmux is only available on Linux and Mac, we only enable these plugins " for Linux and Mac if has('unix') && executable('tmux') - " let vim detect tmux focus event correctly, see + " Let vim detect tmux focus event correctly, see " http://tinyurl.com/y4xd2w3r and http://tinyurl.com/y4878wwm Plug 'tmux-plugins/vim-tmux-focus-events' @@ -895,20 +894,20 @@ if has('unix') && executable('tmux') endif "}} -"{{ misc plugins -" automatically toggle line number based on several conditions +"{{ Misc plugins +" Automatically toggle line number based on several conditions Plug 'jeffkreeftmeijer/vim-numbertoggle' -" highlight yanked region +" Highlight yanked region Plug 'machakann/vim-highlightedyank' -" quickly run a code script +" Quickly run a code script Plug 'thinca/vim-quickrun' -" modern matchit implementation +" Modern matchit implementation Plug 'andymass/vim-matchup' -" simulating smooth scroll motions with physcis +" Simulating smooth scroll motions with physcis Plug 'yuttie/comfortable-motion.vim' Plug 'tpope/vim-scriptease' @@ -917,11 +916,11 @@ call plug#end() "} "{ Plugin settings -"{{ vim-plug settings -" use shortnames for common vim-plug command to reduce typing +"{{ Vim-plug settings +" Use shortnames for common vim-plug command to reduce typing. " To use these shortcut: first activate command line with `:`, then input the -" short alias name, e.g., `pi`, then press , the alias will be expanded -" to the original command automatically +" short alias, e.g., `pi`, then press , the alias will be expanded +" to the full command automatically call Cabbrev('pi', 'PlugInstall') call Cabbrev('pud', 'PlugUpdate') call Cabbrev('pug', 'PlugUpgrade') @@ -929,25 +928,19 @@ call Cabbrev('ps', 'PlugStatus') call Cabbrev('pc', 'PlugClean') "}} -"{{ auto-completion related +"{{ Auto-completion related """""""""""""""""""""""""""" deoplete settings"""""""""""""""""""""""""" -" wheter to enable deoplete automatically after start nvim -let g:deoplete#enable_at_startup = 0 +" Wheter to enable deoplete automatically after start nvim +let g:deoplete#enable_at_startup = 1 -" start deoplete when we go to insert mode -augroup deoplete_start - autocmd! - autocmd InsertEnter * call deoplete#enable() -augroup END - -" maximum candidate window length +" Maximum candidate window width call deoplete#custom#source('_', 'max_menu_width', 80) -" minimum character length needed to start completion, +" Minimum character length needed to activate auto-completion, " see https://goo.gl/QP9am2 call deoplete#custom#source('_', 'min_pattern_length', 1) -" whether to disable completion for certain syntax +" Whether to disable completion for certain syntax " call deoplete#custom#source('_', { " \ 'filetype': ['vim'], " \ 'disabled_syntaxes': ['String'] @@ -957,91 +950,90 @@ call deoplete#custom#source('_', { \ 'disabled_syntaxes': ['Comment'] \ }) -" ignore certain sources, because they only cause nosie most of the time +" Ignore certain sources, because they only cause nosie most of the time call deoplete#custom#option('ignore_sources', { \ '_': ['around', 'buffer', 'tag'] \ }) -" candidate list item limit +" Candidate list item number limit call deoplete#custom#option('max_list', 30) -"The number of processes used for the deoplete parallel feature. +" The number of processes used for the deoplete parallel feature. call deoplete#custom#option('num_processes', 16) -" Delay the completion after input in milliseconds. +" The delay for completion after input, measured in milliseconds. call deoplete#custom#option('auto_complete_delay', 100) -" enable or disable deoplete auto-completion +" Enable deoplete auto-completion call deoplete#custom#option('auto_complete', v:true) -" automatically close function preview windows after completion +" Automatically close function preview windows after completion " see https://goo.gl/Bn5n39 " autocmd InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif -" deoplete tab-complete, see https://goo.gl/LvwZZY +" Tab-complete, see https://goo.gl/LvwZZY " inoremap pumvisible() ? "\" : "\" """""""""""""""""""""""""UltiSnips settings""""""""""""""""""" -" Trigger configuration. Do not use if you use -" https://github.com/Valloric/YouCompleteMe. +" Trigger configuration. Do not use if you use YouCompleteMe let g:UltiSnipsExpandTrigger='' -" shortcut to go to next position +" Shortcut to jump forward and backward in tabstop positions let g:UltiSnipsJumpForwardTrigger='' - -" shortcut to go to previous position let g:UltiSnipsJumpBackwardTrigger='' -" directory `my_snippets` should be put under your config directory (use -" `:echo stdpath('config')` to show the config directory). +" Configuration for custom snippets directory, see +" https://jdhao.github.io/2019/04/17/neovim_snippet_s1/ for details. let g:UltiSnipsSnippetDirectories=['UltiSnips', 'my_snippets'] """""""""""""""""""""""""supertab settings"""""""""""""""""""""""""" -" auto-close method preview window -"let g:SuperTabClosePreviewOnPopupClose = 1 +" Auto-close method preview window +let g:SuperTabClosePreviewOnPopupClose = 1 -" use the default top to bottom way for scroll, see https://goo.gl/APdo9V +" Use the default top to bottom way for scroll, see https://goo.gl/APdo9V let g:SuperTabDefaultCompletionType = '' -" shortcut to navigate forward and backward in completion menu +" Shortcut to navigate forward and backward in completion menu, " see https://is.gd/AoSv4m let g:SuperTabMappingForward = '' let g:SuperTabMappingBackward = '' "}} -"{{ python-related +"{{ Python-related """"""""""""""""""deoplete-jedi settings""""""""""""""""""""""""""" -" whether to show doc string +" Whether to show doc string let g:deoplete#sources#jedi#show_docstring = 0 -" for large package, set autocomplete wait time longer +" For large package, set autocomplete wait time longer let g:deoplete#sources#jedi#server_timeout = 50 -" ignore jedi errors during completion +" Ignore jedi errors during completion let g:deoplete#sources#jedi#ignore_errors = 1 """"""""""""""""""""""""jedi-vim settings""""""""""""""""""" -" disable autocompletion, because I use deoplete for auto-completion +" Disable autocompletion, because I use deoplete for auto-completion let g:jedi#completions_enabled = 0 -" whether to show function call signature +" Whether to show function call signature let g:jedi#show_call_signatures = '0' """""""""""""""""""""""""" semshi settings """"""""""""""""""""""""""""""" -" do not highlight variable under cursor, it is distracting +" Do not highlight for all occurances of variable under cursor let g:semshi#mark_selected_nodes=0 -" do not show error sign since neomake is specicialized for that +" Do not show error sign since neomake is specicialized for that let g:semshi#error_sign=v:false """""""""""""""""""""""""" simpylFold settings """"""""""""""""""""""""""""""" -" do not fold docstring +" Do not fold docstring let g:SimpylFold_fold_docstring = 0 "}} -"{{ search related +"{{ Search related """""""""""""""""""""""""""""vim-sneak settings""""""""""""""""""""""" +" Use sneak label mode let g:sneak#label = 1 + nmap f Sneak_s xmap f Sneak_s onoremap f :call sneak#wrap(v:operator, 2, 0, 1, 1) @@ -1049,23 +1041,23 @@ nmap F Sneak_S xmap F Sneak_S onoremap F :call sneak#wrap(v:operator, 2, 1, 1, 1) -" immediately after entering sneak mode, you can press f and F to go to next +" Immediately after entering sneak mode, you can press f and F to go to next " or previous match let g:sneak#s_next = 1 """"""""""""""""""""""""""""is.vim settings""""""""""""""""""""""" -" to make is.vim work together well with vim-anzu and put current match in -" the center of the window -" `zz`: put cursor line in center of the window -" `zv`: open a fold to reveal the text when cursor step into it +" To make is.vim work together well with vim-anzu and put current match in +" the center of the window. +" `zz`: put cursor line in center of the window. +" `zv`: open a fold to reveal the text when cursor step into it. nmap n (is-nohl)(anzu-n-with-echo)zzzv nmap N (is-nohl)(anzu-N-with-echo)zzzv """""""""""""""""""""""""""""vim-anzu settings""""""""""""""""""""""" -" do not show search index in statusline since it is shown on command line +" Do not show search index in statusline since it is shown on command line let g:airline#extensions#anzu#enabled = 0 -" maximum number of words to search +" Maximum number of words to search let g:anzu_search_limit = 500000 """""""""""""""""""""""""""""vim-asterisk settings""""""""""""""""""""" @@ -1075,9 +1067,9 @@ nmap g* (asterisk-gz*)(is-nohl-1) nmap g# (asterisk-gz#)(is-nohl-1) """""""""""""""""""""""""fzf settings"""""""""""""""""""""""""" -" only use fzf on Mac and Linux, since it doesn't work well for Windows +" Only use fzf on Mac and Linux, since it doesn't work well for Windows if has('unix') - " hide status line when open fzf window + " Hide status line when open fzf window augroup fzf_hide_statusline autocmd! autocmd! FileType fzf @@ -1085,12 +1077,9 @@ if has('unix') \| autocmd BufLeave set laststatus=2 showmode ruler augroup END - " search file recursively under current folder + " Search file recursively under current folder nnoremap f :FZF - " search file recursively under HOME (You may do want to do this!) - " nnoremap F :FZF ~ - """""""""""""""""""""""""fzf.vim settings"""""""""""""""""" " Customize fzf colors to match your color scheme let g:fzf_colors = @@ -1111,11 +1100,9 @@ if has('unix') " [Tags] Command to generate tags file let g:fzf_tags_command = 'ctags -R' - " floating windows only works for latest nvim version - " floating window searching for fzf let $FZF_DEFAULT_OPTS = '--layout=reverse' - - " use floating window to open the fzf search window + " Floating windows only works for latest nvim version. + " Use floating window to open the fzf search window let g:fzf_layout = { 'window': 'call OpenFloatingWin()' } function! OpenFloatingWin() @@ -1124,7 +1111,7 @@ if has('unix') let width = float2nr(&columns - (&columns * 2 / 10)) let col = float2nr((&columns - width) / 2) - " set up the attribute of floating window + " Set up the attribute of floating window let opts = { \ 'relative': 'editor', \ 'row': height * 0.3, @@ -1136,7 +1123,7 @@ if has('unix') let buf = nvim_create_buf(v:false, v:true) let win = nvim_open_win(buf, v:true, opts) - " floating window highlight setting + " Floating window highlight setting call setwinvar(win, '&winhl', 'Normal:Pmenu') setlocal @@ -1153,64 +1140,59 @@ endif "{{ URL related """"""""""""""""""""""""""""open-browser.vim settings""""""""""""""""""" if has('win32') || has('macunix') - " disable netrw's gx mapping. + " Disable netrw's gx mapping. let g:netrw_nogx = 1 - " use another mapping for the open URL method + " Use another mapping for the open URL method nmap ob (openbrowser-smart-search) vmap ob (openbrowser-smart-search) endif -"{{ navigation and tags +"{{ Navigation and tags """"""""""""""""""""""" nerdtree settings """""""""""""""""""""""""" -" toggle nerdtree window and keep cursor in file window, +" Toggle nerdtree window and keep cursor in file window, " adapted from http://tinyurl.com/y2kt8cy9 nnoremap s :NERDTreeToggle:wincmd p -" reveal currently editted file in nerdtree widnow, +" Reveal currently editted file in nerdtree widnow, " see https://goo.gl/kbxDVK nnoremap f :NERDTreeFind -" ignore certain files and folders +" Ignore certain files and folders let NERDTreeIgnore = ['\.pyc$', '^__pycache__$'] -" exit vim when the only window is nerdtree window, see -" https://github.com/scrooloose/nerdtree -" autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && -" \ b:NERDTree.isTabTree()) | q | endif - -" automatically show nerdtree window on entering nvim, -" see https://github.com/scrooloose/nerdtree, but now the cursor +" Automatically show nerdtree window on entering nvim, +" see https://github.com/scrooloose/nerdtree. But now the cursor " is in nerdtree window, so we need to change it to the file window, " extracted from https://goo.gl/vumpvo " autocmd VimEnter * NERDTree | wincmd l -" delete a file buffer when you have deleted it in nerdtree +" Delete a file buffer when you have deleted it in nerdtree let NERDTreeAutoDeleteBuffer = 1 -" show current root as realtive path from HOME in status bar, +" Show current root as realtive path from HOME in status bar, " see https://github.com/scrooloose/nerdtree/issues/891 let NERDTreeStatusline="%{exists('b:NERDTree')?fnamemodify(b:NERDTree.root.path.str(), ':~'):''}" -" disable bookmark and 'press ? for help ' text +" Disable bookmark and 'press ? for help' text let NERDTreeMinimalUI=0 """"""""""""""""""""""""""" tagbar settings """""""""""""""""""""""""""""""""" -" shortcut to toggle tagbar window +" Shortcut to toggle tagbar window nnoremap t :TagbarToggle "}} -"{{ file editting +"{{ File editting """""""""""""""""""""""""""""auto-pairs settings""""""""""""""""""""""""" augroup filetype_custom_autopair autocmd! - " only use the following character pairs for tex file + " Only use the following character pairs for tex file au FileType tex let b:AutoPairs = {'(':')', '[':']', '{':'}'} - " add `<>` pair to filetype vim + " Add `<>` pair to filetype vim au FileType vim let b:AutoPairs = AutoPairsDefine({'<' : '>'}) - " do not use `"` for vim script since `"` is also used for comment + " Do not use `"` for vim script since `"` is also used for comment au FileType vim let b:AutoPairs = {'(':')', '[':']', '{':'}', "'":"'", "`":"`", '<':'>'} augroup END @@ -1218,7 +1200,7 @@ augroup END " Add spaces after comment delimiters by default let g:NERDSpaceDelims = 1 -" use one space after # comment character in python, +" Use one space after # comment character in python, " see http://tinyurl.com/y4hm29o3 let g:NERDAltDelims_python = 1 @@ -1230,7 +1212,7 @@ let g:NERDDefaultAlign = 'left' let g:NERDToggleCheckAllLines = 1 """"""""""""""""""""""""""""vim-titlecase settings""""""""""""""""""""""" -" do not use the default mapping provided +" Do not use the default mapping provided let g:titlecase_map_keys = 0 nmap gt Titlecase @@ -1238,42 +1220,43 @@ vmap gt Titlecase nmap gT TitlecaseLine """"""""""""""""""""""""vim-auto-save settings""""""""""""""""""""""" -" enable autosave on nvim startup +" Enable autosave on nvim startup let g:auto_save = 1 -" a list of events to trigger autosave -let g:auto_save_events = ['InsertLeave', 'TextChanged'] +" A list of events to trigger autosave +" let g:auto_save_events = ['InsertLeave', 'TextChanged'] +let g:auto_save_events = ['InsertLeave'] -" show autosave status on command line +" Show autosave status on command line let g:auto_save_silent = 0 """"""""""""""""""""""""""""vim-yoink settings""""""""""""""""""""""""" if has('win32') || has('macunix') " ctrl-n and ctrl-p will not work if you add the TextChanged event to " vim-auto-save events - " nmap (YoinkPostPasteSwapBack) - " nmap (YoinkPostPasteSwapForward) + nmap (YoinkPostPasteSwapBack) + nmap (YoinkPostPasteSwapForward) nmap p (YoinkPaste_p) nmap P (YoinkPaste_P) - " cycle the yank stack with the following mappings + " Cycle the yank stack with the following mappings nmap [y (YoinkRotateBack) nmap ]y (YoinkRotateForward) - " not change the cursor position + " Do not change the cursor position nmap y (YoinkYankPreserveCursorPosition) xmap y (YoinkYankPreserveCursorPosition) - " move cursor to end of paste after multiline paste + " Move cursor to end of paste after multiline paste let g:yoinkMoveCursorToEndOfPaste = 0 - " record yanks in system clipboard + " Record yanks in system clipboard let g:yoinkSyncSystemClipboardOnFocus = 1 endif """"""""""""""""""""""""""""""vim-signature settings"""""""""""""""""""""""""" -" change mark highlight to be more visible +" Change mark highlight to be more visible augroup signature_highlight autocmd! autocmd ColorScheme * highlight SignatureMarkText cterm=bold ctermbg=10 @@ -1281,35 +1264,37 @@ autocmd ColorScheme * highlight SignatureMarkText cterm=bold ctermbg=10 augroup END "}} -"{{ linting and formating +"{{ Linting and formating """""""""""""""""""""""""""""" neomake settings """"""""""""""""""""""" -" when to activate neomake +" When to activate neomake call neomake#configure#automake('nrw', 50) -" change warning signs and color, see https://goo.gl/eHcjSq -" highlight NeomakeErrorMsg ctermfg=227 ctermbg=237 +" Change warning signs and color, see https://goo.gl/eHcjSq. let g:neomake_warning_sign={'text': '!', 'texthl': 'NeomakeWarningSign'} let g:neomake_error_sign={'text': '✗'} -" which linter to enable for Python source file linting +" Linters enabled for Python source file linting let g:neomake_python_enabled_makers = ['pylint'] -" whether to open quickfix or location list automatically +" Whether to open quickfix or location list automatically let g:neomake_open_list = 0 + +" Which linter to use for TeX source files +let g:neomake_tex_enabled_makers = [] "}} -"{{ git-related +"{{ Git-related """""""""""""""""""""""""vim-signify settings"""""""""""""""""""""""""""""" -" the VCS to use +" The VCS to use let g:signify_vcs_list = [ 'git' ] -" change the sign for certain operations +" Change the sign for certain operations let g:signify_sign_change = '~' "}} "{{ Markdown writing """""""""""""""""""""""""goyo.vim settings"""""""""""""""""""""""""""""" -" make goyo and limelight work together automatically +" Make goyo and limelight work together automatically augroup goyo_work_with_limelight autocmd! autocmd! User GoyoEnter Limelight @@ -1317,50 +1302,49 @@ augroup goyo_work_with_limelight augroup END """""""""""""""""""""""""vim-pandoc-syntax settings""""""""""""""""""""""""" -" whether to conceal urls (seems does not work) +" Whether to conceal urls (seems does not work) let g:pandoc#syntax#conceal#urls = 0 -" use pandoc-syntax for markdown files, it will disable conceal feature for +" Use pandoc-syntax for markdown files, it will disable conceal feature for " links, use it at your own risk augroup pandoc_syntax au! BufNewFile,BufFilePre,BufRead *.md set filetype=markdown.pandoc augroup END """""""""""""""""""""""""plasticboy/vim-markdown settings""""""""""""""""""" -" disable header folding +" Disable header folding let g:vim_markdown_folding_disabled = 1 -" whether to use conceal feature in markdown +" Whether to use conceal feature in markdown let g:vim_markdown_conceal = 1 -" disable math tex conceal and syntax highlight +" Disable math tex conceal and syntax highlight let g:tex_conceal = '' let g:vim_markdown_math = 0 -" support front matter of various format +" Support front matter of various format let g:vim_markdown_frontmatter = 1 " for YAML format let g:vim_markdown_toml_frontmatter = 1 " for TOML format let g:vim_markdown_json_frontmatter = 1 " for JSON format -" let the TOC window autofit so that it doesn't take too much space +" Let the TOC window autofit so that it doesn't take too much space let g:vim_markdown_toc_autofit = 1 """""""""""""""""""""""""markdown-preview settings""""""""""""""""""" -" only setting this for suitable platforms +" Only setting this for suitable platforms if has('win32') || has('macunix') - " do not close the preview tab when switching to other buffers + " Do not close the preview tab when switching to other buffers let g:mkdp_auto_close = 0 - " shortcut to start markdown previewing - nnoremap :MarkdownPreview - nnoremap :MarkdownPreviewStop + " Shortcuts to start and stop markdown previewing + nnoremap :MarkdownPreview + nnoremap :MarkdownPreviewStop endif """"""""""""""""""""""""vim-markdownfootnotes settings"""""""""""""""""""""""" -" replace the default mappings provided by the plugin +" Replace the default mappings provided by the plugin imap ^^ AddVimFootnote nmap ^^ AddVimFootnote - imap @@ ReturnFromFootnote nmap @@ ReturnFromFootnote "}} @@ -1368,13 +1352,13 @@ nmap @@ ReturnFromFootnote "{{ LaTeX editting """"""""""""""""""""""""""""vimtex settings""""""""""""""""""""""""""""" if ( has('macunix') || has('win32')) && executable('latex') - " enhanced matching with matchup plugin + " Enhanced matching with matchup plugin let g:matchup_override_vimtex = 1 - " set up LaTeX flavor + " Set up LaTeX flavor let g:tex_flavor = 'latex' - " deoplete configurations for autocompletion to work + " Deoplete configurations for autocompletion to work call deoplete#custom#var('omni', 'input_patterns', { \ 'tex': g:vimtex#re#deoplete \}) @@ -1413,7 +1397,7 @@ if ( has('macunix') || has('win32')) && executable('latex') \ 'mode' : 2, \} - " viewer settings for different platforms + " Viewer settings for different platforms if has('win32') let g:vimtex_view_general_viewer = 'SumatraPDF' let g:vimtex_view_general_options_latexmk = '-reuse-instance' @@ -1453,13 +1437,13 @@ if ( has('macunix') || has('win32')) && executable('latex') endif "}} -"{{ status line, look +"{{ UI: Status line, look """""""""""""""""""""""""""vim-airline setting"""""""""""""""""""""""""""""" -" set a airline theme only if it exists, else we resort to default color -let s:candidate_airlinetheme = ['alduin', 'ayu_mirage', 'base16_flat', - \ 'monochrome', 'base16_grayscale', 'lucius', 'base16_tomorrow', +" Randomly pick and set an airline theme if it exists +let s:candidate_airlinetheme = ['ayu_mirage', 'base16_flat', + \ 'base16_grayscale', 'lucius', 'base16_tomorrow', 'ayu_dark', \ 'base16_adwaita', 'biogoo', 'distinguished', 'jellybeans', - \ 'luna', 'raven', 'seagull', 'term', 'vice', 'zenburn'] + \ 'luna', 'raven', 'seagull', 'term', 'vice', 'zenburn', 'tomorrow'] let s:idx = RandInt(0, len(s:candidate_airlinetheme)-1) let s:theme = s:candidate_airlinetheme[s:idx] @@ -1467,90 +1451,56 @@ if HasAirlinetheme(s:theme) let g:airline_theme=s:theme endif -" tabline settings -" show tabline +" Tabline settings let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#formatter = 'unique_tail_improved' -" buffer number display format -let g:airline#extensions#tabline#buffer_nr_format = '%s. ' -" show buffer number for easier switching between buffer +" Show buffer number for easier switching between buffer, " see https://github.com/vim-airline/vim-airline/issues/1149 let g:airline#extensions#tabline#buffer_nr_show = 1 -" whether to show function or other tags on status line +" Buffer number display format +let g:airline#extensions#tabline#buffer_nr_format = '%s. ' + +" Whether to show function or other tags on status line let g:airline#extensions#tagbar#enabled = 0 -" skip empty sections if nothing to show -" extract from https://vi.stackexchange.com/a/9637/15292 +" Skip empty sections if there are nothing to show, +" extracted from https://vi.stackexchange.com/a/9637/15292 let g:airline_skip_empty_sections = 1 -"make airline more beautiful, see https://goo.gl/XLY19H for more info +" Make airline more beautiful, see https://goo.gl/XLY19H for more info let g:airline_powerline_fonts = 1 -" show only hunks which is non-zero (git-related) +" Show only hunks which are non-zero (git-related) let g:airline#extensions#hunks#non_zero_only = 1 -" enable gutentags integration +" Enable gutentags integration let g:airline#extensions#gutentags#enabled = 1 -" speed up airline +" Speed up airline let g:airline_highlighting_cache = 1 - -" custom status line symbols -if !exists('g:airline_symbols') - let g:airline_symbols = {} -endif - -let g:airline_left_sep = '»' -let g:airline_left_sep = '▶' -let g:airline_right_sep = '«' -let g:airline_right_sep = '◀' -let g:airline_symbols.crypt = '🔒' -let g:airline_symbols.linenr = '☰' -let g:airline_symbols.linenr = '␊' -let g:airline_symbols.linenr = '␤' -let g:airline_symbols.linenr = '¶' -let g:airline_symbols.maxlinenr = '' -let g:airline_symbols.maxlinenr = '㏑' -let g:airline_symbols.branch = '⎇' -let g:airline_symbols.paste = 'ρ' -let g:airline_symbols.paste = 'Þ' -let g:airline_symbols.paste = '∥' -let g:airline_symbols.spell = 'Ꞩ' -let g:airline_symbols.notexists = 'Ɇ' -let g:airline_symbols.whitespace = 'Ξ' - -" powerline symbols -let g:airline_left_sep = '' -let g:airline_left_alt_sep = '' -let g:airline_right_sep = '' -let g:airline_right_alt_sep = '' -let g:airline_symbols.branch = '' -let g:airline_symbols.readonly = '' -let g:airline_symbols.linenr = '☰' -let g:airline_symbols.maxlinenr = '' "}} -"{{ misc plugin setting +"{{ Misc plugin setting """"""""""""""""""" vim-highlightedyank settings """""""""""""" -" reverse the highlight color for yanked text for better visuals +" Reverse the highlight color for yanked text for better visuals highlight HighlightedyankRegion cterm=reverse gui=reverse -" let highlight endures longer +" Let highlight endures longer let g:highlightedyank_highlight_duration = 1000 """"""""""""""""""""""""""""vim-matchup settings""""""""""""""""""""""""""""" -" whether to enable matching inside comment or string +" Whether to enable matching inside comment or string let g:matchup_delim_noskips = 0 -" change highlight color of matching bracket for better visual effects +" Change highlight color of matching bracket for better visual effects augroup matchup_matchparen_highlight autocmd! autocmd ColorScheme * highlight MatchParen cterm=underline gui=underline augroup END -" show matching keyword as underlined text to reduce color clutter +" Show matching keyword as underlined text to reduce color clutter augroup matchup_matchword_highlight autocmd! autocmd ColorScheme * hi MatchWord cterm=underline gui=underline @@ -1565,56 +1515,47 @@ let g:quickrun_config = {'outputter/buffer/close_on_empty': 1} let g:comfortable_motion_scroll_down_key = 'j' let g:comfortable_motion_scroll_up_key = 'k' -" mouse settings +" Mouse settings noremap :call comfortable_motion#flick(40) noremap :call comfortable_motion#flick(-40) "}} "} "{ Colorscheme and highlight settings -"{{ general settings about colors -" enable true colors support (do not use this option if your terminal does not -" support true colors. For a comprehensive list of terminals supporting true +"{{ General settings about colors +" Enable true colors support (Do not use this option if your terminal does not +" support true colors! For a comprehensive list of terminals supporting true " colors, see https://github.com/termstandard/colors and " https://bit.ly/2InF97t) set termguicolors -" use dark background (better for the eye, IMHO) +" Use dark background set background=dark "}} -"{{ colorscheme settings +"{{ Colorscheme settings """"""""""""""""""""""""""""gruvbox settings""""""""""""""""""""""""""" -" we should check if theme exists before using it, otherwise you will get +" We should check if theme exists before using it, otherwise you will get " error message when starting Nvim if HasColorscheme('gruvbox8') - " italic options should be put before colorscheme setting, + " Italic options should be put before colorscheme setting, " see https://goo.gl/8nXhcp let g:gruvbox_italics=1 let g:gruvbox_italicize_strings=1 let g:gruvbox_filetype_hi_groups = 0 let g:gruvbox_plugin_hi_groups = 0 colorscheme gruvbox8_hard -else - " fall back to a pre-installed theme - colorscheme desert endif """"""""""""""""""""""""""" deus settings""""""""""""""""""""""""""""""""" " colorscheme deus """"""""""""""""""""""""""" solarized8 settings""""""""""""""""""""""""" -" solarized colorscheme without bullshit +" Solarized colorscheme without bullshit " let g:solarized_term_italics=1 " let g:solarized_visibility="high" " colorscheme solarized8_high -""""""""""""""""""""""""""" nord-vim settings""""""""""""""""""""""""" -" let g:nord_italic = 1 -" let g:nord_underline = 1 -" let g:nord_italic_comments = 1 -" colorscheme nord - """"""""""""""""""""""""""" vim-one settings""""""""""""""""""""""""""""" " let g:one_allow_italics = 1 " colorscheme one @@ -1634,8 +1575,8 @@ endif "} "{ A list of resources which inspire me -" this list is non-exhaustive as I can not remember the source of many -" settings +" This list is non-exhaustive as I can not remember the source of many +" settings. " - http://stevelosh.com/blog/2010/09/coming-home-to-vim/ " - https://github.com/tamlok/tvim/blob/master/.vimrc @@ -1643,6 +1584,4 @@ endif " - https://blog.carbonfive.com/2011/10/17/vim-text-objects-the-definitive-guide/ " - https://sanctum.geek.nz/arabesque/vim-anti-patterns/ " - https://github.com/gkapfham/dotfiles/blob/master/.vimrc - -" The ascii art on the frontpage is generated using http://tinyurl.com/y6szckgd "} \ No newline at end of file