aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init/keymaps.vim
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-08-05 18:41:51 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-08-05 18:41:51 +0800
commitb57c461014f585655d897abf0e0ac982807396b7 (patch)
treed3b10761cb75d52ff41b0822bc646c9d1c08d935 /vim/init/keymaps.vim
parentcc96870ff94afba7b0f2dc18f0209611ff7201f7 (diff)
Update
Diffstat (limited to 'vim/init/keymaps.vim')
-rw-r--r--vim/init/keymaps.vim71
1 files changed, 36 insertions, 35 deletions
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim
index a423c20..e8cb61d 100644
--- a/vim/init/keymaps.vim
+++ b/vim/init/keymaps.vim
@@ -3,7 +3,7 @@
3"====================================================================== 3"======================================================================
4" vim: sw=2 ts=2 foldmethod=marker foldmarker={{{,}}} 4" vim: sw=2 ts=2 foldmethod=marker foldmarker={{{,}}}
5 5
6" COMMON_MAPPING {{{ 6" COMMON {{{
7 7
8" Space for searching 8" Space for searching
9map <space> / 9map <space> /
@@ -37,9 +37,7 @@ augroup vimrc_CRfix
37augroup END 37augroup END
38 38
39" Spell 39" Spell
40nnoremap \s :set spell!<CR>:set spell?<CR> 40nnoremap \sp :set spell!<CR>:set spell?<CR>
41nnoremap <leader>ss ]s
42nnoremap <leader>S [s
43 41
44" Show full path by default 42" Show full path by default
45nnoremap <C-g> 1<C-g> 43nnoremap <C-g> 1<C-g>
@@ -48,6 +46,8 @@ nnoremap <C-g> 1<C-g>
48vnoremap Tz :!trans -t zh-TW -b<CR> 46vnoremap Tz :!trans -t zh-TW -b<CR>
49vnoremap Te :!trans -t en-US -b<CR> 47vnoremap Te :!trans -t en-US -b<CR>
50 48
49nnoremap q: :
50
51" }}} 51" }}}
52" WORKING_DIR {{{ 52" WORKING_DIR {{{
53 53
@@ -158,6 +158,16 @@ inoremap <silent><M-9> <Esc>:tablast<CR>
158" }}} 158" }}}
159 159
160" }}} 160" }}}
161" EDIT {{{
162
163" Move one line up and down
164nnoremap <C-j> ddp
165nnoremap <C-k> ddkP
166
167" Clear current line
168nnoremap S S<ESC>
169
170" }}}
161" REGISTER {{{ 171" REGISTER {{{
162" Paste register 0 172" Paste register 0
163nnoremap <C-p> "0p 173nnoremap <C-p> "0p
@@ -176,7 +186,7 @@ vnoremap Y "+y
176function! DeleteMark(mark) 186function! DeleteMark(mark)
177 let mark = nr2char(a:mark) 187 let mark = nr2char(a:mark)
178 echo mark 188 echo mark
179 if mark =~ '[a-Z]' 189 if mark =~ '\a'
180 execute "delmarks " . mark 190 execute "delmarks " . mark
181 endif 191 endif
182endfunc 192endfunc
@@ -259,7 +269,7 @@ function! ChangeUnfold(downward, count)
259 let foldend -= move 269 let foldend -= move
260 endif 270 endif
261 norm! zd 271 norm! zd
262 exe foldstart..","..foldend.."fold" 272 try | silent! exe foldstart..","..foldend.."fold" | endtry
263 273
264 " Get back to origin cursor position 274 " Get back to origin cursor position
265 norm! '' 275 norm! ''
@@ -268,16 +278,6 @@ nnoremap <expr> z> ":\<C-u>call ChangeUnfold(1,"..v:count..")\<CR>"
268nnoremap <expr> z< ":\<C-u>call ChangeUnfold(0,"..v:count..")\<CR>" 278nnoremap <expr> z< ":\<C-u>call ChangeUnfold(0,"..v:count..")\<CR>"
269 279
270"}}} 280"}}}
271" EDIT {{{
272
273" Move one line up and down
274nnoremap <C-j> ddp
275nnoremap <C-k> ddkP
276
277" Clear current line
278nnoremap S S<ESC>
279
280" }}}
281" TERMINAL {{{ 281" TERMINAL {{{
282 282
283" Use <leader>z to toggle 283" Use <leader>z to toggle
@@ -285,13 +285,17 @@ let g:alacritty_extra_padding = 0
285function! ToggleWinPadding() 285function! ToggleWinPadding()
286 if g:alacritty_extra_padding 286 if g:alacritty_extra_padding
287 !alacritty msg config --window-id $WINDOWID --reset 287 !alacritty msg config --window-id $WINDOWID --reset
288 call SetEmulaterBackground()
288 hi EndOfBuffer None 289 hi EndOfBuffer None
289 hi MsgArea None 290 hi MsgArea None
290 else 291 else
291 redir => output | hi LineNr | redir END 292 redir => output | hi LineNr | redir END
292 let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze') 293 let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze')
293 exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color 294
294 exe "hi MsgArea guibg="..bg_color 295 try
296 exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color
297 exe "hi MsgArea guibg="..bg_color
298 endtry
295 exe "!alacritty msg config --window-id $WINDOWID window.padding.x=300 'colors.primary.background=\"\\"..bg_color.."\"'" 299 exe "!alacritty msg config --window-id $WINDOWID window.padding.x=300 'colors.primary.background=\"\\"..bg_color.."\"'"
296 endif 300 endif
297 301
@@ -380,24 +384,16 @@ function! CloseBufferSafely()
380 if answer == "" | return | endif 384 if answer == "" | return | endif
381 endif 385 endif
382 386
383 let l:bufnr = bufnr() 387 let bufnr = bufnr()
384
385 if len(t:bufs) == 1 388 if len(t:bufs) == 1
386 " Close tab for last buffer 389 " Close tab for last buffer
387 tabclose 390 tabclose
388 else 391 else
389 " Switch to proper buffer 392 " Switch to proper buffer
390 let l:next_buf = get(t:bufs, bufnr('#')) ? bufnr('#') : filter(t:bufs, 'v:val != '..l:bufnr)[0] 393 let next_buf = get(t:bufs, bufnr('#')) ? bufnr('#') : filter(t:bufs, 'v:val != '..bufnr)[0]
391 exe "b "..l:next_buf 394 exe "b "..next_buf
392 call filter(t:bufs, 'v:val != '..l:bufnr) 395 call filter(t:bufs, 'v:val != '..bufnr)
393 endif 396 endif
394
395 " Delete buffer if every t:buf doesn't have it
396 for tab in gettabinfo()
397 if get(tab.variables.bufs, l:bufnr) | return | endif
398 endfor
399 exe "bd! "..l:bufnr
400
401endfunction 397endfunction
402function! Bye() 398function! Bye()
403 let windows = gettabinfo(tabpagenr())[0]['windows'] 399 let windows = gettabinfo(tabpagenr())[0]['windows']
@@ -493,10 +489,10 @@ endif
493" MANAGE_TABS {{{ 489" MANAGE_TABS {{{
494 490
495" Useful mappings for managing tabs 491" Useful mappings for managing tabs
496map <leader>tn :tabnew<CR> 492nnoremap <leader>tn :tabnew<CR>
497map <leader>tc :tabclose<CR> 493nnoremap <leader>tc :tabclose<CR>
498map <leader>tm :tabmove<SPACE> 494nnoremap <leader>tm :tabmove<SPACE>
499map <leader>to :tabonly<CR> 495nnoremap <leader>to :tabonly<CR>
500 496
501nnoremap <silent><m-h> :call Tab_MoveLeft()<CR> 497nnoremap <silent><m-h> :call Tab_MoveLeft()<CR>
502nnoremap <silent><m-l> :call Tab_MoveRight()<CR> 498nnoremap <silent><m-l> :call Tab_MoveRight()<CR>
@@ -508,7 +504,7 @@ autocmd TabLeave * let g:lasttab = tabpagenr()
508 504
509" Opens a new tab with the current buffer's path 505" Opens a new tab with the current buffer's path
510" Super useful when editing files in the same directory 506" Super useful when editing files in the same directory
511map <leader>te :tabedit <C-r>=expand("%:p:h")<CR> 507nnoremap <leader>te :tabedit <C-r>=expand("%:p:h")<CR>
512 508
513" Tab move functions 509" Tab move functions
514function! Tvab_MoveLeft() 510function! Tvab_MoveLeft()
@@ -598,6 +594,11 @@ endfunction
598" }}} 594" }}}
599" HIGHLIGHT {{{ 595" HIGHLIGHT {{{
600 596
597nnoremap <expr> \sy exists("g:syntax_on") ? ":syntax off <CR>" : ":syntax enable<CR>"
598
599" Toggle conceallevel0/2
600nnoremap <expr> \c ":set conceallevel="..(&cole ? 0 : 2).."<CR>:set cole?<CR>"
601
601" Disable highlight when <leader><CR> is pressed 602" Disable highlight when <leader><CR> is pressed
602nnoremap <silent> <leader><CR> :noh<CR> 603nnoremap <silent> <leader><CR> :noh<CR>
603 604