MacVim 在现有窗口中打开文件
有没有办法设置 MacVim 在正在运行的 MacVim 实例的当前窗口中打开新文件?我目前设置了 MacVim 首选项“在当前窗口的新选项卡中打开新文件”,但理想情况下我只想以“:e new_file”的方式打开新文件,而不需要选项卡。
我的主要动机是我目前在我的工作流程中使用 NERDTree 和 Bufexplorer,根本不需要选项卡。我还使用 PeepOpen,它非常棒,除了它总是根据 MacVim 的首选项打开文件,所以我能做的最好的事情就是让它在当前 MacVim 窗口中使用新选项卡打开。
Is there a way to set up MacVim to open a new file in the current window in a running MacVim instance? I currently have the MacVim preference "Open new files in a new tab in the current window" set, but ideally I'd just like to open new files the way ":e new_file" works, without the tabs.
My main motivation is that I currently use NERDTree and Bufexplorer for my workflow and don't need the tabs at all. I'm also using PeepOpen, which is awesome except it always opens files based on MacVim's preferences, so the best I can do is get it to open in the current MacVim window with a new tab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您还可以添加:
alias mvim='open -a MacVim'
到您的
.bash_profile
这对我来说似乎是最简单的解决方案。
You can also add:
alias mvim='open -a MacVim'
to your
.bash_profile
This seems like the simplest solution to me.
在看到这里的所有内容并尝试了所
出现的结果后,我个人使用这样的命令。
我发现这
对我有用,然后我很快就在我的
.profile
中添加了一个别名。是的,如果你在选项后不给它提供一个文件,它就会呕吐,但是谁会打开一个没有名称的空白文件呢?I personally use a command like this, after seeing everything here and resorting to experimenting with what
turned up.
I found that
worked for me and then I soon added an alias to my
.profile
. Yes, it barfs if you don't feed it a file after the option, but who opens a blank file with no name anyway?您也可以考虑这个关于编辑主 mvim 脚本的技巧。
为 MacVim 改进 mvim
这个修改稍微不那么严重,也有效:
显然这些都有点次优,因为当你进行 MacVim 更新。但它们帮助我在新的 Mac Vim 选项卡中从终端打开多个文件。
You might also consider this tip on editing the main mvim script.
Improving mvim for MacVim
This modification is a bit less severe and also works:
Obviously these are both a bit sub-optimal b/c you'll have to maintain the hack when you do a MacVim update. But they helped me a bunch in opening multiple files from the Terminal in new Mac Vim tabs.
@Björn Winckler 的答案向您展示了如何对通过查找器和其他操作系统打开机制打开的文件执行此操作。
如果您希望它与 mvim 命令一起使用,请找到 mvim 文件并将底部的行从 更改为
这
将使从命令行打开的所有文件也在同一窗口中打开。
另外,如果您希望文件打开相同的缓冲区(如果该文件已经打开)而不是拆分或添加新选项卡
au VimEnter,BufWinEnter * NERDTreeFind
到您的 gvimrc (这样就不会干扰您的常规 vim)(最后一部分要求您安装 NERDTree)
@Björn Winckler's answer shows you how to do it for files opened through finder and other OS opening mechanisms.
If you want it to work with the mvim command find the
mvim
file and changes the lines at the bottom fromto
This will make all files opened from the command line open in the same window as well.
Also if you would like the file to open the same buffer if that file is already open in stead of splitting or adding a new tab
au VimEnter,BufWinEnter * NERDTreeFind
to your gvimrc (so not to interfere with your regular vim)(this last part requires you to have NERDTree installed)
我是这样实现的:
在 VIM 中,有一个命令“tabo”,它使当前选项卡成为唯一的选项卡。我将以下内容添加到我的 ~/.vimrc 中:
这使得每当我创建新缓冲区或输入新缓冲区时,当前选项卡都会自动成为唯一的选项卡。该命令不会影响我的缓冲区,因此效果正是我想要的:在 MacVim 的当前实例中打开文件并且不添加任何新选项卡。
This is how I accomplished this:
In VIM, there's a command "tabo", which makes the current tab the only tab. I added the following to my ~/.vimrc:
This makes it so that any time I create a new buffer or enter a new buffer, the current tab becomes the only tab automatically. This command doesn't affect my buffers, so the effect is exactly what I want: open a file in the current instance of MacVim and don't add any new tabs.
我发现 Azriel 的答案很好,但如果文件不存在,它就不起作用。这个小函数可以做同样的事情,但你也可以创建新文件。
只需将其添加到您的
.bash_profile
中即可。然后,您可以编辑一个新文件foo
as,它将在新选项卡中打开。
I found Azriel's answer great but it does not work if the file does not exist. This little function does the same thing but you can also create new files.
Just add it in your
.bash_profile
. You can then edit a new filefoo
asand it will open in a new tab.