gpt4 book ai didi

vim - 更改为缓冲区父目录的简单方法?

转载 作者:行者123 更新时间:2023-11-30 23:55:19 26 4
gpt4 key购买 nike

如果我的缓冲区列表如下所示:

:ls  1 %a   "Application/PowerModeServer/test/testTimer.cpp" line 1  2      "Application/PowerModeServer/test/fakeClient.cpp" line 0  3      "Application/PowerModeServer/test/fakeVp.cpp" line 0  7      "Application/PowerModeServer/private/IMsgSender.h" line 0  9      "Application/PowerModeServer/private/UdpSocket.h" line 0 17      "Application/PowerModeServer/src/PowerFsm.cpp" line 0 18      "Application/PowerModeServer/src/lua/src/lfunc.h" line 0 19      "Application/PowerModeServer/src/lua/src/lmem.h" line 0 20      "Application/PowerModeServer/src/lua/src/ltable.h" line 0 41      "Application/PowerModeServer/src/PowerModeServer.cpp" line 0 42      "Application/PowerModeServer/src/UdpSocket.cpp" line 0 43      "Application/PowerModeServer/src/Timer.cpp" line 0

what's the easiest way to change vim's current working directory to the parent directory of, say, buffer 19? I'm used to finger-mumbling my way there using:

:cd A<TAB>P<TAB>s<TAB>l<TAB>s<TAB>
but this requires quite a few keystrokes---especially if the completions are ambiguous. I'd like something more concise, like:
:cd ~19
Any recommendations?

EDIT: Added mods suggested by ZyX here since I don't have sufficient points to edit Jeet's answer directly:

function! CdBufWorkingDir(target)
if empty(a:target)
let targetdir = expand("%:p:h")
else
if a:target =~# '^\~\d'
let targetdir = fnamemodify(bufname(str2nr(a:target[1:])), ":p:h")
else
let targetdir = a:target
endif
endif
execute "cd ".fnameescape(targetdir)
echo targetdir
endfunction
command! -nargs=? Cdbuf :call CdBufWorkingDir(<q-args>)

最佳答案

我使用这个脚本 http://www.vim.org/scripts/script.php?script_id=1325在我的 .vimrc 中

map <silent> <F3> :call BufferList()<CR>
let g:BufferListWidth = 25
let g:BufferListMaxWidth = 50

然后按 f3,你可以只使用/filenname + enter

或者您可以使用 :ls <enter> :buffer BufferNumber <enter>如果您不想安装脚本或 map

为了使最后一个更容易,将它添加到您的 .vimrc nmap <F3> :ls<CR>:buffer然后你可以按 f3 并直接输入你想要的缓冲区的编号。

关于vim - 更改为缓冲区父目录的简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4330394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com