From a2521c35ee83b18f3f2a85c61978e1fd83ddc6f9 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sat, 24 Sep 2022 12:57:45 +0800 Subject: Update vimrc --- Makefile | 7 +- vimrc | 318 ++++++-------------------------------------------------------- vimrc.bak | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 330 insertions(+), 295 deletions(-) create mode 100644 vimrc.bak diff --git a/Makefile b/Makefile index 69da3a6..8f92b82 100644 --- a/Makefile +++ b/Makefile @@ -15,14 +15,9 @@ tig: ln -sf `pwd`/tigrc ~/.tigrc vim: - # amix-vimrc - if [ ! -d "$(HOME)/.vim_runtime" ]; then - git clone --depth=1 --origin my https://github.com/amix/vimrc ~/.vim_runtime && - cd ~/.vim_runtime && sh ~/.vim_runtime/install_awesome_vimrc.sh - fi + ln -sf `pwd`/vimrc ~/.vimrc # vim-plug curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim - ln -sf `pwd`/vimrc ~/.vim_runtime/my_configs.vim gpg: ln -sf `pwd`/misc/gpg-agent ~/.gnupg/gpg-agent.conf diff --git a/vimrc b/vimrc index 29f34d3..20eec84 100644 --- a/vimrc +++ b/vimrc @@ -1,300 +1,40 @@ -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Custom Config -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -set cursorline -set number -set relativenumber -set showcmd -set nowrap -set nostartofline -set sidescroll=1 -set sidescrolloff=999 -set shell=/bin/bash -set shiftwidth=2 -autocmd FileType vimwiki set shiftwidth=4 -" set clipboard=unnamedplus +" Avoid load this script twice +if get(s:, 'loaded', 0) != 0 + finish +else + let s:loaded = 1 +endif -" general -function! Bye() - if len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 - :quit - else - :bdelete - endif -endfunction -nnoremap :call Bye() -nnoremap :q! -nnoremap , :.terminal ++noclose -vnoremap , :terminal -nnoremap Y viW:!tee >(xsel -ib) -vnoremap Y :!tee >(xsel -ib) -nnoremap < :%terminal ++noclose -nnoremap W :set wrap! -nnoremap T :vertical terminal -nnoremap R :read ! -nnoremap P :r !xsel -ob -nnoremap nn :NERDTree -set autoread -set nofoldenable " disable folding +" Get current dir +" let s:home = fnamemodify(resolve(expand(':p')), ':h') +let s:home = '~/.vim/vim-init' +execute 'cd '.s:home -" move -" nnoremap } -" nnoremap { -inoremap -cnoremap -cnoremap -nmap H 0 -nnoremap L $ -nnoremap 60l -nnoremap 60h -nnoremap / ms/ +" Load script in current dir +command! -nargs=1 LoadScript exec 'so '.s:home.'/'.'' -" disable syntax -nnoremap s - \ : if exists("syntax_on") - \ syntax off - \ else - \ syntax enable - \ endif -" show current syntax -nnoremap S :echo join(reverse(map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")')),' ') +" Add current dir into runtimepath +execute 'set runtimepath+='.s:home -" Operator pending -onoremap p i( -onoremap ap a( -" next parenthesis -onoremap fp :normal! f(vi( -onoremap b i{ -onoremap fb :normal! f{vi{ -onoremap ab a{ -" block -onoremap B /return -" Search -vnoremap // y/\V=escape(@",'/\')'") +"---------------------------------------------------------------------- +" Locad Modules +"---------------------------------------------------------------------- -" S&R -nnoremap ; :%s:::g -vnoremap ; :s:::g -cnoremap \\ \(\) +" Basic configuration +LoadScript init/init-basic.vim -" Fix paste bug triggered by inoremaps -set t_BE= +" Key mappings +LoadScript init/init-keymaps.vim -" surround with charactor -vnoremap ' ``>la' -vnoremap q ``>la" -vnoremap ( ``>la) -vnoremap { ``>la} -vnoremap [ ``>la]gvlol -inoremap [ []h -vnoremap ` ``>la` -vnoremap , ``>la> -vnoremap ``>la -vnoremap 8 ``>la* -vnoremap z ``>la」 -vnoremap ~ ``>la~ +" UI +" LoadScript init/init-style.vim -" abbrev -iabbrev @@ typebrook@gmail.com +" 加载扩展配置 +" LoadScript init/init-config.vim +" 设定 tabsize +LoadScript init/init-tabsize.vim -" vim_markdown -let g:vim_markdown_folding_disabled = 1 -let g:vim_markdown_conceal = 0 -vnoremap ``>la]()i - -" XML fold -let g:xml_syntax_folding=1 -autocmd FileType xml setlocal foldmethod=syntax - -" JSON fold -let g:json_syntax_folding=1 -autocmd FileType json setlocal foldmethod=syntax - -" Apply new SniptMat Parser -let g:snipMate = { 'snippet_version' : 1 } - -" Set width of mutt as 72 -au BufRead /tmp/mutt-* set tw=72 - -" Redirection with buffer -" Usage: -" :Redir hi ............. show the full output of command ':hi' in a scratch window -" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window -function! Redir(cmd) - for win in range(1, winnr('$')) - if getwinvar(win, 'scratch') - execute win . 'windo close' - endif - endfor - if a:cmd =~ '^!' - let output = system(matchstr(a:cmd, '^!\zs.*')) - else - redir => output - execute a:cmd - redir END - endif - vnew - let w:scratch = 1 - setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile - call setline(1, split(output, "\n")) -endfunction - -command! -nargs=1 -complete=command Redir silent call Redir() - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Settings for Vimwiki -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -nnoremap tt :VimwikiTable -nnoremap wg :VimwikiGoto -nnoremap wT :VimwikiSearchTags -nnoremap i I- l -nnoremap I :s/^[ ]*- \(\[.\] \)*// -nmap D dd:VimwikiMakeDiaryNoteGp:w!:Bclose -vnoremap D d:VimwikiMakeDiaryNoteGp:w! -let g:vimwiki_list = [{ - \ 'path': '~/log/', - \ 'syntax': 'markdown', - \ 'ext': '.md', - \ }] - -" Git push quietly whenever leaving vim with VimWiki files -augroup vimwikiPush - autocmd! - autocmd VimLeave ~/log/* :!(cd ~/log && git add * && git commit -am Update && git push origin >/dev/null 2>&1 &) -augroup END - -" Configuration fro vim-instant-markdown -let g:instant_markdown_autostart = 0 -nnoremap md :InstantMarkdownPreview - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Settings for Blog -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -" Generate static pages -augroup blogRebuild - autocmd! - autocmd BufWritePost ~/blog/*.md :!cd ~/blog && hugo >/dev/null -augroup END - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Settings for Slides -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -" Generate static pages -augroup slideRebuild - autocmd BufWritePost ~/public/**/slide/*.md :!(cd %:p:h && ~/helper/tools/markdown/reveal %:t >/dev/null &) -augroup END - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Redirect the output of a Vim or external command into a scratch buffer -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Copy from : https://gist.github.com/romainl/eae0a260ab9c135390c30cd370c20cd7 -" -" Usage: -" :Redir hi ............. show the full output of command ':hi' in a scratch window -" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window - -function! Redir(cmd) - for win in range(1, winnr('$')) - if getwinvar(win, 'scratch') - execute win . 'windo close' - endif - endfor - if a:cmd =~ '^!' - let output = system(matchstr(a:cmd, '^!\zs.*')) - else - redir => output - execute a:cmd - redir END - endif - vnew - let w:scratch = 1 - setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile - call setline(1, split(output, "\n")) -endfunction - -command! -nargs=1 -complete=command Redir silent call Redir() -nnoremap r :Redir - - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Make Alt key works on Gnome terminal -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Solution is here: https://stackoverflow.com/questions/6778961 - -let c='a' -while c <= 'z' - exec "set =\e".c - exec "imap \e".c." " - let c = nr2char(1+char2nr(c)) -endw -set timeout ttimeoutlen=50 - - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => vim-racer -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -set hidden -let g:racer_cmd = "~/.cargo/bin/racer" -let g:racer_experimental_completer = 1 - -autocmd FileType rust nmap gd (rust-def) -autocmd FileType rust nmap gs (rust-def-split) -autocmd FileType rust nmap gx (rust-def-vertical) -autocmd FileType rust nmap gd (rust-doc) - - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => vim-plug -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" run :PlugInstall to install plugins - -call plug#begin('~/.vim/plugged') - -" Add indent line - -Plug 'Yggdroot/indentLine' -Plug 'mileszs/ack.vim' -Plug 'tpope/vim-surround' -"Plug 'lifepillar/pgsql.vim' -Plug 'vimwiki/vimwiki' -"Plug 'iberianpig/tig-explorer.vim' -Plug 'rust-lang/rust.vim' -"Plug 'racer-rust/vim-racer' -"Plug 'suan/vim-instant-markdown', {'for': 'markdown'} -Plug 'junegunn/fzf.vim' -Plug 'michal-h21/vim-zettel' -Plug 'rlue/vim-barbaric' -Plug 'nathangrigg/vim-beancount' -Plug 'preservim/nerdtree' - -" Initialize plugin system -call plug#end() - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => lf -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Use lf as file selector -function! LF() - let temp = tempname() - exec 'silent !lf -selection-path=' . shellescape(temp) - if !filereadable(temp) - redraw! - return - endif - let names = readfile(temp) - if empty(names) - redraw! - return - endif - exec 'edit ' . fnameescape(names[0]) - for name in names[1:] - exec 'argadd ' . fnameescape(name) - endfor - redraw! -endfunction -command! -bar LF call LF() +" Plugins +LoadScript init/init-plugins.vim diff --git a/vimrc.bak b/vimrc.bak new file mode 100644 index 0000000..29f34d3 --- /dev/null +++ b/vimrc.bak @@ -0,0 +1,300 @@ +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Custom Config +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +set cursorline +set number +set relativenumber +set showcmd +set nowrap +set nostartofline +set sidescroll=1 +set sidescrolloff=999 +set shell=/bin/bash +set shiftwidth=2 +autocmd FileType vimwiki set shiftwidth=4 +" set clipboard=unnamedplus + +" general +function! Bye() + if len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 + :quit + else + :bdelete + endif +endfunction +nnoremap :call Bye() +nnoremap :q! +nnoremap , :.terminal ++noclose +vnoremap , :terminal +nnoremap Y viW:!tee >(xsel -ib) +vnoremap Y :!tee >(xsel -ib) +nnoremap < :%terminal ++noclose +nnoremap W :set wrap! +nnoremap T :vertical terminal +nnoremap R :read ! +nnoremap P :r !xsel -ob +nnoremap nn :NERDTree +set autoread +set nofoldenable " disable folding + +" move +" nnoremap } +" nnoremap { +inoremap +cnoremap +cnoremap +nmap H 0 +nnoremap L $ +nnoremap 60l +nnoremap 60h +nnoremap / ms/ + +" disable syntax +nnoremap s + \ : if exists("syntax_on") + \ syntax off + \ else + \ syntax enable + \ endif +" show current syntax +nnoremap S :echo join(reverse(map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")')),' ') + +" Operator pending +onoremap p i( +onoremap ap a( +" next parenthesis +onoremap fp :normal! f(vi( +onoremap b i{ +onoremap fb :normal! f{vi{ +onoremap ab a{ +" block +onoremap B /return + +" Search +vnoremap // y/\V=escape(@",'/\')'") + +" S&R +nnoremap ; :%s:::g +vnoremap ; :s:::g +cnoremap \\ \(\) + +" Fix paste bug triggered by inoremaps +set t_BE= + +" surround with charactor +vnoremap ' ``>la' +vnoremap q ``>la" +vnoremap ( ``>la) +vnoremap { ``>la} +vnoremap [ ``>la]gvlol +inoremap [ []h +vnoremap ` ``>la` +vnoremap , ``>la> +vnoremap ``>la +vnoremap 8 ``>la* +vnoremap z ``>la」 +vnoremap ~ ``>la~ + +" abbrev +iabbrev @@ typebrook@gmail.com + + +" vim_markdown +let g:vim_markdown_folding_disabled = 1 +let g:vim_markdown_conceal = 0 +vnoremap ``>la]()i + +" XML fold +let g:xml_syntax_folding=1 +autocmd FileType xml setlocal foldmethod=syntax + +" JSON fold +let g:json_syntax_folding=1 +autocmd FileType json setlocal foldmethod=syntax + +" Apply new SniptMat Parser +let g:snipMate = { 'snippet_version' : 1 } + +" Set width of mutt as 72 +au BufRead /tmp/mutt-* set tw=72 + +" Redirection with buffer +" Usage: +" :Redir hi ............. show the full output of command ':hi' in a scratch window +" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window +function! Redir(cmd) + for win in range(1, winnr('$')) + if getwinvar(win, 'scratch') + execute win . 'windo close' + endif + endfor + if a:cmd =~ '^!' + let output = system(matchstr(a:cmd, '^!\zs.*')) + else + redir => output + execute a:cmd + redir END + endif + vnew + let w:scratch = 1 + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile + call setline(1, split(output, "\n")) +endfunction + +command! -nargs=1 -complete=command Redir silent call Redir() + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Settings for Vimwiki +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +nnoremap tt :VimwikiTable +nnoremap wg :VimwikiGoto +nnoremap wT :VimwikiSearchTags +nnoremap i I- l +nnoremap I :s/^[ ]*- \(\[.\] \)*// +nmap D dd:VimwikiMakeDiaryNoteGp:w!:Bclose +vnoremap D d:VimwikiMakeDiaryNoteGp:w! +let g:vimwiki_list = [{ + \ 'path': '~/log/', + \ 'syntax': 'markdown', + \ 'ext': '.md', + \ }] + +" Git push quietly whenever leaving vim with VimWiki files +augroup vimwikiPush + autocmd! + autocmd VimLeave ~/log/* :!(cd ~/log && git add * && git commit -am Update && git push origin >/dev/null 2>&1 &) +augroup END + +" Configuration fro vim-instant-markdown +let g:instant_markdown_autostart = 0 +nnoremap md :InstantMarkdownPreview + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Settings for Blog +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" Generate static pages +augroup blogRebuild + autocmd! + autocmd BufWritePost ~/blog/*.md :!cd ~/blog && hugo >/dev/null +augroup END + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Settings for Slides +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" Generate static pages +augroup slideRebuild + autocmd BufWritePost ~/public/**/slide/*.md :!(cd %:p:h && ~/helper/tools/markdown/reveal %:t >/dev/null &) +augroup END + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Redirect the output of a Vim or external command into a scratch buffer +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Copy from : https://gist.github.com/romainl/eae0a260ab9c135390c30cd370c20cd7 +" +" Usage: +" :Redir hi ............. show the full output of command ':hi' in a scratch window +" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window + +function! Redir(cmd) + for win in range(1, winnr('$')) + if getwinvar(win, 'scratch') + execute win . 'windo close' + endif + endfor + if a:cmd =~ '^!' + let output = system(matchstr(a:cmd, '^!\zs.*')) + else + redir => output + execute a:cmd + redir END + endif + vnew + let w:scratch = 1 + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile + call setline(1, split(output, "\n")) +endfunction + +command! -nargs=1 -complete=command Redir silent call Redir() +nnoremap r :Redir + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Make Alt key works on Gnome terminal +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Solution is here: https://stackoverflow.com/questions/6778961 + +let c='a' +while c <= 'z' + exec "set =\e".c + exec "imap \e".c." " + let c = nr2char(1+char2nr(c)) +endw +set timeout ttimeoutlen=50 + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => vim-racer +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +set hidden +let g:racer_cmd = "~/.cargo/bin/racer" +let g:racer_experimental_completer = 1 + +autocmd FileType rust nmap gd (rust-def) +autocmd FileType rust nmap gs (rust-def-split) +autocmd FileType rust nmap gx (rust-def-vertical) +autocmd FileType rust nmap gd (rust-doc) + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => vim-plug +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" run :PlugInstall to install plugins + +call plug#begin('~/.vim/plugged') + +" Add indent line + +Plug 'Yggdroot/indentLine' +Plug 'mileszs/ack.vim' +Plug 'tpope/vim-surround' +"Plug 'lifepillar/pgsql.vim' +Plug 'vimwiki/vimwiki' +"Plug 'iberianpig/tig-explorer.vim' +Plug 'rust-lang/rust.vim' +"Plug 'racer-rust/vim-racer' +"Plug 'suan/vim-instant-markdown', {'for': 'markdown'} +Plug 'junegunn/fzf.vim' +Plug 'michal-h21/vim-zettel' +Plug 'rlue/vim-barbaric' +Plug 'nathangrigg/vim-beancount' +Plug 'preservim/nerdtree' + +" Initialize plugin system +call plug#end() + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => lf +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Use lf as file selector +function! LF() + let temp = tempname() + exec 'silent !lf -selection-path=' . shellescape(temp) + if !filereadable(temp) + redraw! + return + endif + let names = readfile(temp) + if empty(names) + redraw! + return + endif + exec 'edit ' . fnameescape(names[0]) + for name in names[1:] + exec 'argadd ' . fnameescape(name) + endfor + redraw! +endfunction +command! -bar LF call LF() -- cgit v1.2.3-70-g09d2