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

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

vi main.pl maintenance.pl

然后在他们之间跳来跳去

:n
:prev

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

:args

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

:n test.pl

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

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


当前回答

这里有很多答案!我不用重新发明轮子——最著名的插件(不会很快消亡,被很多人使用)是超快和极客的。

ctrlpvim / ctrlp。Vim -查找文件的名称模糊搜索的位置或只是它的名称 jlanzarotta/bufexplorer -用来浏览打开的缓冲区(当你不记得最近打开和修改了多少文件,也不记得它们在哪里时,可能是因为你用Ag搜索了它们) rk / ag)。Vim搜索关于gitignore的文件 Scrooloose /nerdtree查看目录结构,查找,添加/删除/修改文件

编辑:最近我一直在使用dyng/ctrlsf。vim搜索上下文视图(像Sublime搜索),我把引擎从ag切换到ripgrep。演出非常出色。

EDIT2:与CtrlSF一起,您可以使用mg979/vim-visual-multi,一次更改多个文件,然后在最后一次保存它们。

其他回答

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

使用,

: e file_name.extension

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

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

我们使用

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

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

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

有一个尝试以下地图方便编辑多个文件

“分割窗口”

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

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

您可能希望使用Vim全局标记。

通过这种方式,您可以快速地在文件之间来回切换,甚至跳转到文件中标记的位置。此外,关键命令也很短: C会带我找到我正在处理的代码, T把我带到了我正在使用的单元测试。

当你改变位置时,重置标记也很快: mC标记新的代码点, mT标志着新的测试点。

To open 2 or more files with vim type: vim -p file1 file2 After that command to go threw that files you can use CTRL+Shift+↑ or ↓ , it will change your files in vim. If u want to add one more file vim and work on it use: :tabnew file3 Also u can use which will not create a new tab and will open file on screen slicing your screen: :new file3 If u want to use a plugin that will help u work with directories and files i suggest u NERDTree. To download it u need to have vim-plug so to download other plugins also NERDTree to type this commands in your ~/.vimrc.

    let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
    if empty(glob(data_dir . '/autoload/plug.vim'))
      silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs 
      https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
      autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
    endif

    call plug#begin('~/.vim/plugged')
    Plug 'scrooloose/nerdtree'
    call plug#end()

然后通过命令:wq保存.vimrc,返回并输入::PlugInstall

之后,插件将被安装,你可以使用你的NERDTree与其他插件。