Changing the practice of quiting and opening vi (vim) editor?

后端 未结 5 682
灰色年华
灰色年华 2021-02-11 07:05

One of the primary distinction betweeen vi (vim) and emacs, is emacs is designed and supposed to be run at times without quitting, where as given the quick load time of vim, it

相关标签:
5条回答
  • 2021-02-11 07:08

    So you're running one file Vim per screen session? That sounds pretty bad man. You don't really need any special plugins to use multiple files in Vim easily. Just do

    :e /home/project/myfile.py
    

    I have set autochdir in my .vimrc which automatically changes current working directory to whatever buffer is currently active. So once you have that file open you can just do

    :e myfile2.py
    :e myfile3.py
    

    etc. BTW opening any files in Vim can be completed with tab completion so make sure you are doing that. Once you have a bunch of buffers open to switch between I just do

    :b myfile1.py
    

    which you can also use tab completion for you can just type :b 1 and hit tab and it will figure out you want myfile1.py open so it is super quick if you can remember the general file name and if there is more than one similar match it will give you a list that you can tab through. For that I would also advise taking a look at the wildmode and wildmenu settings to see what you prefer they will give you enhanced tab completion menus. If at any time you start getting lost with what buffers are open and what you want to look at you can just do

    :ls
    

    and it will show you everything open.

    Also remember you can run external commands by preceding a command with !

    :!ls
    

    for example. Hope some of this helps or at least gets you looking in the right direction.

    0 讨论(0)
  • 2021-02-11 07:09

    You can even drop down to a shell using :sh, and then get back to Vim using exit in the shell. For editing multiple files in the same Vim, you can use :vsplit filename or :split filename (for vertical and horizontal splits), and then use Esc+Ctrl+w+arrow keys to navigate between the different splits. This way you don't need tabs. Works especially well if you're working with small pieces of code.

    0 讨论(0)
  • 2021-02-11 07:15

    Here's good video tutorial that helps with workflow of how and why to use a single Vim session to manage all your edits:

    http://www.derekwyatt.org/vim/vim-tutorial-videos/vim-intermediate-tutorial-videos/#onevim

    0 讨论(0)
  • 2021-02-11 07:16

    Just use the :! command to run stuff in a shell. It mixes great with :cd and % expansion

    bash> vim path/to/ex.c
    ...
    :cd %:h. " move to path/ex/
    :!gcc -o %:r % && %:r " compile ex.c into ex and run it
    

    You can also mix it with :read if you want to put the output of a command in the current buffer:

    :read !ls " read in the names of all the files in the current directory
    
    0 讨论(0)
  • 2021-02-11 07:20

    Everything the others said plus three:

    • With set hidden you can open a new buffer in place of the current one, even if it's not saved. You can open dozens of buffers like that, no need to close Vim! See :help windows or the Vim wiki.

    • Supposing Vim is compiled with the correct flag (+clientserver) you can have a single Vim running as a "server" (in a terminal window A) and open all your files in that single Vim (from terminal window B). It's done in two steps:

      1. $ vim --servername WHATEVER to start Vim
      2. $ vim --remote file.js to open a file

      Your file is opened in Vim in terminal window A and you still have your prompt in terminal window B.

    • Don't touch tabs. They are terribly wrongly named and don't work like tabs at all.

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