From 3526eb6d756e3c37190814eca2e22ce9f7d9f1de Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Fri, 28 Jun 2024 01:24:13 +0800 Subject: Update --- vim/init/keymaps.vim | 183 ++++++++++++++++++++++++++------------------------- 1 file changed, 92 insertions(+), 91 deletions(-) (limited to 'vim/init/keymaps.vim') 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 "---------------------------------------------------------------------- " MANAGE_VIMRC "---------------------------------------------------------------------- -nnoremap e :edit $MYVIMRC +nnoremap e :scriptnames +nnoremap ee :edit $MYVIMRC autocmd! BUFWRITEPOST $MYVIMRC source $MYVIMRC @@ -227,16 +228,16 @@ map te :tabedit =expand("%:p:h") " Tab move functions function! Tab_MoveLeft() - let l:tabnr = tabpagenr() - 2 - if l:tabnr >= 0 - exec 'tabmove '.l:tabnr - endif + let l:tabnr = tabpagenr() - 2 + if l:tabnr >= 0 + exec 'tabmove '.l:tabnr + endif endfunc function! Tab_MoveRight() - let l:tabnr = tabpagenr() + 1 - if l:tabnr <= tabpagenr('$') - exec 'tabmove '.l:tabnr - endif + let l:tabnr = tabpagenr() + 1 + if l:tabnr <= tabpagenr('$') + exec 'tabmove '.l:tabnr + endif endfunc @@ -283,22 +284,22 @@ vnoremap Q ``>la」 " :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")) + 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() @@ -340,22 +341,22 @@ inoremap j inoremap k if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1') - " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式 - " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+? - " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改 - set termwinkey= - tnoremap h - tnoremap l - tnoremap j - tnoremap k - tnoremap + " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式 + " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+? + " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改 + set termwinkey= + tnoremap h + tnoremap l + tnoremap j + tnoremap k + tnoremap elseif has('nvim') - " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 - tnoremap h - tnoremap l - tnoremap j - tnoremap k - tnoremap + " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 + tnoremap h + tnoremap l + tnoremap j + tnoremap k + tnoremap endif @@ -394,7 +395,7 @@ nnoremap :AsyncRun -cwd= cmake . " Windows 下支持直接打开新 cmd 窗口运行 if has('win32') || has('win64') - nnoremap :AsyncRun -cwd= -mode=4 make run + nnoremap :AsyncRun -cwd= -mode=4 make run endif @@ -402,45 +403,45 @@ endif " F5 运行当前文件:根据文件类型判断方法,并且输出到 quickfix 窗口 "---------------------------------------------------------------------- function! ExecuteFile() - let cmd = '' - if index(['c', 'cpp', 'rs', 'go'], &ft) >= 0 - " native 语言,把当前文件名去掉扩展名后作为可执行运行 - " 写全路径名是因为后面 -cwd=? 会改变运行时的当前路径,所以写全路径 - " 加双引号是为了避免路径中包含空格 - let cmd = '"$(VIM_FILEDIR)/$(VIM_FILENOEXT)"' - elseif &ft == 'python' - let $PYTHONUNBUFFERED=1 " 关闭 python 缓存,实时看到输出 - let cmd = 'python "$(VIM_FILEPATH)"' - elseif &ft == 'javascript' - let cmd = 'node "$(VIM_FILEPATH)"' - elseif &ft == 'perl' - let cmd = 'perl "$(VIM_FILEPATH)"' - elseif &ft == 'ruby' - let cmd = 'ruby "$(VIM_FILEPATH)"' - elseif &ft == 'php' - let cmd = 'php "$(VIM_FILEPATH)"' - elseif &ft == 'lua' - let cmd = 'lua "$(VIM_FILEPATH)"' - elseif &ft == 'zsh' - let cmd = 'zsh "$(VIM_FILEPATH)"' - elseif &ft == 'ps1' - let cmd = 'powershell -file "$(VIM_FILEPATH)"' - elseif &ft == 'vbs' - let cmd = 'cscript -nologo "$(VIM_FILEPATH)"' - elseif &ft == 'sh' - let cmd = 'bash "$(VIM_FILEPATH)"' - else - return - endif - " Windows 下打开新的窗口 (-mode=4) 运行程序,其他系统在 quickfix 运行 - " -raw: 输出内容直接显示到 quickfix window 不匹配 errorformat - " -save=2: 保存所有改动过的文件 - " -cwd=$(VIM_FILEDIR): 运行初始化目录为文件所在目录 - if has('win32') || has('win64') - exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=4 '. cmd - else - exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=0 '. cmd - endif + let cmd = '' + if index(['c', 'cpp', 'rs', 'go'], &ft) >= 0 + " native 语言,把当前文件名去掉扩展名后作为可执行运行 + " 写全路径名是因为后面 -cwd=? 会改变运行时的当前路径,所以写全路径 + " 加双引号是为了避免路径中包含空格 + let cmd = '"$(VIM_FILEDIR)/$(VIM_FILENOEXT)"' + elseif &ft == 'python' + let $PYTHONUNBUFFERED=1 " 关闭 python 缓存,实时看到输出 + let cmd = 'python "$(VIM_FILEPATH)"' + elseif &ft == 'javascript' + let cmd = 'node "$(VIM_FILEPATH)"' + elseif &ft == 'perl' + let cmd = 'perl "$(VIM_FILEPATH)"' + elseif &ft == 'ruby' + let cmd = 'ruby "$(VIM_FILEPATH)"' + elseif &ft == 'php' + let cmd = 'php "$(VIM_FILEPATH)"' + elseif &ft == 'lua' + let cmd = 'lua "$(VIM_FILEPATH)"' + elseif &ft == 'zsh' + let cmd = 'zsh "$(VIM_FILEPATH)"' + elseif &ft == 'ps1' + let cmd = 'powershell -file "$(VIM_FILEPATH)"' + elseif &ft == 'vbs' + let cmd = 'cscript -nologo "$(VIM_FILEPATH)"' + elseif &ft == 'sh' + let cmd = 'bash "$(VIM_FILEPATH)"' + else + return + endif + " Windows 下打开新的窗口 (-mode=4) 运行程序,其他系统在 quickfix 运行 + " -raw: 输出内容直接显示到 quickfix window 不匹配 errorformat + " -save=2: 保存所有改动过的文件 + " -cwd=$(VIM_FILEDIR): 运行初始化目录为文件所在目录 + if has('win32') || has('win64') + exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=4 '. cmd + else + exec 'AsyncRun -cwd=$(VIM_FILEDIR) -raw -save=2 -mode=0 '. cmd + endif endfunc @@ -452,17 +453,17 @@ endfunc " 下面进行 grep,这样能方便的对相关项目进行搜索 "---------------------------------------------------------------------- if executable('rg') - noremap :AsyncRun! -cwd= rg -n --no-heading - \ --color never -g *.h -g *.c* -g *.py -g *.js -g *.vim - \ "" + noremap :AsyncRun! -cwd= rg -n --no-heading + \ --color never -g *.h -g *.c* -g *.py -g *.js -g *.vim + \ "" elseif has('win32') || has('win64') - noremap :AsyncRun! -cwd= findstr /n /s /C:"" - \ "\%CD\%\*.h" "\%CD\%\*.c*" "\%CD\%\*.py" "\%CD\%\*.js" - \ "\%CD\%\*.vim" - \ + noremap :AsyncRun! -cwd= findstr /n /s /C:"" + \ "\%CD\%\*.h" "\%CD\%\*.c*" "\%CD\%\*.py" "\%CD\%\*.js" + \ "\%CD\%\*.vim" + \ else - noremap :AsyncRun! -cwd= grep -n -s -R - \ --include='*.h' --include='*.c*' --include='*.py' - \ --include='*.js' --include='*.vim' - \ '' + noremap :AsyncRun! -cwd= grep -n -s -R + \ --include='*.h' --include='*.c*' --include='*.py' + \ --include='*.js' --include='*.vim' + \ '' endif -- cgit v1.2.3-70-g09d2