How to effectively work with multiple files in Vim

前端 未结 28 2656
甜味超标
甜味超标 2020-11-28 00:18

I\'ve started using Vim to develop Perl scripts and am starting to find it very powerful.

One thing I like is to be able to open multiple files at once with:

<
相关标签:
28条回答
  • 2020-11-28 00:34

    When using multiple files in vim, I use these commands mostly (with ~350 files open):

    • :b <partial filename><tab> (jump to a buffer)
    • :bw (buffer wipe, remove a buffer)
    • :e <file path> (edit, open a new buffer>
    • pltags - enable jumping to subroutine/method definitions
    0 讨论(0)
  • 2020-11-28 00:35
    :ls
    

    for list of open buffers

    • :bp previous buffer
    • :bn next buffer
    • :bn (n a number) move to n'th buffer
    • :b <filename-part> with tab-key providing auto-completion (awesome !!)

    In some versions of vim, bn and bp are actually bnext and bprevious respectively. Tab auto-complete is helpful in this case.

    Or when you are in normal mode, use ^ to switch to the last file you were working on.

    Plus, you can save sessions of vim

    :mksession! ~/today.ses
    

    The above command saves the current open file buffers and settings to ~/today.ses. You can load that session by using

    vim -S ~/today.ses
    

    No hassle remembering where you left off yesterday. ;)

    0 讨论(0)
  • 2020-11-28 00:37

    Things like :e and :badd will only accept ONE argument, therefore the following will fail

    :e foo.txt bar.txt
    :e /foo/bar/*.txt
    :badd /foo/bar/*
    

    If you want to add multiple files from within vim, use arga[dd]

    :arga foo.txt bar.txt
    :arga /foo/bar/*.txt
    :argadd /foo/bar/*
    
    0 讨论(0)
  • 2020-11-28 00:37

    If you are going to use multiple buffers, I think the most important thing is to set hidden so that it will let you switch buffers even if you have unsaved changes in the one you are leaving.

    0 讨论(0)
  • 2020-11-28 00:37

    I would suggest using the plugin

    NERDtree

    Here is the github link with instructions.

    Nerdtree

    I use vim-plug as a plugin manager, but you can use Vundle as well.

    vim-plug

    Vundle

    0 讨论(0)
  • 2020-11-28 00:39

    You can be an absolute madman and alias vim to vim -p by adding in your .bashrc:

    alias vim="vim -p"

    This will result in opening multiple files from the shell in tabs, without having to invoke :tab ball from within vim afterwards.

    0 讨论(0)
提交回复
热议问题