我已经开始使用Vim来开发Perl脚本,并开始发现它非常强大。

我喜欢的一件事是能够同时打开多个文件:

vi main.pl maintenance.pl

然后在他们之间跳来跳去

:n
:prev

然后查看哪个文件是打开的:

:args

要添加一个文件,我可以说:

:n test.pl

我希望它会被添加到我的文件列表中,但相反,它会清除我当前的文件列表,当我输入:args时,我只有test.pl打开。

那么我如何在我的args列表中添加和删除文件?


当前回答

如果你在osx上,想要能够点击你的标签,使用MouseTerm和SIMBL(从这里)。另外,看看这个相关的讨论。

其他回答

Vim(但不是原始的Vi!)有制表符,我发现(在许多情况下)比缓冲区更好。你可以说:table [filename]在新选项卡中打开一个文件。标签之间的循环是通过点击标签或组合键[n]gt和gt来完成的。graphic Vim甚至有图形标签。

清单

要查看当前缓冲区的列表,我使用:

:ls

开放

要打开一个新文件,我使用

:e ../myFile.pl

增强的TAB补全功能(将set wildmenu放在你的.vimrc中)。

注意:你也可以使用:find,它会为你搜索一组路径,但是你需要先自定义这些路径。


切换

要在所有打开的文件之间切换,我使用

:b myfile

增强选项卡完成(仍然设置野生菜单)。

注意::b#选择最后访问的文件,因此您可以使用它在两个文件之间快速切换。


使用windows

Ctrl-W s和Ctrl-W v水平和垂直分割当前窗口。你也可以使用:split和:vertical split (:sp和:vs)

Ctrl-W w在打开的窗口之间切换,Ctrl-W h(或j或k或l)在打开的窗口中导航。

按Ctrl-W c关闭当前窗口,按Ctrl-W o关闭除当前窗口外的所有窗口。

使用-o或-o标志启动vim将打开每个文件各自的分割。


有了所有这些,我不需要在Vim中使用标签,我的手指可以找到缓冲区,而不是眼睛。

注意:如果您希望所有文件都转到同一个Vim实例,请使用——remote-silent选项启动Vim。

将所有缓冲区更改为选项卡视图。

 :tab sball

将打开TAB视图的所有缓冲区。然后我们可以使用任何与制表符相关的命令

gt or :tabn           "    go to next tab
gT or :tabp or :tabN  "    go to previous tab

详细信息见:help tab-page-commands。

我们可以通过vim -p file1 file2命令vim以tab视图的形式打开多个文件。 别名vim='vim -p'将很有用。 在~/.vimrc中使用下面的自动命令也可以实现同样的功能

 au VimEnter * if !&diff | tab all | tabfirst | endif

总之,回答这个问题: 添加到arg列表:arga文件

从参数列表中删除:argd模式

更多信息见:help arglist

如果你在osx上,想要能够点击你的标签,使用MouseTerm和SIMBL(从这里)。另外,看看这个相关的讨论。

我有效处理多个文件的方法是使用tmux。

它允许你垂直和水平分割窗口,如下所示:

I have it working this way on both my mac and linux machines and I find it better than the native window pane switching mechanism that's provided (on Macs). I find the switching easier and only with tmux have I been able to get the 'new page at the same current directory' working on my mac (despite the fact that there seems to be options to open new panes in the same directory) which is a surprisingly critical piece. An instant new pane at the current location is amazingly useful. A method that does new panes with the same key combos for both OS's is critical for me and a bonus for all for future personal compatibility. Aside from multiple tmux panes, I've also tried using multiple tabs, e.g. and multiple new windows, e.g. and ultimately I've found that multiple tmux panes to be the most useful for me. I am very 'visual' and like to keep my various contexts right in front of me, connected together as panes.

Tmux还支持水平和垂直窗格,这是旧屏幕所不支持的(尽管mac的iterm2似乎支持它,但是,当前的目录设置对我来说不管用)。tmux 1.8