我已经开始使用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

其他回答

添加到args列表:

:argadd

从args列表中删除:

:argdelete

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

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

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

“分割窗口”

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中使用多个文件时,我主要使用这些命令(打开了大约350个文件):

:b <partial filename><tab>(跳转到缓冲区) :bw(缓冲区擦除,删除缓冲区) :e <文件路径>(编辑,打开一个新的缓冲区> . Pltags -允许跳转到子例程/方法定义

我认为您在查看已打开的文件列表时可能使用了错误的命令。

尝试执行一个: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寄存器,其中包含你已经删除的内容。如果您想重新使用以前删除的文本,这尤其有用。

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与其他插件。