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

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

vi main.pl maintenance.pl

然后在他们之间跳来跳去

:n
:prev

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

:args

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

:n test.pl

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

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


当前回答

这个帖子中的大多数答案都是使用普通的vim命令,这当然很好,但我认为我将使用我认为特别有用的插件和函数的组合来提供一个广泛的答案(至少其中一些技巧来自Gary Bernhardt的文件导航技巧):

To toggle between the last two file just press <leader> twice. I recommend assigning <leader> to the spacebar: nnoremap <leader><leader> <c-^> For quickly moving around a project the answer is a fuzzy matching solution such as CtrlP. I bind it to <leader>a for quick access. In the case I want to see a visual representation of the currently open buffers I use the BufExplorer plugin. Simple but effective. If I want to browse around the file system I would use the command line or an external utility (Quicklsilver, Afred etc.) but to look at the current project structure NERD Tree is a classic. Do not use this though in the place of 2 as your main file finding method. It will really slow you down. I use the binding <leader>ff.

这些应该足够查找和打开文件了。从那里当然使用水平和垂直分割。关于分割,我发现这些函数特别有用:

当没有足够的空间时,在较小的区域打开新的裂缝,并在导航时扩展它们。参考这里的评论,这些具体做什么: 设置winwidth = 84 设置winheight = 5 设置winminheight = 5 设置winheight = 999 nnoremap <C-w>v:111vs<CR> nnoremap <C-w>s:rightbelow split<CR> 设置splitright 轻松地从一个分裂到另一个分裂: nnoremap <C-J> <C-W><C-J> nnoremap <C-K> <C-W><C-K> nnoremap <C-L> <C-W><C-L> nnoremap <C-H> <C-W><C-H>

其他回答

我建议使用插件

书树

这里是github链接的说明。

书树

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

我来-plug

冯德尔

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

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

alias vim="vim -p"

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

在我和其他许多vim用户中,最好的选择是,

使用,

: e file_name.extension

然后按Ctrl + 6切换到最后一个缓冲区。或者,你可以一直按

:ls列出缓冲区,然后使用b后跟缓冲区编号更改缓冲区。

我们使用

:vsp表示垂直分割 :sp:水平拆分

然后<C-W><C-H/K/L/j>来改变工作分割。

当然,您可以在任意数量的分割中编辑任何文件。

添加到args列表:

:argadd

从args列表中删除:

:argdelete

在您的示例中,您可以使用:argedit test.pl将test.pl添加到args列表中,并一步编辑该文件。

:帮助参数提供了更多的细节和高级用法