我已经开始使用Vim来开发Perl脚本,并开始发现它非常强大。
我喜欢的一件事是能够同时打开多个文件:
vi main.pl maintenance.pl
然后在他们之间跳来跳去
:n
:prev
然后查看哪个文件是打开的:
:args
要添加一个文件,我可以说:
:n test.pl
我希望它会被添加到我的文件列表中,但相反,它会清除我当前的文件列表,当我输入:args时,我只有test.pl打开。
那么我如何在我的args列表中添加和删除文件?
我已经开始使用Vim来开发Perl脚本,并开始发现它非常强大。
我喜欢的一件事是能够同时打开多个文件:
vi main.pl maintenance.pl
然后在他们之间跳来跳去
:n
:prev
然后查看哪个文件是打开的:
:args
要添加一个文件,我可以说:
:n test.pl
我希望它会被添加到我的文件列表中,但相反,它会清除我当前的文件列表,当我输入:args时,我只有test.pl打开。
那么我如何在我的args列表中添加和删除文件?
当前回答
我使用以下,这给了你很多功能,你会期望在其他编辑器,如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
其他回答
清单
要查看当前缓冲区的列表,我使用:
:ls
开放
要打开一个新文件,我使用
:e ../myFile.pl
增强的TAB补全功能(将set wildmenu放在你的.vimrc中)。
注意:你也可以使用:find,它会为你搜索一组路径,但是你需要先自定义这些路径。
切换
要在所有打开的文件之间切换,我使用
:b myfile
增强选项卡完成(仍然设置野生菜单)。
注意::b#选择最后访问的文件,因此您可以使用它在两个文件之间快速切换。
使用windows
Ctrl-W s和Ctrl-W v水平和垂直分割当前窗口。你也可以使用:split和:vertical split (:sp和:vs)
Ctrl-W w在打开的窗口之间切换,Ctrl-W h(或j或k或l)在打开的窗口中导航。
按Ctrl-W c关闭当前窗口,按Ctrl-W o关闭除当前窗口外的所有窗口。
使用-o或-o标志启动vim将打开每个文件各自的分割。
有了所有这些,我不需要在Vim中使用标签,我的手指可以找到缓冲区,而不是眼睛。
注意:如果您希望所有文件都转到同一个Vim实例,请使用——remote-silent选项启动Vim。
将所有缓冲区更改为选项卡视图。
: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
我使用了多个隐藏在~/中的缓冲区。vimrc文件。
迷你缓冲区资源管理器脚本也很好,可以获得缓冲区的紧凑列表。然后:b1或:b2…要转到适当的缓冲区或使用迷你缓冲区资源管理器并通过缓冲区使用TAB。
我认为您在查看已打开的文件列表时可能使用了错误的命令。
尝试执行一个: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寄存器,其中包含你已经删除的内容。如果您想重新使用以前删除的文本,这尤其有用。
我做了一个非常简单的视频来展示我使用的工作流程。基本上我使用Ctrl-P Vim插件,并将缓冲区导航映射到Enter键。
通过这种方式,我可以在普通模式下按Enter,查看打开的文件列表(在屏幕底部的一个小新窗口中显示),选择我想编辑的文件并再次按Enter。要快速搜索多个打开的文件,只需输入部分文件名,选择文件并按Enter。
视频中打开的文件不多,但当你开始有很多文件时,它会变得非常有用。
由于插件使用MRU顺序对缓冲区进行排序,您只需按两次Enter键就可以跳转到您正在编辑的最新文件。
插件安装完成后,你唯一需要做的配置是:
nmap <CR> :CtrlPBuffer<CR>
当然,您可以将它映射到不同的键,但我发现要输入的映射非常方便。