我已经开始使用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列表中添加和删除文件?
当前回答
为什么不使用标签(在Vim 7中引入)? 你可以用:tabn和:tabp在选项卡之间切换, 使用:table <filepath>您可以添加一个新选项卡;使用常规的:q或:wq关闭一个选项卡。 如果你映射:tabn和:tabp到你的F7/F8键,你可以很容易地在文件之间切换。
如果没有那么多文件或者你没有Vim 7,你也可以把你的屏幕分成多个文件::sp <filepath>。然后你可以用Ctrl+W和方向键在你想要移动的方向上切换分屏(或者代替方向键,W代表下一个和W代表上一个分屏)
其他回答
你可以在你的.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>来改变工作分割。
当然,您可以在任意数量的分割中编辑任何文件。
我使用以下,这给了你很多功能,你会期望在其他编辑器,如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
When I started using VIM I didn't realize that tabs were supposed to be used as different window layouts, and buffer serves the role for multiple file editing / switching between each other. Actually in the beginning tabs are not even there before v7.0 and I just opened one VIM inside a terminal tab (I was using gnome-terminal at the moment), and switch between tabs using alt+numbers, since I thought using commands like :buffers, :bn and :bp were too much for me. When VIM 7.0 was released I find it's easier to manager a lot of files and switched to it, but recently I just realized that buffers should always be the way to go, unless one thing: you need to configure it to make it works right.
所以我尝试了vim-airline,并启用了可视的顶部选项卡式缓冲条,但图形与我的iTerm2有问题,所以我尝试了其他几个,似乎MBE最适合我。我还设置shift+h/l作为快捷键,因为原来的那些(移动到当前页面的头部/尾部)对我来说不是很有用。 map <S-h>:bprev<返回> map <S-l>:bnext<返回>
它似乎比gt和gt更简单,而且:e也比:tabnew更简单。我发现:bd不像:q那样方便,虽然(MBE有一些问题),但我可以在缓冲区中使用所有文件。
有一个尝试以下地图方便编辑多个文件
“分割窗口”
nmap <leader>sh:leftabove vnew<CR>
nmap <leader>sl: vnew<CR>
nmap <leader>sk:leftabove new<CR>
nmap <leader>sj:rightbelow new<CR>
“四处走动
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
nmap <C-h> <C-w>h