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

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

vi main.pl maintenance.pl

然后在他们之间跳来跳去

:n
:prev

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

:args

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

:n test.pl

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

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


当前回答

如果你要使用多个缓冲区,我认为最重要的事情是 设置隐藏 这样它就能让你切换缓冲区即使你要离开的缓冲区中有未保存的更改。

其他回答

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

这个帖子中的大多数答案都是使用普通的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>

为什么不使用标签(在Vim 7中引入)? 你可以用:tabn和:tabp在选项卡之间切换, 使用:table <filepath>您可以添加一个新选项卡;使用常规的:q或:wq关闭一个选项卡。 如果你映射:tabn和:tabp到你的F7/F8键,你可以很容易地在文件之间切换。

如果没有那么多文件或者你没有Vim 7,你也可以把你的屏幕分成多个文件::sp <filepath>。然后你可以用Ctrl+W和方向键在你想要移动的方向上切换分屏(或者代替方向键,W代表下一个和W代表上一个分屏)

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

我使用了多个隐藏在~/中的缓冲区。vimrc文件。

迷你缓冲区资源管理器脚本也很好,可以获得缓冲区的紧凑列表。然后:b1或:b2…要转到适当的缓冲区或使用迷你缓冲区资源管理器并通过缓冲区使用TAB。