开发者

vim command after cd

开发者_运维技巧

I want to execute a command automatically after cd'ing to a new directory from within vim. For example, I open gvim and run:

:cd ~/src/player

I would like vim at this point to automatically source a file that is in that directory.

Is this possible?


You can write an alias for that in your .vimrc:

command -nargs=1 Mycd call MyCd(<args>)
function MyCd(path)
  cd a:path
  e somefile.ext
endfunction

Then just type:

:Mycd /some/path/


Not exactly what you're asking for, but

:au BufEnter,BufFilePost * lc <afile>:h

will make it so that whenever you open a new file (e.g. with :e ~/src/player/README), you will automatically change directories to ~/src/player. If you open multiple buffers, you will be changed to the directory containing the local buffer as you change between them, and if you open multiple tabs, they will remain in their respective directories.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜