How to effectively work with multiple files in Vim

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

    Most of the answers in this thread are using plain vim commands which is of course fine but I thought I would provide an extensive answer using a combination of plugins and functions that I find particularly useful (at least some of these tips came from Gary Bernhardt's file navigation tips):

    1. To toggle between the last two file just press twice. I recommend assigning to the spacebar:

      nnoremap  
      
    2. For quickly moving around a project the answer is a fuzzy matching solution such as CtrlP. I bind it to a for quick access.

    3. In the case I want to see a visual representation of the currently open buffers I use the BufExplorer plugin. Simple but effective.

    4. If I want to browse around the file system I would use the command line or an external utility (Quicklsilver, Afred etc.) but to look at the current project structure NERD Tree is a classic. Do not use this though in the place of 2 as your main file finding method. It will really slow you down. I use the binding ff.

    These should be enough for finding and opening files. From there of course use horizontal and vertical splits. Concerning splits I find these functions particularly useful:

    1. Open new splits in smaller areas when there is not enough room and expand them on navigation. Refer here for comments on what these do exactly:

      set winwidth=84
      set winheight=5
      set winminheight=5
      set winheight=999
      
      nnoremap v :111vs
      nnoremap s :rightbelow split
      set splitright
      
    2. Move from split to split easily:

      nnoremap  
      nnoremap  
      nnoremap  
      nnoremap  
      

提交回复
热议问题