如何在 VIm 和终端中始终拥有相同的当前目录? [英] How to always have the same current directory in VIm and in Terminal?

查看:33
本文介绍了如何在 VIm 和终端中始终拥有相同的当前目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的终端当前目录跟随我的 VIM 之一.

I would like to my terminal current directory follows my VIM one.

示例:

在终端:

> pwd
=> /Users/rege
> vim

然后在 VIM 中

:cd /Users/rege/project
<Ctrl-z>(for suspend)

在终端

> pwd
=> /Users/rege/project

我使用的是 MacOS、zsh、tmux.

I`m using MacOS, zsh, tmux.

我需要这个,因为当我尝试在 VIM 中使用标签时,标签是从我的终端目录而不是 vim 目录中检入的.

I need this because when Im trying to use tags in VIM, tags are check in project from my terminal directory not vim one.

因此,当我更改 VIM 当前目录时,我需要始终更改终端当前目录.

So I need to change terminal current directory always when I change VIM current directory.

推荐答案

在你挂起 Vim 之后,你在你的 shell 中发出什么样的命令?Vim 的 :!command 还不够吗?

What kind of command do you issue in your shell after you suspend Vim? Isn't Vim's :!command enough?

使用set autochdir,当你从一个文件跳转到另一个文件时,Vim 的当前目录会跟随你.使用此设置,一个简单的 :!ctags -R . 将始终在当前文件的目录中创建一个 tags 文件.

With set autochdir, Vim's current directory follows you as you jump from file to file. With this setting, a simple :!ctags -R . will always create a tags file in the directory of the current file.

另一个有用的设置是 set tags=./tags,tags;$HOME 它告诉 Vim 在当前文件的目录中查找一个 tags 文件,然后在当前目录"中向上直到它到达您的 ~/.您可以修改端点以满足您的需要.这允许您在编辑属于项目的任何文件时在项目的根目录使用 tags.

Another useful setting is set tags=./tags,tags;$HOME which tells Vim to look for a tags file in the directory of the current file, then in the "current directory" and up and up until it reaches your ~/. You might modify the endpoint to suit your needs. This allows you to use a tags at the root of your project while editing any file belonging to the project.

所以,基本上,你可以在不离开 Vim 的情况下走很长的路.

So, basically, you can go a long way without leaving Vim at all.

如果您确实需要返回 shell 来发出您的命令,:shell(或 :sh)会启动一个新的 shell使用 Vim 的当前目录.完成后,您只需 $ exit 即可返回 Vim:

If you really need to go back to the shell to issue your commands, :shell (or :sh) launchs a new shell with Vim's current directory. When you are done, you only have to $ exit to go back to Vim:

$ pwd
/home/romainl
$ vim
:cd Projects
:sh
$ pwd
/home/romainl/Projects
$ exit

这篇关于如何在 VIm 和终端中始终拥有相同的当前目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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