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

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

vi main.pl maintenance.pl

然后在他们之间跳来跳去

:n
:prev

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

:args

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

:n test.pl

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

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


当前回答

这个线程中的一些答案建议使用制表符,其他建议使用buffer来完成同样的事情。制表符和缓冲区是不同的。我强烈建议你阅读这篇文章“Vim标签疯狂-缓冲区vs标签”。

下面是我从这篇文章中摘录的一个很好的总结:

简介:

缓冲区是文件在内存中的文本。 窗口是缓冲区上的视口。 标签页是窗口的集合。

其他回答

我使用以下,这给了你很多功能,你会期望在其他编辑器,如Sublime文本/ Textmate

Use buffers not 'tab pages'. Buffers are the same concept as tabs in almost all other editors. If you want the same look of having tabs you can use the vim-airline plugin with the following setting in your .vimrc: let g:airline#extensions#tabline#enabled = 1. This automatically displays all the buffers as tab headers when you have no tab pages opened Use Tim Pope's vim-unimpaired which gives [b and ]b for moving to previous/next buffers respectively (plus a whole host of other goodies) Have set wildmenu in your .vimrc then when you type :b <file part> + Tab for a buffer you will get a list of possible buffers that you can use left/right arrows to scroll through Use Tim Pope's vim-obsession plugin to store sessions that play nicely with airline (I had lots of pain with sessions and plugins) Use Tim Pope's vim-vinegar plugin. This works with the native :Explore but makes it much easier to work with. You just type - to open the explorer, which is the same key as to go up a directory in the explorer. Makes navigating faster (however with fzf I rarely use this) fzf (which can be installed as a vim plugin) is also a really powerful fuzzy finder that you can use for searching for files (and buffers too). fzf also plays very nicely with fd (a faster version of find) Use Ripgrep with vim-ripgrep to search through your code base and then you can use :cdo on the results to do search and replace

你可以在你的.bashrc文件中添加vim和vim -p的别名:

alias vim="vim -p"

这将导致在选项卡中从shell打开多个文件,而不必随后在vim中调用:tab ball。

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

我经常使用命令行和git,所以我在bashrc中有这个别名:

alias gvim="gvim --servername \$(git rev-parse --show-toplevel || echo 'default') --remote-tab"

这将在现有窗口的新选项卡中打开每个新文件,并为每个git存储库创建一个窗口。 因此,如果你从回购A中打开两个文件,从回购B中打开三个文件,你将最终得到两个窗口,一个是回购A,有两个选项卡,一个是回购B,有三个选项卡。

如果你正在打开的文件不包含在git repo中,它将进入一个默认窗口。

为了在选项卡之间跳转,我使用了以下映射:

nmap <C-p> :tabprevious<CR>
nmap <C-n> :tabnext<CR>

要一次打开多个文件,您应该将此方法与其他解决方案之一结合使用。

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

尝试执行一个: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寄存器,其中包含你已经删除的内容。如果您想重新使用以前删除的文本,这尤其有用。