diff --git a/init.vim b/init.vim index 186c0e6..9f90f13 100644 --- a/init.vim +++ b/init.vim @@ -20,7 +20,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-05-06 21:53:28+0800 +" Update: 2019-05-11 19:46:55+0800 "}} "{{ License: MIT License @@ -49,15 +49,20 @@ "{ Variable "{{ builtin variables -" path to Python 3 interpreter (must be an absolute path), make startup faster. -" see https://neovim.io/doc/user/provider.html. You should change this -" variable in accordance with your system. -if has('win32') " for Windows - let g:python3_host_prog='D:/Anaconda/python' -elseif has('macunix') " for Mac - let g:python3_host_prog=expand('~/anaconda3/bin/python') -else " for Linux - let g:python3_host_prog=expand('~/tools/anaconda3/bin/python') +" 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') + if has('win32') " for Windows + " the output of `system()` function contains a newline character which + " should be removed + 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' endif " set custom mapping (use `:h mapleader` for more info) @@ -78,7 +83,7 @@ let g:loaded_zipPlugin = 1 let loaded_gzip = 1 let g:loaded_tarPlugin = 1 -" do not use matchit.vim and matchparen.vim +" do not use builtin matchit.vim and matchparen.vim let loaded_matchit = 1 let g:loaded_matchparen = 1 "}} @@ -86,11 +91,12 @@ let g:loaded_matchparen = 1 "{ Custom functions " remove trailing white space, see https://goo.gl/sUjgFi -" function! s:StripTrailingWhitespaces() abort -" let l:save = winsaveview() -" keeppatterns %s/\s\+$//e -" call winrestview(l:save) -" endfunction +function! s:StripTrailingWhitespaces() abort + let l:save = winsaveview() + " vint: next-line -ProhibitCommandRelyOnUser -ProhibitCommandWithUnintendedSideEffect + keeppatterns %s/\s\+$//e + call winrestview(l:save) +endfunction " create command alias safely, see https://bit.ly/2ImFOpL " the following two functions are taken from answer below on SO @@ -116,37 +122,23 @@ nnoremap st :call SynGroup() " the following two functions are from " https://stackoverflow.com/a/5703164/6064933 (with adaptation) - " check if a colorscheme exists in runtimepath function! HasColorscheme(name) abort - let pat = 'colors/'.a:name.'.vim' - return !empty(globpath(&runtimepath, pat)) + 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 - let pat = 'autoload/airline/themes/'.a:name.'.vim' - return !empty(globpath(&runtimepath, pat)) + let l:pat = 'autoload/airline/themes/'.a:name.'.vim' + return !empty(globpath(&runtimepath, l:pat)) endfunction -" generate a random integer from range [Low, High] using Python +" generate random integer in the range [Low, High] in pure vimscrpt, +" adapted from http://tinyurl.com/y2o6rj3o function! RandInt(Low, High) abort -" if you use Python 3, the python block should start with `python3` instead of -" `python`, see https://github.com/neovim/neovim/issues/9927 -python3 << EOF -import vim -import random - -# using vim.eval to import variable outside Python script to python -idx = random.randint(int(vim.eval('a:Low')), int(vim.eval('a:High'))) - -# using vim.command to export variable inside Python script to vim script so -# we can return its value in vim script -vim.command("let index = {}".format(idx)) -EOF - -" vint: next-line -ProhibitUsingUndeclaredVariable -return index + let l:milisec = str2nr(matchstr(reltimestr(reltime()), '\v\.\zs\d+')) + return l:milisec % (a:High - a:Low + 1) + a:Low endfunction " custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292 @@ -196,13 +188,12 @@ set fillchars=fold:\ ,vert:\| set pastetoggle= " split window below/right when creating horizontal/vertical windows -set splitbelow -set splitright +set splitbelow splitright " Time in milliseconds to wait for a mapped sequence to complete " see https://goo.gl/vHvyu8 for more info set timeoutlen=800 -set updatetime=1000 " speed up updatetime so changes show quicker +set updatetime=1000 " clipboard settings, always use clipboard for all delete, yank, change, put " operation, see https://goo.gl/YAHBbJ @@ -216,7 +207,7 @@ 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 showmatch " highlight matching bracket set matchpairs+=<:>,「:」 " matching pairs of characters " show line number and relative line number @@ -230,30 +221,34 @@ 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`) -set linebreak " line will break at predefined characters +" line will break at predefined characters +set linebreak +" character to show before the lines that have been soft-wrapped +set showbreak=↪ " list all items and start selecting matches set wildmode=list:longest,full -set cursorline " whether to show current line cursor is in -set colorcolumn=80 " set a ruler at column 80, see https://goo.gl/vEkF5i +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 set scrolloff=5 " minimum lines to keep above and below cursor " use mouse to select window and resizing window, etc if has('mouse') - set mouse=a " enable mouse in several mode (see `:h 'mouse'`) + set mouse=a " enable mouse in several mode set mousemodel=popup " set the behaviour of mouse endif -" do not show mode on command line because vim-airline can show it already +" 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 set concealcursor=c " the mode in which cursorline text can be concealed -" the way to show the result of subsitute 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 @@ -267,7 +262,7 @@ 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 error, 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 @@ -277,9 +272,6 @@ set history=500 " the number of command and search history to keep " use list mode and customized listchars set list listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:+ ",trail:·,eol:¬ -" string to show before the lines that have been soft-wrapped -set showbreak=↪ - set autowrite " auto write the file based on some condition " show hostname, full path of file and lastmod time on the window title. @@ -295,9 +287,8 @@ set undofile " persistent undo even after you close and file and reopen it set shortmess+=c set completeopt+=noinsert " auto select the first completion entry -set completeopt+=menuone " show menu even if there is only one item -" disable the preview window, see also https://goo.gl/18zNPD -set completeopt-=preview +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 " settings for popup menu set pumheight=15 " maximum number of items to show in popup menu @@ -314,8 +305,6 @@ set shiftround set virtualedit=block " virtual edit is useful for visual block edit -set signcolumn=yes " always show sign column - " correctly break multi-byte characters such as CJK, " see http://tinyurl.com/y4sq6vf3 set formatoptions+=mM @@ -325,10 +314,11 @@ let $MY_DICT = stdpath('config') . '/dict/words' set dictionary+=$MY_DICT set spelllang=en,cjk " spell languages -set lazyredraw - " tilde ~ is an operator (thus must be followed by motion like `c` or `d`) set tildeop + +" set pyx version to use python3 by default +set pyxversion=3 "} "{ Custom key mappings @@ -344,16 +334,13 @@ nnoremap q; q: " combination inoremap jk -" use sane regex expression (see `:h magic` for more info) -nnoremap / /\v - " 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 -nmap w :update +nnoremap w :update " saves the file if modified and quit nnoremap q :x " quit all opened buffers @@ -373,6 +360,10 @@ nnoremap ]Q :clastzv " see https://goo.gl/uXncnS nnoremap \x :windo lclose cclose +" 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 nnoremap hl (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" @@ -408,19 +399,28 @@ nnoremap ah nnoremap Y y$ " move cursor based on physical lines not the actual lines. -noremap j (v:count == 0 ? 'gj' : 'j') -noremap k (v:count == 0 ? 'gk' : 'k') +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, +" see https://goo.gl/PkuZox +vnoremap $ g_ + +" jump to matching pairs easily in normal mode +nmap % + +" go to start or end of line easier +nnoremap H ^ +nnoremap L $ + " 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 -" resize window in vertical directory nnoremap < nnoremap > -" resize window in horizontal directory nnoremap - nnoremap + @@ -443,44 +443,26 @@ inoremap ((pumvisible())?("\"):("\")) " use to close auto-completion menu inoremap ((pumvisible())?("\"):("\")) -" reload init.vim quickly and give a message -nnoremap sv :update $MYVIMRC:source $MYVIMRC - \ :echom "Nvim config successfully reloaded!" - -" edit init.vim in a vertical split +" edit and reload init.vim quickly nnoremap ev :edit $MYVIMRC +nnoremap sv :silent update $MYVIMRC source $MYVIMRC + \ echomsg "Nvim config successfully reloaded!" -" delete a buffer and switching to another buffer, do not close the -" window, see https://goo.gl/Wd8yZJ -nnoremap \d :bprevious:bdelete # - -" nnoremap :call StripTrailingWhitespaces() -" autocmd FileType * autocmd BufWritePre :call StripTrailingWhitespaces() - -" do not include white space character when using $ in visual mode, -" see https://goo.gl/PkuZox -vnoremap $ g_ - -" jump to matching pairs easily in normal mode -nmap % - -" go to start or end of line easier -nnoremap H ^ -nnoremap L $ +nnoremap :call StripTrailingWhitespaces() " reselect the text that has just been pasted nnoremap v `[V`] -" find and replace (like Sublime Text 3) -nnoremap :%s/\v +" use sane regex expression (see `:h magic` for more info) +nnoremap / /\v -" change current working locally to where the opened file resides +" find and replace (like Sublime Text 3) +nnoremap :%s/ + +" 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 -" reduce indent level in insert mode with shift+tab -inoremap < @@ -488,6 +470,9 @@ tnoremap " when we are doing spell checking) nnoremap :set spell! :AutoSaveToggle inoremap :set spell! :AutoSaveToggle + +" decrease indent level in insert mode with shift+tab +inoremap < pumvisible() ? "\" : "\" +" inoremap pumvisible() ? "\" : "\" """""""""""""""""""""""""UltiSnips settings""""""""""""""""""" " Trigger configuration. Do not use if you use @@ -1022,38 +975,28 @@ let g:SuperTabDefaultCompletionType = '' " see https://is.gd/AoSv4m let g:SuperTabMappingForward = '' let g:SuperTabMappingBackward = '' +"}} +"{{ python-related """"""""""""""""""deoplete-jedi settings""""""""""""""""""""""""""" " whether to show doc string let g:deoplete#sources#jedi#show_docstring = 0 -" do not use typeinfo (for faster completion) -let g:deoplete#sources#jedi#enable_typeinfo = 0 - " for large package, set autocomplete wait time longer let g:deoplete#sources#jedi#server_timeout = 50 -"}} -"{{ python-related +" 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 let g:jedi#completions_enabled = 0 -" open the go-to function in split, not another buffer -" let g:jedi#use_splits_not_buffers = 'right' - " show function call signature -let g:jedi#show_call_signatures = '2' - -"""""""""""""""""""""""""python-syntax highlight settings""""""""""""""""""" -" highlight all -let g:python_highlight_all = 1 - -" don't highlight space error, really annoying!!!!! -let g:python_highlight_space_errors = 0 +let g:jedi#show_call_signatures = '1' """""""""""""""""""""""""" semshi settings """"""""""""""""""""""""""""""" -" do not highlight variable under cursor +" do not highlight variable under cursor, it is distracting let g:semshi#mark_selected_nodes=0 " do not show error sign since neomake is specicialized for that @@ -1065,10 +1008,10 @@ let g:semshi#error_sign=v:false let g:sneak#label = 1 nmap f Sneak_s xmap f Sneak_s -omap f Sneak_s +onoremap f :call sneak#wrap(v:operator, 2, 0, 1, 1) nmap F Sneak_S xmap F Sneak_S -omap 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 " or previous match @@ -1090,9 +1033,9 @@ let g:airline#extensions#anzu#enabled = 0 let g:anzu_search_limit = 500000 """""""""""""""""""""""""""""vim-asterisk settings""""""""""""""""""""" -nmap * (asterisk-z*)(is-nohl-1)(anzu-star-with-echo) +nmap * (asterisk-z*)(is-nohl-1) +nmap # (asterisk-z#)(is-nohl-1) nmap g* (asterisk-gz*)(is-nohl-1) -nmap # (asterisk-z#)(is-nohl-1)(anzu-sharp-with-echo) nmap g# (asterisk-gz#)(is-nohl-1) """""""""""""""""""""""""fzf settings"""""""""""""""""""""""""" @@ -1182,10 +1125,6 @@ if has('win32') || has('macunix') vmap ob (openbrowser-smart-search) endif -"""""""""""""""""""""""""vim-highlighturl settings""""""""""""""""""""""""" -" whether to underline the URL -let g:highlighturl_underline=1 - "{{ navigation and tags """"""""""""""""""""""" nerdtree settings """""""""""""""""""""""""" " toggle nerdtree window and keep cursor in file window, @@ -1235,7 +1174,7 @@ autocmd! " 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 @@ -1267,16 +1206,17 @@ nmap gT TitlecaseLine let g:auto_save = 1 " a list of events to trigger autosave -let g:auto_save_events = ['InsertLeave'] +let g:auto_save_events = ['InsertLeave', 'TextChanged'] " show autosave status on command line let g:auto_save_silent = 0 """"""""""""""""""""""""""""vim-yoink settings""""""""""""""""""""""""" if has('win32') || has('macunix') - " it seems that ctrl-n and ctrl-p does not work on neovim - nmap (YoinkPostPasteSwapBack) - nmap (YoinkPostPasteSwapForward) + " ctrl-n and ctrl-p will not work if you add the TextChanged event to + " vim-auto-save events + " nmap (YoinkPostPasteSwapBack) + " nmap (YoinkPostPasteSwapForward) nmap p (YoinkPaste_p) nmap P (YoinkPaste_P) @@ -1296,20 +1236,6 @@ if has('win32') || has('macunix') let g:yoinkSyncSystemClipboardOnFocus = 1 endif -"""""""""""""""""""""vim-better-whitespace settings"""""""""""""""""""""""""" -" whether to highlight trailing whitespace with the default red color (I find -" it distracting so I turn it off) -let g:better_whitespace_enabled=0 - -" set a mapping for StripWhitespace command -nnoremap :StripWhitespace - -" strip white line at the end of the file -let g:strip_whitelines_at_eof=1 - -" disable whitespace operator -let g:better_whitespace_operator='' - """"""""""""""""""""""""""""""vim-signature settings"""""""""""""""""""""""""" " change mark highlight to be more visible augroup signature_highlight @@ -1335,25 +1261,8 @@ let g:neomake_python_enabled_makers = ['flake8', 'pylint'] " whether to open quickfix or location list automatically let g:neomake_open_list = 0 - -"let g:neomake_python_pylint_maker = { -" \ 'args': [ -" \ '-d', 'C0103, C0111', -" \ '-f', 'text', -" \ '--msg-template="{path}:{line}:{column}:{C}: [{symbol}] {msg} [{msg_id}]"', -" \ '-r', 'n' -" \ ], -" \ 'errorformat': -" \ '%A%f:%l:%c:%t: %m,' . -" \ '%A%f:%l: %m,' . -" \ '%A%f:(%l): %m,' . -" \ '%-Z%p^%.%#,' . -" \ '%-G%.%#', -" \ } "}} - - "{{ git-related """""""""""""""""""""""""vim-signify settings"""""""""""""""""""""""""""""" " the VCS to use @@ -1361,8 +1270,8 @@ let g:signify_vcs_list = [ 'git' ] " change the sign for certain operations let g:signify_sign_change = '~' - "}} + "{{ Markdown writing """""""""""""""""""""""""goyo.vim settings"""""""""""""""""""""""""""""" " make goyo and limelight work together automatically @@ -1374,7 +1283,7 @@ augroup END """""""""""""""""""""""""vim-pandoc-syntax settings""""""""""""""""""""""""" " do not conceal urls (seems does not work) -let g:pandoc#syntax#conceal#urls = 0 +let g:pandoc#syntax#conceal#urls = 1 " use pandoc-syntax for markdown files, it will disable conceal feature for " links, use it at your own risk @@ -1667,7 +1576,6 @@ if HasColorscheme('gruvbox') let g:gruvbox_italic=1 let g:gruvbox_contrast_dark='hard' let g:gruvbox_italicize_strings=1 - colorscheme gruvbox else " fall back to a pre-installed theme @@ -1699,7 +1607,7 @@ endif " let g:material_theme_style = 'dark' " colorscheme material -"""""""""""""""""""""""""""material.vim settings"""""""""""""""""""""""""" +"""""""""""""""""""""""""""badwolf settings"""""""""""""""""""""""""" " let g:badwolf_darkgutter = 0 " " Make the tab line lighter than the background. " let g:badwolf_tabline = 2 @@ -1719,4 +1627,4 @@ endif " - 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 +"}