aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init/keymaps.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/init/keymaps.vim')
-rw-r--r--vim/init/keymaps.vim183
1 files changed, 92 insertions, 91 deletions
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim
index ff4821e..dc7f616 100644
--- a/vim/init/keymaps.vim
+++ b/vim/init/keymaps.vim
@@ -128,7 +128,8 @@ vnoremap so :source<CR>
128"---------------------------------------------------------------------- 128"----------------------------------------------------------------------
129" MANAGE_VIMRC 129" MANAGE_VIMRC
130"---------------------------------------------------------------------- 130"----------------------------------------------------------------------
131nnoremap <leader>e :edit $MYVIMRC<CR> 131nnoremap <leader>e :scriptnames<space>
132nnoremap <leader>ee :edit $MYVIMRC<CR>
132autocmd! BUFWRITEPOST $MYVIMRC source $MYVIMRC 133autocmd! BUFWRITEPOST $MYVIMRC source $MYVIMRC
133 134
134 135
@@ -227,16 +228,16 @@ map <leader>te :tabedit <C-r>=expand("%:p:h")<cr>
227 228
228" Tab move functions 229" Tab move functions
229function! Tab_MoveLeft() 230function! Tab_MoveLeft()
230 let l:tabnr = tabpagenr() - 2 231 let l:tabnr = tabpagenr() - 2
231 if l:tabnr >= 0 232 if l:tabnr >= 0
232 exec 'tabmove '.l:tabnr 233 exec 'tabmove '.l:tabnr
233 endif 234 endif
234endfunc 235endfunc
235function! Tab_MoveRight() 236function! Tab_MoveRight()
236 let l:tabnr = tabpagenr() + 1 237 let l:tabnr = tabpagenr() + 1
237 if l:tabnr <= tabpagenr('$') 238 if l:tabnr <= tabpagenr('$')
238 exec 'tabmove '.l:tabnr 239 exec 'tabmove '.l:tabnr
239 endif 240 endif
240endfunc 241endfunc
241 242
242 243
@@ -283,22 +284,22 @@ vnoremap Q <ESC>`<i「<ESC>`>la」<ESC>
283" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window 284" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window
284" 285"
285function! Redir(cmd) 286function! Redir(cmd)
286 for win in range(1, winnr('$')) 287 for win in range(1, winnr('$'))
287 if getwinvar(win, 'scratch') 288 if getwinvar(win, 'scratch')
288 execute win . 'windo close' 289 execute win . 'windo close'
289 endif 290 endif
290 endfor 291 endfor
291 if a:cmd =~ '^!' 292 if a:cmd =~ '^!'
292 let output = system(matchstr(a:cmd, '^!\zs.*')) 293 let output = system(matchstr(a:cmd, '^!\zs.*'))
293 else 294 else
294 redir => output 295 redir => output
295 execute a:cmd 296 execute a:cmd
296 redir END 297 redir END
297 endif 298 endif
298 vnew 299 vnew
299 let w:scratch = 1 300 let w:scratch = 1
300 setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile 301 setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
301 call setline(1, split(output, "\n")) 302 call setline(1, split(output, "\n"))
302endfunction 303endfunction
303 304
304command! -nargs=1 -complete=command Redir silent call Redir(<q-args>) 305command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)
@@ -340,22 +341,22 @@ inoremap <m-J> <esc><c-w>j
340inoremap <m-K> <esc><c-w>k 341inoremap <m-K> <esc><c-w>k
341 342
342if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1') 343if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1')
343 " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式 344 " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式
344 " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+? 345 " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+?
345 " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改 346 " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改
346 set termwinkey=<c-_> 347 set termwinkey=<c-_>
347 tnoremap <m-H> <c-_>h 348 tnoremap <m-H> <c-_>h
348 tnoremap <m-L> <c-_>l 349 tnoremap <m-L> <c-_>l
349 tnoremap <m-J> <c-_>j 350 tnoremap <m-J> <c-_>j
350 tnoremap <m-K> <c-_>k 351 tnoremap <m-K> <c-_>k
351 tnoremap <m-q> <c-\><c-n> 352 tnoremap <m-q> <c-\><c-n>
352elseif has('nvim') 353elseif has('nvim')
353 " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 354 " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式
354 tnoremap <m-H> <c-\><c-n><c-w>h 355 tnoremap <m-H> <c-\><c-n><c-w>h
355 tnoremap <m-L> <c-\><c-n><c-w>l 356 tnoremap <m-L> <c-\><c-n><c-w>l
356 tnoremap <m-J> <c-\><c-n><c-w>j 357 tnoremap <m-J> <c-\><c-n><c-w>j
357 tnoremap <m-K> <c-\><c-n><c-w>k 358 tnoremap <m-K> <c-\><c-n><c-w>k
358 tnoremap <m-q> <c-\><c-n> 359 tnoremap <m-q> <c-\><c-n>
359endif 360endif
360 361
361 362
@@ -394,7 +395,7 @@ nnoremap <silent> <F4> :AsyncRun -cwd=<root> cmake . <cr>
394 395
395" Windows 下支持直接打开新 cmd 窗口运行 396" Windows 下支持直接打开新 cmd 窗口运行
396if has('win32') || has('win64') 397if has('win32') || has('win64')
397 nnoremap <silent> <F8> :AsyncRun -cwd=<root> -mode=4 make run <cr> 398 nnoremap <silent> <F8> :AsyncRun -cwd=<root> -mode=4 make run <cr>
398endif 399endif
399 400
400 401
@@ -402,45 +403,45 @@ endif
402" F5 运行当前文件:根据文件类型判断方法,并且输出到 quickfix 窗口 403" F5 运行当前文件:根据文件类型判断方法,并且输出到 quickfix 窗口
403"---------------------------------------------------------------------- 404"----------------------------------------------------------------------
404function! ExecuteFile() 405function! ExecuteFile()
405 let cmd = '' 406 let cmd = ''
406 if index(['c', 'cpp', 'rs', 'go'], &ft) >= 0 407 if index(['c', 'cpp', 'rs', 'go'], &ft) >= 0
407 " native 语言,把当前文件名去掉扩展名后作为可执行运行 408 " native 语言,把当前文件名去掉扩展名后作为可执行运行
408 " 写全路径名是因为后面 -cwd=? 会改变运行时的当前路径,所以写全路径 409 " 写全路径名是因为后面 -cwd=? 会改变运行时的当前路径,所以写全路径
409 " 加双引号是为了避免路径中包含空格 410 " 加双引号是为了避免路径中包含空格
410 let cmd = '"$(VIM_FILEDIR)/$(VIM_FILENOEXT)"' 411 let cmd = '"$(VIM_FILEDIR)/$(VIM_FILENOEXT)"'
411 elseif &ft == 'python' 412 elseif &ft == 'python'
412 let $PYTHONUNBUFFERED=1 " 关闭 python 缓存,实时看到输出 413 let $PYTHONUNBUFFERED=1 " 关闭 python 缓存,实时看到输出
413 let cmd = 'python "$(VIM_FILEPATH)"' 414 let cmd = 'python "$(VIM_FILEPATH)"'
414 elseif &ft == 'javascript' 415 elseif &ft == 'javascript'
415 let cmd = 'node "$(VIM_FILEPATH)"' 416 let cmd = 'node "$(VIM_FILEPATH)"'
416 elseif &ft == 'perl' 417 elseif &ft == 'perl'
417 let cmd = 'perl "$(VIM_FILEPATH)"' 418 let cmd = 'perl "$(VIM_FILEPATH)"'
418 elseif &ft == 'ruby' 419 elseif &ft == 'ruby'
419 let cmd = 'ruby "$(VIM_FILEPATH)"' 420 let cmd = 'ruby "$(VIM_FILEPATH)"'
420 elseif &ft == 'php' 421 elseif &ft == 'php'
421 let cmd = 'php "$(VIM_FILEPATH)"' 422 let cmd = 'php "$(VIM_FILEPATH)"'
422 elseif &ft == 'lua' 423 elseif &ft == 'lua'
423 let cmd = 'lua "$(VIM_FILEPATH)"' 424 let cmd = 'lua "$(VIM_FILEPATH)"'
424 elseif &ft == 'zsh' 425 elseif &ft == 'zsh'
425 let cmd = 'zsh "$(VIM_FILEPATH)"' 426 let cmd = 'zsh "$(VIM_FILEPATH)"'
426 elseif &ft == 'ps1' 427 elseif &ft == 'ps1'
427 let cmd = 'powershell -file "$(VIM_FILEPATH)"' 428 let cmd = 'powershell -file "$(VIM_FILEPATH)"'
428 elseif &ft == 'vbs' 429 elseif &ft == 'vbs'
429 let cmd = 'cscript -nologo "$(VIM_FILEPATH)"' 430 let cmd = 'cscript -nologo "$(VIM_FILEPATH)"'
430 elseif &ft == 'sh' 431 elseif &ft == 'sh'
431 let cmd = 'bash "$(VIM_FILEPATH)"' 432 let cmd = 'bash "$(VIM_FILEPATH)"'
432 else 433 else
433 return 434 return
434 endif 435 endif
435 " Windows 下打开新的窗口 (-mode=4) 运行程序,其他系统在 quickfix 运行 436 " Windows 下打开新的窗口 (-mode=4) 运行程序,其他系统在 quickfix 运行
436 " -raw: 输出内容直接显示到 quickfix window 不匹配 errorformat 437 " -raw: 输出内容直接显示到 quickfix window 不匹配 errorformat
437 " -save=2: 保存所有改动过的文件 438 " -save=2: 保存所有改动过的文件
438 " -cwd=$(VIM_FILEDIR): 运行初始化目录为文件所在目录 439 " -cwd=$(VIM_FILEDIR): 运行初始化目录为文件所在目录
439 if has('win32') || has('win64') 440 if has('win32') || has('win64')
440 exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=4 '. cmd 441 exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=4 '. cmd
441 else 442 else
442 exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=0 '. cmd 443 exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=0 '. cmd
443 endif 444 endif
444endfunc 445endfunc
445 446
446 447
@@ -452,17 +453,17 @@ endfunc
452" 下面进行 grep,这样能方便的对相关项目进行搜索 453" 下面进行 grep,这样能方便的对相关项目进行搜索
453"---------------------------------------------------------------------- 454"----------------------------------------------------------------------
454if executable('rg') 455if executable('rg')
455 noremap <silent><F2> :AsyncRun! -cwd=<root> rg -n --no-heading 456 noremap <silent><F2> :AsyncRun! -cwd=<root> rg -n --no-heading
456 \ --color never -g *.h -g *.c* -g *.py -g *.js -g *.vim 457 \ --color never -g *.h -g *.c* -g *.py -g *.js -g *.vim
457 \ <C-R><C-W> "<root>" <cr> 458 \ <C-R><C-W> "<root>" <cr>
458elseif has('win32') || has('win64') 459elseif has('win32') || has('win64')
459 noremap <silent><F2> :AsyncRun! -cwd=<root> findstr /n /s /C:"<C-R><C-W>" 460 noremap <silent><F2> :AsyncRun! -cwd=<root> findstr /n /s /C:"<C-R><C-W>"
460 \ "\%CD\%\*.h" "\%CD\%\*.c*" "\%CD\%\*.py" "\%CD\%\*.js" 461 \ "\%CD\%\*.h" "\%CD\%\*.c*" "\%CD\%\*.py" "\%CD\%\*.js"
461 \ "\%CD\%\*.vim" 462 \ "\%CD\%\*.vim"
462 \ <cr> 463 \ <cr>
463else 464else
464 noremap <silent><F2> :AsyncRun! -cwd=<root> grep -n -s -R <C-R><C-W> 465 noremap <silent><F2> :AsyncRun! -cwd=<root> grep -n -s -R <C-R><C-W>
465 \ --include='*.h' --include='*.c*' --include='*.py' 466 \ --include='*.h' --include='*.c*' --include='*.py'
466 \ --include='*.js' --include='*.vim' 467 \ --include='*.js' --include='*.vim'
467 \ '<root>' <cr> 468 \ '<root>' <cr>
468endif 469endif