Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在从 vim 中 cd 到新目录后自动执行命令。例如,我打开 gvim 并运行:
:cd ~/src/player
此时我希望 vim 自动获取该目录中的文件。
这可能吗?
你可以在你的 .vimrc 中为它写一个别名:
command -nargs=1 Mycd call MyCd(<args>) function MyCd(path) cd a:path e somefile.ext endfunction
然后只需键入:
:Mycd /some/path/
不完全是你要求的,但是
:au BufEnter , BufFilePost * lc <afile> :h
将使得每当您打开一个新文件(例如使用:e ~/src/player/README)时,您将自动将目录更改为~/src/player. 如果您打开多个缓冲区,您将在它们之间切换时切换到包含本地缓冲区的目录,如果您打开多个选项卡,它们将保留在各自的目录中。
:e ~/src/player/README
~/src/player