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

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

vi main.pl maintenance.pl

然后在他们之间跳来跳去

:n
:prev

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

:args

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

:n test.pl

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

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


当前回答

我经常使用命令行和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>

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

其他回答

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

 :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

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

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

:ls

用于打开缓冲区的列表

:bp前一个缓冲区 :bn下一个缓冲区 :bn (n个数字)移动到第n个缓冲区 :b <filename-part> with tab-key提供自动补全功能(太棒了!!)

在某些版本的vim中,bn和bp实际上分别是bnext和bprevious。Tab自动补全在这种情况下很有用。

或者当您处于正常模式时,使用^切换到您正在处理的最后一个文件。

另外,您可以保存vim的会话

:mksession! ~/today.ses

上面的命令将当前打开的文件缓冲区和设置保存到~/today.ses。您可以使用

vim -S ~/today.ses

记起昨天讲到哪里就不麻烦了。;)

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

我使用以下,这给了你很多功能,你会期望在其他编辑器,如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