在vim中打开与当前文件在同一文件夹中的文件 [英] Opening files in the same folder as the current file, in vim

查看:24
本文介绍了在vim中打开与当前文件在同一文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 vim 中,当我打开一个缓冲区时,我经常需要在该文件所在的同一目录中加载另一个文件,但由于我通常不将 cd 放入其中,pwd 是父文件夹,所以我每次都必须重新输入路径.这有捷径吗?或将密码更改为文件所在目录的方法?

In vim, when I have a buffer open, I often need to load another file in the same directory that file is in, but since I don't usually cd into it, the pwd is a parent folder, so I have to retype the path every time. Is there a shortcut for this? or a way to change the pwd to the directory the file is in?

示例:

cd /src
vi lib/foo/file.js

lib/foo 有两个文件:file.jsfile2.js

在vi中:

:e file2.js  # doesn't work

推荐答案

较新版本的 vim 内置了 autochdir 命令,如果没有,您可以退回到类似 BufEnter 的设置.

Newer versions of vim have a autochdir command built in, if not you can fall back to a BufEnter like setup.

" set vim to chdir for each file
if exists('+autochdir')
    set autochdir
else
    autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ /
endif

这篇关于在vim中打开与当前文件在同一文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆