在vim中打开目录
我是一名 mac 用户,正在认真尝试 vim。我习惯的大多数 GUI 编辑器都允许我通过执行以下命令来将目录作为“项目”打开:
编辑 ~/www/example.com/
vim 等效的 vim ~/www/example.com/
将显示目录中的文件列表,我可以打开它们。但它没有将 vim 的工作目录设置为该路径,我必须运行 :cd .
来设置工作目录。
有没有某种方法,也许使用 shell 脚本,打开 vim 并将其工作目录设置为给定路径?
我实际上正在使用 MacVim,如果这有什么区别的话。
I'm a mac user giving vim a serious try. Most of the GUI editors I'm used to allow me to open a directory as a "project" by executing a command like:
edit ~/www/example.com/
The vim equivalent vim ~/www/example.com/
will show me a list of files in the directory, and I can open them. But it does not set vim's working directory to that path, I have to run :cd .
to set the working directory.
Is there some way, perhaps with a shell script, to open vim and have it's working directory set to a given path?
I'm actually using MacVim, if that makes any difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
感谢@sehe的建议,我想出了这个。不确定这是否是最好的解决方案,但它似乎有效。
Thanks to @sehe's suggestions, I came up with this. Not sure if it's the best solution, but it seems to work.
Braindead:
不那么重要:
你总是可以将
:cd %:h
映射到一个方便的键或放入一个自动命令(我实际上不会推荐后者,但对于品味是没有争议的)哦,还有对于目录而不是文件:
就足够了
Braindead:
Less so:
You can always map
:cd %:h
to a convenient key or put in an autocommand (I wouldn't actually recommend the latter, but there is no arguing about taste)Oh and for directories instead of files:
is quite enough
这有帮助吗?
我找到了http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
Would this help?
I found it http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
尝试将以下内容添加到您的 .vimrc
这将使目录浏览使用树形样式来显示文件(您可以通过将光标放在目录上并按 Enter 来展开目录)并使当前工作目录也成为您的目录正在浏览。
您可能还对 NERDTree 插件感兴趣,该插件提供了比内置浏览器更高级的目录浏览器。它有一个选项
可以使当前目录与显示的树的根匹配,或者
在您使用命令(
:e
或:NERDTree
)浏览树时更改目录。新目录。Try adding the following to your .vimrc
This will make the directory browsing use a tree style for showing the files (you can expand a directory by putting the cursor on a directory and hitting enter) and make the current working directory also be the one you are browsing.
You might also be interested in the NERDTree plugin that provides a directory browser that is more advanced than the built in one. It has an option
to make the current directory match the root of the displayed tree or
to change the directory whenever you use a command (
:e
or:NERDTree
) to browse a new directory.