vim, switching between files rapidly using vanilla Vim (no plugins)

后端 未结 7 2006
南旧
南旧 2020-11-30 16:14

I understand that limiting myself to vanilla Vim (not using plugins) limits the power of the editor, but as I switch between different machines frequently, it is often too m

相关标签:
7条回答
  • 2020-11-30 16:34

    The answer depends a lot on your preferences and circumstances. Some examples:

    • If it's mostly two files (e.g. a C header and implementation file), <C-^> is very handy. In general, the alternate file is an important concept.
    • If you use a large editor window, window :splits turn the problem of locating a buffer from locating the window (once you've got all buffers opened). You can use [N]<C-w><C-w> to quickly switch to it.
    • If you can memorize (a few) buffer numbers, the :[N]b[uffer] and :[N]sb[uffer] commands are quite handy; :ls tells you the numbers.

    Plugins (or at least custom mappings) can improve things a lot, and there's a whole variety on this topic on vim.org. There are various mechanisms to distribute your config (Pathogen + GitHub, Dropbox, ...), or you could remotely edit server files through the netrw plugin that ships with Vim.

    0 讨论(0)
  • 2020-11-30 16:35

    You can do wildcard tab completion on the command line without any plugins. e.g.

    :e src/**/foo*<tab>
    

    will let you cycle through all the files starting with 'foo' in the directory tree under ./src and select the one you want to edit.

    If you have already edited the file and it is still in a buffer then you can switch to it with:

    :b foo<tab>
    

    which will cycle through all the buffers with 'foo' in the path. You may need to set the wildmode and wildmenu options to get the behaviour you want. I have

    wildmode=longest:full
    wildmenu
    

    in my .vimrc.

    0 讨论(0)
  • 2020-11-30 16:39

    I had the same issue with Vim.

    The last thing I want is to depend on plugins for a task as mundane as file switching.

    I added the following lines to .vimrc

    set path+=**
    set wildmenu
    

    And BAM! I can now :find any/filename/in/any/folder/ as long as vim is in the root directory of the project. Tab completion works. Wildcards work!

    Once files are opened already, and there are a ton of buffers in the background (you could use :ls to see all buffers), running :b any/file <TAB> will fuzzy search for all buffers and jumps to the required file. In case it is not unique there will be a wildmenu of tabs (hence the 2nd line in .vimrc) which can be selected using tab.

    My answer is coming from this awesome video
    https://www.youtube.com/watch?v=XA2WjJbmmoM&feature=youtu.be&t=489
    There are more tricks in and I recommend watching it.

    0 讨论(0)
  • 2020-11-30 16:40

    If you are on a filename and want to jump to that file, gf will do it for you. I also like using ctags, which isn't a plugin; you just build the tags and can easily jump around your codebase.

    0 讨论(0)
  • 2020-11-30 16:41

    If you want switch between files in vim editor, please see below answer

    First press Esc key to exit from edit mode.

    Then type :e to check current file path.

    if you want to go another file then type :e /path-of-file.txt/ using this you are able to switch.

    If you want to go previous file simply type :e# which switch to previous file path.

    0 讨论(0)
  • 2020-11-30 16:44

    Sometimes it is also handy to go sequentially through a list of files (e.g., if you did something like vim *.php to open several files at once). Then you can use :n[ext] (as well as :prev[ious], :fir[st], and :la[st]) for navigation (in addition to what was suggested in the other answers).

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