How to effectively work with multiple files in Vim

前端 未结 28 2676
甜味超标
甜味超标 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:22

    I use the same .vimrc file for gVim and the command line Vim. I tend to use tabs in gVim and buffers in the command line Vim, so I have my .vimrc set up to make working with both of them easier:

    " Movement between tabs OR buffers
    nnoremap L :call MyNext()
    nnoremap H :call MyPrev()
    
    " MyNext() and MyPrev(): Movement between tabs OR buffers
    function! MyNext()
        if exists( '*tabpagenr' ) && tabpagenr('$') != 1
            " Tab support && tabs open
            normal gt
        else
            " No tab support, or no tabs open
            execute ":bnext"
        endif
    endfunction
    function! MyPrev()
        if exists( '*tabpagenr' ) && tabpagenr('$') != '1'
            " Tab support && tabs open
            normal gT
        else
            " No tab support, or no tabs open
            execute ":bprev"
        endif
    endfunction
    

    This clobbers the existing mappings for H and L, but it makes switching between files extremely fast and easy. Just hit H for next and L for previous; whether you're using tabs or buffers, you'll get the intended results.

提交回复
热议问题