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

编程入门 行业动态 更新时间:2024-10-28 12:29:45
如何在VIm和终端中始终拥有相同的当前目录?(How to always have the same current directory in VIm and in Terminal?)

我想我的终端当前目录跟随我的VIM之一。

例:

在TERMINAL:

> pwd => /Users/rege > vim

然后在VIM

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

在终端

> pwd => /Users/rege/project

我正在使用MacOS,zsh,tmux。

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

因此,当我更改VIM当前目录时,我总是需要更改终端当前目录。

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

Example:

In TERMINAL:

> pwd => /Users/rege > vim

Then in VIM

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

In terminal

> pwd => /Users/rege/project

I`m using MacOS, zsh, tmux.

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

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

最满意答案

暂停Vim后,你在shell中发出什么样的命令? 不是Vim的:!command不够?

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

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

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

如果你真的需要回到shell发出命令, :shell (或:sh )用Vim的当前目录启动一个新的shell。 当你完成后,你只需要$ exit以回到Vim:

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

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

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.

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.

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

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

更多推荐

本文发布于:2023-08-07 21:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466181.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:终端   目录   如何在   VIm   Terminal

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!