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

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

vi main.pl maintenance.pl

然后在他们之间跳来跳去

:n
:prev

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

:args

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

:n test.pl

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

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


当前回答

When I started using VIM I didn't realize that tabs were supposed to be used as different window layouts, and buffer serves the role for multiple file editing / switching between each other. Actually in the beginning tabs are not even there before v7.0 and I just opened one VIM inside a terminal tab (I was using gnome-terminal at the moment), and switch between tabs using alt+numbers, since I thought using commands like :buffers, :bn and :bp were too much for me. When VIM 7.0 was released I find it's easier to manager a lot of files and switched to it, but recently I just realized that buffers should always be the way to go, unless one thing: you need to configure it to make it works right.

所以我尝试了vim-airline,并启用了可视的顶部选项卡式缓冲条,但图形与我的iTerm2有问题,所以我尝试了其他几个,似乎MBE最适合我。我还设置shift+h/l作为快捷键,因为原来的那些(移动到当前页面的头部/尾部)对我来说不是很有用。 map <S-h>:bprev<返回> map <S-l>:bnext<返回>

它似乎比gt和gt更简单,而且:e也比:tabnew更简单。我发现:bd不像:q那样方便,虽然(MBE有一些问题),但我可以在缓冲区中使用所有文件。

其他回答

我认为您在查看已打开的文件列表时可能使用了错误的命令。

尝试执行一个:ls来查看你已经打开的文件列表,你会看到:

   1 %a   "./checkin.pl"            line 1
  2 #    "./grabakamailogs.pl"     line 1
  3      "./grabwmlogs.pl"         line 0
  etc.

然后,您可以通过引用列出的数字来浏览文件,例如: b: 3

或者你可以通过输入数字,但使用sb而不是b来分割屏幕。

作为旁白,%表示当前可见的文件,#表示备用文件。

您可以通过按Ctrl Shift 6在这两个文件之间轻松切换

编辑:像:ls,你可以使用:reg来查看你的寄存器的当前内容,包括0-9寄存器,其中包含你已经删除的内容。如果您想重新使用以前删除的文本,这尤其有用。

我建议使用插件

书树

这里是github链接的说明。

书树

我使用vim-plug作为插件管理器,但你也可以使用Vundle。

我来-plug

冯德尔

我有效处理多个文件的方法是使用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

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

当在vim中使用多个文件时,我主要使用这些命令(打开了大约350个文件):

:b <partial filename><tab>(跳转到缓冲区) :bw(缓冲区擦除,删除缓冲区) :e <文件路径>(编辑,打开一个新的缓冲区> . Pltags -允许跳转到子例程/方法定义