aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init
diff options
context:
space:
mode:
Diffstat (limited to 'vim/init')
-rw-r--r--vim/init/basic.vim133
-rw-r--r--vim/init/config.vim30
-rw-r--r--vim/init/keymaps.vim115
3 files changed, 171 insertions, 107 deletions
diff --git a/vim/init/basic.vim b/vim/init/basic.vim
index 2394045..e18d51f 100644
--- a/vim/init/basic.vim
+++ b/vim/init/basic.vim
@@ -4,7 +4,7 @@
4" Used for general usecases. No keymap and personal preference 4" Used for general usecases. No keymap and personal preference
5"====================================================================== 5"======================================================================
6 6
7" Vimscript file settings ---------------------- {{{ 7" For Vimscript {{{
8 8
9" Usage: type --- for foldmark 9" Usage: type --- for foldmark
10augroup filetype_vim 10augroup filetype_vim
@@ -14,13 +14,63 @@ augroup filetype_vim
14augroup END 14augroup END
15 15
16" }}} 16" }}}
17" GERERNAL ----------------{{{ 17" For Buffer and Tab {{{
18augroup tabinfo
19 au!
20 let g:tab_group = {}
21 " BufEnter {{{
22 function! AddBufToTabGroup(tab_group)
23 let l:tabId = tabpagenr()
24 let l:bufnr = bufnr()
25
26 if has_key(a:tab_group, l:tabId)
27 for v in a:tab_group[l:tabId]
28 if v == l:bufnr
29 return
30 endif
31 endfor
32 call add(a:tab_group[l:tabId], l:bufnr)
33 else
34 let a:tab_group[l:tabId] = [l:bufnr]
35 endif
36
37 endfunc
38 autocmd BufWinEnter * if &buflisted | call AddBufToTabGroup(g:tab_group) | endif
39 " }}}
40 " BufDelete {{{
41 function! RemoveBufFromTabGroup(tab_group)
42 let l:tabId = tabpagenr()
43
44 if has_key(a:tab_group, l:tabId)
45 let l:new_tab_group = {}
46
47 for [k, tab_list] in items(a:tab_group)
48 let l:list = []
49 for buf in tab_list
50 if buflisted(buf) > 0 && buf != expand('<abuf>')
51 call add(l:list, buf)
52 end
53 endfor
54 if !empty(l:list)
55 let l:new_tab_group[k] = l:list
56 endif
57 endfor
58 let g:tab_group = l:new_tab_group
59
60 endif
61
62 endfunc
63 autocmd BufDelete * call RemoveBufFromTabGroup(g:tab_group)
64 "}}}
65augroup END
66"}}}
67" GERERNAL {{{
18 68
19let mapleader = "," " Always use comma as leader key 69let mapleader = "," " Always use comma as leader key
20set nocompatible " Disable vi compatible, today is 20XX 70set nocompatible " Disable vi compatible, today is 20XX
21set path=.,** " Allow :find with completion 71set path=.,** " Allow :find with completion
22set mouse= " Disable mouse selection 72set mouse= " Disable mouse selection
23set winaltkeys=no " Allow alt key for mapping 73set winaltkeys=no " Allow alt key for mapping
24 74
25" Turn persistent undo on 75" Turn persistent undo on
26" means that you can undo even when you close a buffer/VIM 76" means that you can undo even when you close a buffer/VIM
@@ -43,22 +93,20 @@ set spellfile="/tmp/spell"
43sign define piet text=>> texthl=Search 93sign define piet text=>> texthl=Search
44 94
45" }}} 95" }}}
46" VISUAL ----------------{{{ 96" VISUAL {{{
47 97
48" colorscheme desert 98" colorscheme desert
49 99
50" Editing Area 100" Editing Area
51set wrap " enable wrap by default 101set wrap " enable wrap by default
52set scrolloff=3 " Leave some buffer when scrolling down 102set scrolloff=3 " Leave some buffer when scrolling down
53set showmatch " Show pairing brackets 103set showmatch " Show pairing brackets
54set display=lastline 104set display=lastline
55set lazyredraw 105set lazyredraw
56set formatoptions+=m " 遇到Unicode值大於255的文本,不必等到空格再折行
57set formatoptions+=B " 合併兩行中文時,不在中間加空格
58set whichwrap=b,s 106set whichwrap=b,s
59 107
60" Side column 108" Side column
61set signcolumn=yes number relativenumber 109set number relativenumber
62 110
63" Cursor 111" Cursor
64set cursorline 112set cursorline
@@ -67,30 +115,40 @@ set matchtime=2
67 115
68" In most of the cases, it is overrides by lightline.vim 116" In most of the cases, it is overrides by lightline.vim
69set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c 117set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
70set laststatus=2 " Always show the status line 118set laststatus=2 " Always show the status line
71set ruler " Show cursor position 119set ruler " Show cursor position
72set wildmenu wildoptions=pum,fuzzy 120set wildmenu wildoptions=pum,fuzzy
73 121
74" Format of error message 122" Format of error message
75set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m 123set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
76 124
125" Direction for new window
126set splitright
127
77" }}} 128" }}}
78" EDIT ----------------{{{ 129" EDIT {{{
130
131" overrides ftplugin in runtimepath
132" Don't wrap line when typing CJK characters
133" Don't add spaces for CJK
134" Don't add comment at next line
135autocmd Filetype * set fo+=mB fo-=cro
79 136
80set backspace=eol,start,indent " Set Backspace behaviors
81set autoindent smartindent
82set shiftwidth=2 137set shiftwidth=2
138set autoindent smartindent
83set cindent 139set cindent
84set ttimeout 140set ttimeout
85set timeoutlen=500 141set timeoutlen=500
142
143set backspace=eol,start,indent " Set Backspace behaviors
144
86" set updatetime=4000 145" set updatetime=4000
87" autocmd CursorHold * normal! m' 146" autocmd CursorHold * normal! m'
88 147
89" TAB and special Chars ----------------{{{ 148" TAB and special Chars {{{
90 149
91set tabstop=8 150set tabstop=8 softtabstop=8
92set expandtab 151set expandtab
93set softtabstop=-1
94 152
95" Invisible chars 153" Invisible chars
96set nolist 154set nolist
@@ -99,23 +157,23 @@ set listchars=tab:»·,extends:>,precedes:<
99" }}} 157" }}}
100 158
101" }}} 159" }}}
102" JUMP to anoterh file ----------------{{{ 160" JUMP to anoterh file {{{
103 161
104set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file) 162set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file)
105set suffixesadd=.md " Enable reference markdown file without extension 163set suffixesadd=.md " Enable reference markdown file without extension
106 164
107" }}} 165" }}}
108" SEARCH ----------------{{{ 166" SEARCH {{{
109 167
110set ignorecase " Search case without case sensation 168set ignorecase " Search case without case sensation
111set smartcase 169set smartcase
112set hlsearch " Hilight all matched texts 170set hlsearch " Highlight all matched texts
113set incsearch " Show matched strings when typing 171set incsearch " Show matched strings when typing
114 172
115" }}} 173" }}}
116" BUFFERS ----------------{{{ 174" BUFFERS {{{
117 175
118" Go to last cursor position ----------------{{{ 176" Go to last cursor position {{{
119augroup vimStartup 177augroup vimStartup
120 au! 178 au!
121 " When editing a file, always jump to the last known cursor position. 179 " When editing a file, always jump to the last known cursor position.
@@ -131,21 +189,22 @@ augroup END
131" }}} 189" }}}
132 190
133" }}} 191" }}}
134" FOLD ----------------{{{ 192" FOLD {{{
193
135set foldenable " Allow fold 194set foldenable " Allow fold
136set foldmethod=indent " Fold contents by indent 195set foldmethod=indent " Fold contents by indent
137set foldlevel=2 196set foldlevel=2
138set fillchars+=foldopen:▽,foldsep:│,foldclose:▶ 197set fillchars+=foldopen:▽,foldsep:│,foldclose:▶
139let g:defaut_foldcolumn = "" 198let g:defaut_foldcolumn = ""
140if has('nvim') 199if has('nvim')
141 let g:defaut_foldcolumn = "auto:5" 200 let g:defaut_foldcolumn = "auto:3"
142else 201else
143 let g:defaut_foldcolumn = 5 202 let g:defaut_foldcolumn = 3
144endif 203endif
145let &foldcolumn = g:defaut_foldcolumn 204let &foldcolumn = g:defaut_foldcolumn
146 205
147" }}} 206" }}}
148" ENCODING_PREFERENCE ----------------{{{ 207" ENCODING_PREFERENCE {{{
149 208
150if has('multi_byte') 209if has('multi_byte')
151 set encoding=utf-8 210 set encoding=utf-8
@@ -155,7 +214,7 @@ if has('multi_byte')
155endif 214endif
156 215
157" }}} 216" }}}
158" BACKUP ----------------{{{ 217" BACKUP {{{
159 218
160" Allow backup 219" Allow backup
161set backup 220set backup
@@ -170,7 +229,7 @@ set backupdir=~/.vim/tmp
170set writebackup 229set writebackup
171 230
172" }}} 231" }}}
173" HIGHLIGHT ----------------{{{ 232" HIGHLIGHT {{{
174 233
175syntax enable 234syntax enable
176set conceallevel=1 235set conceallevel=1
@@ -185,7 +244,7 @@ highlight ExtraWhitespace ctermbg=red guibg=red
185match ExtraWhitespace /\s\+$/ 244match ExtraWhitespace /\s\+$/
186 245
187" }}} 246" }}}
188" MISC ----------------{{{ 247" MISC {{{
189 248
190" Use Unix way to add newline 249" Use Unix way to add newline
191set ffs=unix,dos,mac 250set ffs=unix,dos,mac
diff --git a/vim/init/config.vim b/vim/init/config.vim
index 4e1c06c..4181ad3 100644
--- a/vim/init/config.vim
+++ b/vim/init/config.vim
@@ -3,7 +3,7 @@
3" Do some autocommand for by contexts 3" Do some autocommand for by contexts
4"====================================================================== 4"======================================================================
5 5
6" Unnamed Buffer ----------------{{{ 6" Unnamed Buffer {{{
7 7
8" Automatically delete unnamed empty buffer when leaving 8" Automatically delete unnamed empty buffer when leaving
9augroup DeleteUnnamedEmptBuffer! 9augroup DeleteUnnamedEmptBuffer!
@@ -12,7 +12,7 @@ augroup DeleteUnnamedEmptBuffer!
12augroup END 12augroup END
13 13
14" }}} 14" }}}
15" Small Terminal ----------------{{{ 15" Small Terminal {{{
16 16
17augroup TerminalSize 17augroup TerminalSize
18 au! 18 au!
@@ -27,13 +27,13 @@ augroup TerminalSize
27augroup END 27augroup END
28 28
29" }}} 29" }}}
30" X11 ----------------{{{ 30" X11 {{{
31 31
32" Change IM to US when exit to Normal mode 32" Change IM to US when exit to Normal mode
33autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true 33autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true
34 34
35" }}} 35" }}}
36" TMUX ----------------{{{ 36" TMUX {{{
37 37
38" 有 tmux 何没有的功能键超时(毫秒) 38" 有 tmux 何没有的功能键超时(毫秒)
39if $TMUX != '' 39if $TMUX != ''
@@ -60,7 +60,7 @@ if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
60endif 60endif
61 61
62" }}} 62" }}}
63" KeyCode ----------------{{{ 63" KeyCode {{{
64 64
65"---------------------------------------------------------------------- 65"----------------------------------------------------------------------
66" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021 66" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021
@@ -114,22 +114,22 @@ call s:key_escape('<S-F11>', '[23;2~')
114call s:key_escape('<S-F12>', '[24;2~') 114call s:key_escape('<S-F12>', '[24;2~')
115 115
116" }}} 116" }}}
117" Filetype ----------------{{{ 117" Filetype {{{
118 118
119augroup InitFileTypes 119augroup InitFileTypes
120 120
121 au! 121 au!
122 122
123 " Filetype for Vim ----------------{{{ 123 " Filetype for Vim {{{
124 124
125 " Help page 125 " Help page
126 autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif 126 autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted | endif
127 127
128 " quickfix: hide line number 128 " quickfix: hide line number
129 autocmd FileType quickfix setlocal nonumber 129 autocmd FileType quickfix setlocal nonumber
130 130
131 " }}} 131 " }}}
132 " Shebeng: Set filetype from shebeng ----------------{{{ 132 " Shebeng: Set filetype from shebeng {{{
133 function! s:ApplyShebang() 133 function! s:ApplyShebang()
134 let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$') 134 let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$')
135 let l:shebangMatch = #{ node: "javascript" } 135 let l:shebangMatch = #{ node: "javascript" }
@@ -143,7 +143,7 @@ augroup InitFileTypes
143 endfunction 143 endfunction
144 autocmd BufReadPost * call <SID>ApplyShebang() 144 autocmd BufReadPost * call <SID>ApplyShebang()
145 " }}} 145 " }}}
146 " Markdown ----------------{{{ 146 " Markdown {{{
147 147
148 augroup Config_Markdown 148 augroup Config_Markdown
149 au! 149 au!
@@ -168,7 +168,7 @@ augroup InitFileTypes
168 augroup END 168 augroup END
169 169
170 " }}} 170 " }}}
171 " HTML ----------------{{{ 171 " HTML {{{
172 172
173 " Usage: <leader>cl(ass) or <leader>id to edit html tag attribute 173 " Usage: <leader>cl(ass) or <leader>id to edit html tag attribute
174 function! s:ChangeAttr(pattern) 174 function! s:ChangeAttr(pattern)
@@ -192,17 +192,17 @@ augroup InitFileTypes
192 192
193 " Reload preview server 193 " Reload preview server
194 autocmd BufWrite *.html,*.js,*.css call ReloadServer() 194 autocmd BufWrite *.html,*.js,*.css call ReloadServer()
195 function ReloadServer() 195 function! ReloadServer()
196 silent !browser-sync reload &>/dev/null 196 silent !browser-sync reload &>/dev/null
197 endfunction 197 endfunction
198 198
199 " }}} 199 " }}}
200 " Mail ----------------{{{ 200 " Mail {{{
201 201
202 autocmd BufRead /tmp/mutt-* set tw=72 202 autocmd BufRead /tmp/mutt-* set tw=72
203 203
204 " }}} 204 " }}}
205 " Password ----------------{{{ 205 " Password {{{
206 206
207 " Hide the first line of a file if editing password file 207 " Hide the first line of a file if editing password file
208 " TODO a better way to determine a file is related to password-store, now use 208 " TODO a better way to determine a file is related to password-store, now use
@@ -218,7 +218,7 @@ augroup InitFileTypes
218 norm! ggzfl 218 norm! ggzfl
219 endfunction 219 endfunction
220 " }}} 220 " }}}
221 " Beancount ----------------{{{ 221 " Beancount {{{
222 222
223 autocmd BufRead,BufNewFile *.bean call PrepareBean() 223 autocmd BufRead,BufNewFile *.bean call PrepareBean()
224 function PrepareBean() 224 function PrepareBean()
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim
index f13756b..1eb2b20 100644
--- a/vim/init/keymaps.vim
+++ b/vim/init/keymaps.vim
@@ -21,15 +21,15 @@ nnoremap <leader>W :set wrap!<CR>
21function! s:WriteOrEnterFileName() 21function! s:WriteOrEnterFileName()
22 if !empty(expand('%')) | write! | else | call feedkeys(":w ") | endif 22 if !empty(expand('%')) | write! | else | call feedkeys(":w ") | endif
23endfunction 23endfunction
24nmap <leader>w :call <SID>WriteOrEnterFileName()<CR> 24nnoremap <leader>w :call <SID>WriteOrEnterFileName()<CR>
25 25
26" :W sudo saves the file 26" :W sudo saves the file
27" (useful for handling the permission-denied error) 27" (useful for handling the permission-denied error)
28command! W execute 'w !sudo -S tee %' <bar> edit! 28command! W execute 'w !sudo -S tee %' <bar> edit!
29 29
30" Quit 30" Quit
31nmap <leader>q :q<CR> 31nnoremap <leader>q :q<CR>
32nmap cq :cq<CR> 32nnoremap cq :cq<CR>
33 33
34" Remap <CR> in Quickfix, Cmdwin Location list 34" Remap <CR> in Quickfix, Cmdwin Location list
35augroup vimrc_CRfix 35augroup vimrc_CRfix
@@ -57,7 +57,7 @@ augroup END
57" execute "set <M-h>=\eh" 57" execute "set <M-h>=\eh"
58 58
59" Spell 59" Spell
60nnoremap <leader><leader>sp :set spell!<CR>:set spell?<CR> 60nnoremap \s :set spell!<CR>:set spell?<CR>
61nnoremap <leader>ss ]s 61nnoremap <leader>ss ]s
62nnoremap <leader>S [s 62nnoremap <leader>S [s
63 63
@@ -68,6 +68,7 @@ nnoremap <C-g> 1<C-g>
68vnoremap Tz :!trans -t zh-TW -b<CR> 68vnoremap Tz :!trans -t zh-TW -b<CR>
69vnoremap Te :!trans -t en-US -b<CR> 69vnoremap Te :!trans -t en-US -b<CR>
70 70
71
71" }}} 72" }}}
72" WORKING_DIR ----------------{{{ 73" WORKING_DIR ----------------{{{
73 74
@@ -82,8 +83,8 @@ nnoremap cd :cd %:p:h<CR>:pwd<CR>
82 83
83nnoremap cd<space> :cd<space> 84nnoremap cd<space> :cd<space>
84nnoremap cdg :call CdToGitRepo()<CR>:pwd<CR> 85nnoremap cdg :call CdToGitRepo()<CR>:pwd<CR>
85noremap <C-[> :cd ..<CR>:pwd<CR> 86nnoremap <C-[> :cd ..<CR>:pwd<CR>
86noremap <C-]> :call InCaseCdToLatestDir()<CR> 87nnoremap <C-]> :call InCaseCdToLatestDir()<CR>
87 88
88" Switch CWD to root git directory 89" Switch CWD to root git directory
89function! CdToGitRepo() 90function! CdToGitRepo()
@@ -105,17 +106,21 @@ endfunction
105" MOTION ----------------{{{ 106" MOTION ----------------{{{
106 107
107" j/k will move virtual lines (lines that wrap) 108" j/k will move virtual lines (lines that wrap)
108noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j') 109nnoremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
109noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k') 110nnoremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
110 111
111" Quick move in a line 112" Quick move in a line
112noremap <C-h> 30h 113nnoremap <C-h> 30h
113noremap <C-l> 30l 114nnoremap <C-l> 30l
114 115
115" File under the cursor 116" File under the cursor
116nnoremap <CR> gf 117nnoremap <CR> gf
117nnoremap gF :e <cfile><CR> 118nnoremap gF :e <cfile><CR>
118 119
120xnoremap iq i"
121xnoremap aq a"
122
123
119" READLINE_FEATURES ----------------{{{ 124" READLINE_FEATURES ----------------{{{
120 125
121inoremap <C-f> <Right> 126inoremap <C-f> <Right>
@@ -145,22 +150,22 @@ cnoremap <C-k> <C-x>d$<C-c>
145cnoremap <M-d> <C-x>de<C-c> 150cnoremap <M-d> <C-x>de<C-c>
146 151
147" Moving with wrap 152" Moving with wrap
148noremap <m-j> gj 153nnoremap <m-j> gj
149noremap <m-k> gk 154nnoremap <m-k> gk
150inoremap <m-j> <c-\><c-o>gj 155inoremap <m-j> <c-\><c-o>gj
151inoremap <m-k> <c-\><c-o>gk 156inoremap <m-k> <c-\><c-o>gk
152" }}} 157" }}}
153" JUMP_TO_TABS_WITH_ALT ----------------{{{ 158" JUMP_TO_TABS_WITH_ALT ----------------{{{
154 159
155noremap <silent><A-1> :tabn 1<CR> 160nnoremap <silent><A-1> :tabn 1<CR>
156noremap <silent><A-2> :tabn 2<CR> 161nnoremap <silent><A-2> :tabn 2<CR>
157noremap <silent><M-3> :tabn 3<CR> 162nnoremap <silent><M-3> :tabn 3<CR>
158noremap <silent><M-4> :tabn 4<CR> 163nnoremap <silent><M-4> :tabn 4<CR>
159noremap <silent><M-5> :tabn 5<CR> 164nnoremap <silent><M-5> :tabn 5<CR>
160noremap <silent><M-6> :tabn 6<CR> 165nnoremap <silent><M-6> :tabn 6<CR>
161noremap <silent><M-7> :tabn 7<CR> 166nnoremap <silent><M-7> :tabn 7<CR>
162noremap <silent><M-8> :tabn 8<CR> 167nnoremap <silent><M-8> :tabn 8<CR>
163noremap <silent><M-9> :tablast<CR> 168nnoremap <silent><M-9> :tablast<CR>
164inoremap <silent><A-1> <Esc>:tabn 1<CR> 169inoremap <silent><A-1> <Esc>:tabn 1<CR>
165inoremap <silent><A-2> <Esc>:tabn 2<CR> 170inoremap <silent><A-2> <Esc>:tabn 2<CR>
166inoremap <silent><M-3> <Esc>:tabn 3<CR> 171inoremap <silent><M-3> <Esc>:tabn 3<CR>
@@ -211,23 +216,25 @@ nnoremap <leader>ee :edit $MYVIMRC<CR>
211" MANAGE_BUFFERS ----------------{{{ 216" MANAGE_BUFFERS ----------------{{{
212 217
213" Set options 218" Set options
214noremap st :set<space> 219nnoremap so :set<space>
215noremap <leader><leader>ft :<C-\>e'set filetype='..&filetype<CR> 220nnoremap <leader><leader>ft :<C-\>e'set filetype='..&filetype<CR>
216noremap <leader><leader>li :set list!<CR> 221nnoremap <leader><leader>sw :<C-\>e'set shiftwidth='..&shiftwidth<CR>
217noremap <leader><leader>sw :<C-\>e'set shiftwidth='..&shiftwidth<CR> 222nnoremap <leader><leader>ts :<C-\>e'set tabstop='..&tabstop<CR>
218noremap <leader><leader>nu :set number!<CR> 223nnoremap \e :set expandtab!<CR>:set expandtab?<CR>
219noremap <leader><leader>ru :set relativenumber!<CR> 224nnoremap \l :set list!<CR>:set list?<CR>
225nnoremap \n :set nu!<CR>:set nu?<CR>
226nnoremap \r :set relativenumber!<CR>:set rnu?<CR>
220 227
221" Open a new buffer 228" Open a new buffer
222nmap <leader>B :enew<CR> 229nnoremap <leader>B :enew<CR>
223nmap <leader>O :e /tmp/buffer<CR> 230nnoremap <leader>O :e /tmp/buffer<CR>
224 231
225" Let <leader>l toggle between this and the last accessed buffer 232" Let <leader>l toggle between this and the last accessed buffer
226augroup SaveLastBuffer 233augroup SaveLastBuffer
227 let g:lastbuffer = 1 234 let g:lastbuffer = 1
228 au BufLeave * let g:lastbuffer = bufnr() 235 au BufLeave * if &buflisted | let g:lastbuffer = expand('<abuf>') | endif
229augroup END 236augroup END
230noremap <leader>l :exe "buffer ".g:lastbuffer<CR> 237nnoremap <leader>l :exe "buffer ".g:lastbuffer<CR>
231 238
232" Use Ctrl-C for buffer delete or quit vim ----------------{{{ 239" Use Ctrl-C for buffer delete or quit vim ----------------{{{
233 240
@@ -238,9 +245,11 @@ function! ToggleQuit()
238 let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock" 245 let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock"
239 echo message 246 echo message
240endfunction 247endfunction
241nnoremap <leader><leader>gl :call ToggleQuit()<CR> 248nnoremap \q :call ToggleQuit()<CR>
242 249
243function! CloseBufferSafely() 250function! CloseBufferSafely()
251 let l:bufnr = bufnr()
252 " Ask Saving
244 if &modified 253 if &modified
245 let answer = confirm("Save changes?", "&Yes\n&No\n&Cancel") 254 let answer = confirm("Save changes?", "&Yes\n&No\n&Cancel")
246 if answer == 1 | write | endif 255 if answer == 1 | write | endif
@@ -248,27 +257,22 @@ function! CloseBufferSafely()
248 if answer == "" | return | endif 257 if answer == "" | return | endif
249 endif 258 endif
250 259
251 let bufs = getbufinfo({'buflisted': 1}) 260 if g:tab_group[tabpagenr()] == [l:bufnr]
252 if len(bufs) == 1 261 bdelete
253 bdelete!
254 else 262 else
255 b# | bd! # 263 bprevious | bd #
256 endif 264 endif
257endfunction 265endfunction
258func! QuitWithCheck() 266func! QuitWithCheck()
259 if g:quitVimWhenPressingCtrlC 267 if g:quitVimWhenPressingCtrlC
260 silent! quit 268 silent! quit
261 else 269 else
262 echo "Press <leader><leader>gl to allow quit with <C-c>" 270 echo "Press \\q to allow quit with <C-c>"
263 endif 271 endif
264endfunc 272endfunc
265function! Bye() 273function! Bye()
266 let windows = gettabinfo(tabpagenr())[0]['windows'] 274 let windows = gettabinfo(tabpagenr())[0]['windows']
267 try 275 let bufs = getbufinfo({'buflisted': 1})
268 let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs']
269 catch
270 let bufs = getbufinfo({'buflisted': 1})
271 endtry
272 276
273 if len(windows) == 1 && len(bufs) == 1 277 if len(windows) == 1 && len(bufs) == 1
274 call QuitWithCheck() 278 call QuitWithCheck()
@@ -282,8 +286,8 @@ function! Bye()
282endfunction 286endfunction
283nnoremap <silent> <C-c> :call Bye()<CR> 287nnoremap <silent> <C-c> :call Bye()<CR>
284 288
285 289" }}}
286" Diff Mode ---------------- 290" Diff Mode {{{
287 291
288function! CloseBuffersForDiff() 292function! CloseBuffersForDiff()
289 windo | if &diff && &buftype == "nofile" | bdelete | endif 293 windo | if &diff && &buftype == "nofile" | bdelete | endif
@@ -329,10 +333,10 @@ nnoremap <leader><leader>sb :windo set scrollbind!<CR>
329" 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在 333" 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在
330" bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的 334" bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的
331"---------------------------------------------------------------------- 335"----------------------------------------------------------------------
332noremap <m-H> <c-w>h 336nnoremap <m-H> <c-w>h
333noremap <m-L> <c-w>l 337nnoremap <m-L> <c-w>l
334noremap <m-J> <c-w>j 338nnoremap <m-J> <c-w>j
335noremap <m-K> <c-w>k 339nnoremap <m-K> <c-w>k
336inoremap <m-H> <esc><c-w>h 340inoremap <m-H> <esc><c-w>h
337inoremap <m-L> <esc><c-w>l 341inoremap <m-L> <esc><c-w>l
338inoremap <m-J> <esc><c-w>j 342inoremap <m-J> <esc><c-w>j
@@ -365,12 +369,12 @@ map <leader>tc :tabclose<CR>
365map <leader>tm :tabmove<SPACE> 369map <leader>tm :tabmove<SPACE>
366map <leader>to :tabonly<CR> 370map <leader>to :tabonly<CR>
367 371
368noremap <silent><m-h> :call Tab_MoveLeft()<CR> 372nnoremap <silent><m-h> :call Tab_MoveLeft()<CR>
369noremap <silent><m-l> :call Tab_MoveRight()<CR> 373nnoremap <silent><m-l> :call Tab_MoveRight()<CR>
370 374
371" Let <leader>tl toggle between this and the last accessed tab 375" Let <leader>tl toggle between this and the last accessed tab
372let g:lasttab = 1 376let g:lasttab = 1
373nmap <Leader>tl :exe "tabn ".g:lasttab<CR> 377nnoremap <Leader>tl :exe "tabn ".g:lasttab<CR>
374autocmd TabLeave * let g:lasttab = tabpagenr() 378autocmd TabLeave * let g:lasttab = tabpagenr()
375 379
376" Opens a new tab with the current buffer's path 380" Opens a new tab with the current buffer's path
@@ -394,8 +398,8 @@ endfunc
394" FOLD ----------------{{{ 398" FOLD ----------------{{{
395 399
396" Set fold options 400" Set fold options
397noremap <leader><leader>fm :<C-\>e'set foldmethod='..&foldmethod<CR> 401nnoremap <leader><leader>fm :<C-\>e'set foldmethod='..&foldmethod<CR>
398noremap <leader><leader>fc :<C-\>e'set foldcolumn='..&foldcolumn<CR> 402nnoremap <leader><leader>fc :<C-\>e'set foldcolumn='..&foldcolumn<CR>
399 403
400nnoremap zi zizz 404nnoremap zi zizz
401 405
@@ -463,7 +467,7 @@ endfunction
463" HIGHLIGHT ----------------{{{ 467" HIGHLIGHT ----------------{{{
464 468
465" Disable highlight when <leader><CR> is pressed 469" Disable highlight when <leader><CR> is pressed
466noremap <silent> <leader><CR> :noh<CR> 470nnoremap <silent> <leader><CR> :noh<CR>
467 471
468function! HiFile() 472function! HiFile()
469 let i = 1 473 let i = 1
@@ -501,7 +505,6 @@ inoremap ( ()<Left>
501inoremap [ []<Left> 505inoremap [ []<Left>
502inoremap { {}<Left> 506inoremap { {}<Left>
503 507
504vnoremap S sa
505vnoremap ' <ESC>`<i'<ESC>`>la'<ESC> 508vnoremap ' <ESC>`<i'<ESC>`>la'<ESC>
506vnoremap q <ESC>`<i"<ESC>`>la"<ESC> 509vnoremap q <ESC>`<i"<ESC>`>la"<ESC>
507vnoremap ( <ESC>`<i(<ESC>`>la)<ESC> 510vnoremap ( <ESC>`<i(<ESC>`>la)<ESC>
@@ -591,6 +594,8 @@ vnoremap <CR> <Cmd>call SubstituteBySearch()<CR>
591" }}} 594" }}}
592" SIGN ----------------{{{ 595" SIGN ----------------{{{
593 596
597nnoremap <leader><leader>sc :<C-\>e'set signcolumn='..&signcolumn<CR>
598
594nnoremap <leader>si :exe ":sign place " .. line('.') .. " line=" .. line('.') .. " name=piet file=" .. expand("%:p")<CR> 599nnoremap <leader>si :exe ":sign place " .. line('.') .. " line=" .. line('.') .. " name=piet file=" .. expand("%:p")<CR>
595nnoremap <leader>sI :exe ":sign unplace * file=" .. expand("%:p")<CR> 600nnoremap <leader>sI :exe ":sign unplace * file=" .. expand("%:p")<CR>
596 601