diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2022-09-24 12:57:45 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2022-09-24 12:57:45 +0800 |
| commit | a2521c35ee83b18f3f2a85c61978e1fd83ddc6f9 (patch) | |
| tree | 60040ae2157a741285a11b2e8394c60c0f532aa5 /vimrc | |
| parent | 1a72c05ac8c88f25c7cbd0f48f5d77708275b0d8 (diff) | |
Update vimrc
Diffstat (limited to 'vimrc')
| -rw-r--r-- | vimrc | 318 |
1 files changed, 29 insertions, 289 deletions
| @@ -1,300 +1,40 @@ | |||
| 1 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | 1 | " Avoid load this script twice |
| 2 | " => Custom Config | 2 | if get(s:, 'loaded', 0) != 0 |
| 3 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | 3 | finish |
| 4 | set cursorline | 4 | else |
| 5 | set number | 5 | let s:loaded = 1 |
| 6 | set relativenumber | 6 | endif |
| 7 | set showcmd | ||
| 8 | set nowrap | ||
| 9 | set nostartofline | ||
| 10 | set sidescroll=1 | ||
| 11 | set sidescrolloff=999 | ||
| 12 | set shell=/bin/bash | ||
| 13 | set shiftwidth=2 | ||
| 14 | autocmd FileType vimwiki set shiftwidth=4 | ||
| 15 | " set clipboard=unnamedplus | ||
| 16 | 7 | ||
| 17 | " general | 8 | " Get current dir |
| 18 | function! Bye() | 9 | " let s:home = fnamemodify(resolve(expand('<sfile>:p')), ':h') |
| 19 | if len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 | 10 | let s:home = '~/.vim/vim-init' |
| 20 | :quit | 11 | execute 'cd '.s:home |
| 21 | else | ||
| 22 | :bdelete | ||
| 23 | endif | ||
| 24 | endfunction | ||
| 25 | nnoremap <silent> <C-C> :call Bye()<CR> | ||
| 26 | nnoremap <silent> <C-S-C> :q!<CR> | ||
| 27 | nnoremap <leader>, :.terminal ++noclose<CR> | ||
| 28 | vnoremap <leader>, :terminal<CR> | ||
| 29 | nnoremap Y viW:!tee >(xsel -ib)<CR> | ||
| 30 | vnoremap Y :!tee >(xsel -ib)<CR> | ||
| 31 | nnoremap <leader>< :%terminal ++noclose<CR> | ||
| 32 | nnoremap <leader>W :set wrap!<CR> | ||
| 33 | nnoremap <leader>T :vertical terminal<CR> | ||
| 34 | nnoremap <leader>R :read ! | ||
| 35 | nnoremap <leader>P :r !xsel -ob<CR> | ||
| 36 | nnoremap <leader>nn :NERDTree<CR> | ||
| 37 | set autoread | ||
| 38 | set nofoldenable " disable folding | ||
| 39 | 12 | ||
| 40 | " move | 13 | " Load script in current dir |
| 41 | " nnoremap <Tab> } | 14 | command! -nargs=1 LoadScript exec 'so '.s:home.'/'.'<args>' |
| 42 | " nnoremap <S-Tab> { | ||
| 43 | inoremap <C-L> <Right> | ||
| 44 | cnoremap <C-L> <Right> | ||
| 45 | cnoremap <C-H> <Left> | ||
| 46 | nmap H 0 | ||
| 47 | nnoremap L $ | ||
| 48 | nnoremap <C-L> 60l | ||
| 49 | nnoremap <C-H> 60h | ||
| 50 | nnoremap / ms/ | ||
| 51 | 15 | ||
| 52 | " disable syntax | 16 | " Add current dir into runtimepath |
| 53 | nnoremap <silent> <leader>s | 17 | execute 'set runtimepath+='.s:home |
| 54 | \ : if exists("syntax_on") <BAR> | ||
| 55 | \ syntax off <BAR> | ||
| 56 | \ else <BAR> | ||
| 57 | \ syntax enable <BAR> | ||
| 58 | \ endif<CR> | ||
| 59 | " show current syntax | ||
| 60 | nnoremap <leader>S :echo join(reverse(map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")')),' ')<CR> | ||
| 61 | 18 | ||
| 62 | " Operator pending | ||
| 63 | onoremap p i( | ||
| 64 | onoremap ap a( | ||
| 65 | " next parenthesis | ||
| 66 | onoremap fp :<c-u>normal! f(vi(<cr> | ||
| 67 | onoremap b i{ | ||
| 68 | onoremap fb :<c-u>normal! f{vi{<cr> | ||
| 69 | onoremap ab a{ | ||
| 70 | " block | ||
| 71 | onoremap B /return<CR> | ||
| 72 | 19 | ||
| 73 | " Search | 20 | "---------------------------------------------------------------------- |
| 74 | vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>'") | 21 | " Locad Modules |
| 22 | "---------------------------------------------------------------------- | ||
| 75 | 23 | ||
| 76 | " S&R | 24 | " Basic configuration |
| 77 | nnoremap <leader>; :%s:::g<Left><Left><Left> | 25 | LoadScript init/init-basic.vim |
| 78 | vnoremap <leader>; :s:::g<Left><Left><Left> | ||
| 79 | cnoremap \\ \(\)<Left><Left> | ||
| 80 | 26 | ||
| 81 | " Fix paste bug triggered by inoremaps | 27 | " Key mappings |
| 82 | set t_BE= | 28 | LoadScript init/init-keymaps.vim |
| 83 | 29 | ||
| 84 | " surround with charactor | 30 | " UI |
| 85 | vnoremap ' <ESC>`<i'<ESC>`>la'<ESC> | 31 | " LoadScript init/init-style.vim |
| 86 | vnoremap q <ESC>`<i"<ESC>`>la"<ESC> | ||
| 87 | vnoremap ( <ESC>`<i(<ESC>`>la)<ESC> | ||
| 88 | vnoremap { <ESC>`<i{<ESC>`>la}<ESC> | ||
| 89 | vnoremap [ <ESC>`<i[<ESC>`>la]<ESC>gvlol | ||
| 90 | inoremap [ []<C-O>h | ||
| 91 | vnoremap ` <ESC>`<i`<ESC>`>la`<ESC> | ||
| 92 | vnoremap , <ESC>`<i<<ESC>`>la><ESC> | ||
| 93 | vnoremap <space> <ESC>`<i<space><ESC>`>la<space><ESC> | ||
| 94 | vnoremap 8 <ESC>`<i*<ESC>`>la*<ESC> | ||
| 95 | vnoremap z <ESC>`<i「<ESC>`>la」<ESC> | ||
| 96 | vnoremap ~ <ESC>`<i~<ESC>`>la~<ESC> | ||
| 97 | 32 | ||
| 98 | " abbrev | 33 | " 加载扩展配置 |
| 99 | iabbrev @@ typebrook@gmail.com | 34 | " LoadScript init/init-config.vim |
| 100 | 35 | ||
| 36 | " 设定 tabsize | ||
| 37 | LoadScript init/init-tabsize.vim | ||
| 101 | 38 | ||
| 102 | " vim_markdown | 39 | " Plugins |
| 103 | let g:vim_markdown_folding_disabled = 1 | 40 | LoadScript init/init-plugins.vim |
| 104 | let g:vim_markdown_conceal = 0 | ||
| 105 | vnoremap <C-K> <ESC>`<i[<ESC>`>la]()<ESC>i | ||
| 106 | |||
| 107 | " XML fold | ||
| 108 | let g:xml_syntax_folding=1 | ||
| 109 | autocmd FileType xml setlocal foldmethod=syntax | ||
| 110 | |||
| 111 | " JSON fold | ||
| 112 | let g:json_syntax_folding=1 | ||
| 113 | autocmd FileType json setlocal foldmethod=syntax | ||
| 114 | |||
| 115 | " Apply new SniptMat Parser | ||
| 116 | let g:snipMate = { 'snippet_version' : 1 } | ||
| 117 | |||
| 118 | " Set width of mutt as 72 | ||
| 119 | au BufRead /tmp/mutt-* set tw=72 | ||
| 120 | |||
| 121 | " Redirection with buffer | ||
| 122 | " Usage: | ||
| 123 | " :Redir hi ............. show the full output of command ':hi' in a scratch window | ||
| 124 | " :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window | ||
| 125 | function! Redir(cmd) | ||
| 126 | for win in range(1, winnr('$')) | ||
| 127 | if getwinvar(win, 'scratch') | ||
| 128 | execute win . 'windo close' | ||
| 129 | endif | ||
| 130 | endfor | ||
| 131 | if a:cmd =~ '^!' | ||
| 132 | let output = system(matchstr(a:cmd, '^!\zs.*')) | ||
| 133 | else | ||
| 134 | redir => output | ||
| 135 | execute a:cmd | ||
| 136 | redir END | ||
| 137 | endif | ||
| 138 | vnew | ||
| 139 | let w:scratch = 1 | ||
| 140 | setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile | ||
| 141 | call setline(1, split(output, "\n")) | ||
| 142 | endfunction | ||
| 143 | |||
| 144 | command! -nargs=1 -complete=command Redir silent call Redir(<q-args>) | ||
| 145 | |||
| 146 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 147 | " => Settings for Vimwiki | ||
| 148 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 149 | |||
| 150 | nnoremap <leader>tt :VimwikiTable<CR> | ||
| 151 | nnoremap <leader>wg :VimwikiGoto | ||
| 152 | nnoremap <leader>wT :VimwikiSearchTags | ||
| 153 | nnoremap <leader>i I- <esc>l | ||
| 154 | nnoremap <leader>I :s/^[ ]*- \(\[.\] \)*//<CR> | ||
| 155 | nmap <leader>D dd:VimwikiMakeDiaryNote<CR>Gp:w!<CR>:Bclose<CR> | ||
| 156 | vnoremap <leader>D d:VimwikiMakeDiaryNote<CR>Gp:w!<CR> | ||
| 157 | let g:vimwiki_list = [{ | ||
| 158 | \ 'path': '~/log/', | ||
| 159 | \ 'syntax': 'markdown', | ||
| 160 | \ 'ext': '.md', | ||
| 161 | \ }] | ||
| 162 | |||
| 163 | " Git push quietly whenever leaving vim with VimWiki files | ||
| 164 | augroup vimwikiPush | ||
| 165 | autocmd! | ||
| 166 | autocmd VimLeave ~/log/* :!(cd ~/log && git add * && git commit -am Update && git push origin >/dev/null 2>&1 &) | ||
| 167 | augroup END | ||
| 168 | |||
| 169 | " Configuration fro vim-instant-markdown | ||
| 170 | let g:instant_markdown_autostart = 0 | ||
| 171 | nnoremap <leader>md :InstantMarkdownPreview<CR> | ||
| 172 | |||
| 173 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 174 | " => Settings for Blog | ||
| 175 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 176 | |||
| 177 | " Generate static pages | ||
| 178 | augroup blogRebuild | ||
| 179 | autocmd! | ||
| 180 | autocmd BufWritePost ~/blog/*.md :!cd ~/blog && hugo >/dev/null | ||
| 181 | augroup END | ||
| 182 | |||
| 183 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 184 | " => Settings for Slides | ||
| 185 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 186 | |||
| 187 | " Generate static pages | ||
| 188 | augroup slideRebuild | ||
| 189 | autocmd BufWritePost ~/public/**/slide/*.md :!(cd %:p:h && ~/helper/tools/markdown/reveal %:t >/dev/null &) | ||
| 190 | augroup END | ||
| 191 | |||
| 192 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 193 | " => Redirect the output of a Vim or external command into a scratch buffer | ||
| 194 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 195 | " Copy from : https://gist.github.com/romainl/eae0a260ab9c135390c30cd370c20cd7 | ||
| 196 | " | ||
| 197 | " Usage: | ||
| 198 | " :Redir hi ............. show the full output of command ':hi' in a scratch window | ||
| 199 | " :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window | ||
| 200 | |||
| 201 | function! Redir(cmd) | ||
| 202 | for win in range(1, winnr('$')) | ||
| 203 | if getwinvar(win, 'scratch') | ||
| 204 | execute win . 'windo close' | ||
| 205 | endif | ||
| 206 | endfor | ||
| 207 | if a:cmd =~ '^!' | ||
| 208 | let output = system(matchstr(a:cmd, '^!\zs.*')) | ||
| 209 | else | ||
| 210 | redir => output | ||
| 211 | execute a:cmd | ||
| 212 | redir END | ||
| 213 | endif | ||
| 214 | vnew | ||
| 215 | let w:scratch = 1 | ||
| 216 | setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile | ||
| 217 | call setline(1, split(output, "\n")) | ||
| 218 | endfunction | ||
| 219 | |||
| 220 | command! -nargs=1 -complete=command Redir silent call Redir(<q-args>) | ||
| 221 | nnoremap <leader>r :Redir | ||
| 222 | |||
| 223 | |||
| 224 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 225 | " => Make Alt key works on Gnome terminal | ||
| 226 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 227 | " Solution is here: https://stackoverflow.com/questions/6778961 | ||
| 228 | |||
| 229 | let c='a' | ||
| 230 | while c <= 'z' | ||
| 231 | exec "set <A-".c.">=\e".c | ||
| 232 | exec "imap \e".c." <A-".c.">" | ||
| 233 | let c = nr2char(1+char2nr(c)) | ||
| 234 | endw | ||
| 235 | set timeout ttimeoutlen=50 | ||
| 236 | |||
| 237 | |||
| 238 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 239 | " => vim-racer | ||
| 240 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 241 | set hidden | ||
| 242 | let g:racer_cmd = "~/.cargo/bin/racer" | ||
| 243 | let g:racer_experimental_completer = 1 | ||
| 244 | |||
| 245 | autocmd FileType rust nmap gd <Plug>(rust-def) | ||
| 246 | autocmd FileType rust nmap gs <Plug>(rust-def-split) | ||
| 247 | autocmd FileType rust nmap gx <Plug>(rust-def-vertical) | ||
| 248 | autocmd FileType rust nmap <leader>gd <Plug>(rust-doc) | ||
| 249 | |||
| 250 | |||
| 251 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 252 | " => vim-plug | ||
| 253 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 254 | " run :PlugInstall to install plugins | ||
| 255 | |||
| 256 | call plug#begin('~/.vim/plugged') | ||
| 257 | |||
| 258 | " Add indent line | ||
| 259 | |||
| 260 | Plug 'Yggdroot/indentLine' | ||
| 261 | Plug 'mileszs/ack.vim' | ||
| 262 | Plug 'tpope/vim-surround' | ||
| 263 | "Plug 'lifepillar/pgsql.vim' | ||
| 264 | Plug 'vimwiki/vimwiki' | ||
| 265 | "Plug 'iberianpig/tig-explorer.vim' | ||
| 266 | Plug 'rust-lang/rust.vim' | ||
| 267 | "Plug 'racer-rust/vim-racer' | ||
| 268 | "Plug 'suan/vim-instant-markdown', {'for': 'markdown'} | ||
| 269 | Plug 'junegunn/fzf.vim' | ||
| 270 | Plug 'michal-h21/vim-zettel' | ||
| 271 | Plug 'rlue/vim-barbaric' | ||
| 272 | Plug 'nathangrigg/vim-beancount' | ||
| 273 | Plug 'preservim/nerdtree' | ||
| 274 | |||
| 275 | " Initialize plugin system | ||
| 276 | call plug#end() | ||
| 277 | |||
| 278 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 279 | " => lf | ||
| 280 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
| 281 | " Use lf as file selector | ||
| 282 | function! LF() | ||
| 283 | let temp = tempname() | ||
| 284 | exec 'silent !lf -selection-path=' . shellescape(temp) | ||
| 285 | if !filereadable(temp) | ||
| 286 | redraw! | ||
| 287 | return | ||
| 288 | endif | ||
| 289 | let names = readfile(temp) | ||
| 290 | if empty(names) | ||
| 291 | redraw! | ||
| 292 | return | ||
| 293 | endif | ||
| 294 | exec 'edit ' . fnameescape(names[0]) | ||
| 295 | for name in names[1:] | ||
| 296 | exec 'argadd ' . fnameescape(name) | ||
| 297 | endfor | ||
| 298 | redraw! | ||
| 299 | endfunction | ||
| 300 | command! -bar LF call LF() | ||