Change working directory to currently opened file

前端 未结 3 1127
甜味超标
甜味超标 2021-02-01 18:52

How can I change my working directory to the path of the file that I currently have open?

Example

  1. current working directory is $HOME
3条回答
  •  日久生厌
    2021-02-01 19:00

    That's actually a builtin. (here's the help link)

    :set autochdir
    

    Stick that in your .vimrc or whatnot (:e $MYVIMRC). As mentioned here, sometimes plugins will have issues with that and you need to use something more complicated like

    autocmd BufEnter * lcd %:p:h
    

提交回复
热议问题