How do you return from 'gf' in Vim

前端 未结 11 1069
执念已碎
执念已碎 2020-12-12 09:23

I am using Vim for windows installed in Unix mode. Thanks to this site I now use the gf command to go to a file under the cursor.

I\'m looking for a com

相关标签:
11条回答
  • 2020-12-12 10:16

    When you open a new file (with gf or :n or another command) the old file remains in a buffer list. You can list open files with :ls

    If you want to navigate easily between buffers in vim, you can create a mapping like this:

    nmap <M-LEFT> :bN<cr>
    nmap <M-RIGHT> :bn<cr>
    

    Now you can switch between buffers with Alt + left arrow or Alt + right arrow.

    The complete documentation on mappings is here:

    :help map.txt
    
    0 讨论(0)
  • 2020-12-12 10:16

    I haven't looked at your gf command but I imagine it uses the :e or :find command.
    Assuming that this is correct, simply replace the :e or :find with :new (or :vnew for a vertical split) and the file will open in a new window instead of the same one.

    e.g.

    "Switch between header and cpp
    nmap ,s :find %:t:r.cpp<CR>
    nmap ,S :new %:t:r.cpp<CR>
    nmap ,h :find %:t:r.h<CR>
    nmap ,H :new %:t:r.h<CR>
    nmap ,F :new =expand("<cfile>:t")<CR><CR>
    nmap ,d :new =expand("<cfile>")<CR><CR> 
    

    0 讨论(0)
  • 2020-12-12 10:19

    I got CTRL-W f to work.
    It's quite depressing that I've spent so long perfecting maps for these commands only to discover that there are built-in versions.

    0 讨论(0)
  • 2020-12-12 10:23

    Use gf to descend into a file and use :bf to get back

    0 讨论(0)
  • 2020-12-12 10:26

    See :help alternate-file.

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