简体   繁体   English

vimrc - 当前工作目录

[英]vimrc - current working directory

I would like to be able to access the current working directory in my vimrc. 我希望能够访问我的vimrc中的当前工作目录。 For example, I can access the current file by using %. 例如,我可以使用%访问当前文件。

Specifically, I have the following line in my vimrc: map ,l :!latex % 具体来说,我在我的vimrc中有以下行:map,l:!latex%

When it runs everything works fine, except the resulting dvi and other files are stored in my home directory instead of my current working directory. 当它运行时一切正常,除了生成的dvi和其他文件存储在我的主目录而不是我当前的工作目录。

Any suggestions? 有什么建议?

See :help autochdir . 请参阅:help autochdir Vim can automatically change the current working directory to the directory where the file you are editing lives. Vim可以自动将当前工作目录更改为您正在编辑的文件所在的目录。

Otherwise, if you want to do this manually, see :help cd and :help lcd . 否则,如果要手动执行此操作,请参阅:help cd:help lcd

:he filename-modifiers

:!latex % -output-directory %:h

Most likely, you're running vim from your home directory, so it is the current for him . 很可能,你是从你的主目录运行vim,所以这是他的最新动态 The latex command, being invoked from vim, also therefore has the home directory as current. 因此,从vim调用的latex命令也将主目录作为当前目录。

You probably know this, and want just to extract path from the filename and supply it as an argument to -o option of the latex command. 您可能知道这一点,并且只想从文件名中提取路径并将其作为参数提供给latex命令的-o选项。 Just use the shell capabilities: 只需使用shell功能:

:!latex % -output-directory `dirname "%"`

I am not sure that it's -output-directory option, but you get what you asked for--a directory name of the file you're editing. 我不确定它是-output-directory选项,但是你得到了你要求的内容 - 你正在编辑的文件的目录名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM