In Vim, how to jump between two files

I need to jump back and forth between two files in Vim.

I can do this manually as :e file1.txt , followed by :e file2.txt . Is there a shortcut to go directly to a previously opened file?

Note. I do not want to open two files in split windows or multiple tabs.

I am looking for something like [ctrl + o] , only the jump should be in the previous file, not in the previous location in the same file

thanks for any tips

+6
source share
7 answers

Use <C-^> or <C-6> .

From :h ctrl-^ :

 Edit the alternate file. Mostly the alternate file is the previously edited file. This is a quick way to toggle between two files. It is equivalent to ":e #", except that it also works when there is no file name. If the 'autowrite' or 'autowriteall' option is on and the buffer was changed, write it. Mostly the ^ character is positioned on the 6 key, pressing CTRL and 6 then gets you what we call CTRL-^. But on some non-US keyboards CTRL-^ is produced in another way. 
+8
source

I'm not sure I understand correctly, but only with two open files is it possible that buffer next :bn will be enough?

+6
source

To really switch between the two files, use :b# : this is more convenient if you have more than two files open.

Say you downloaded file1 , file2 , file3 and want to flip between 2 and 3 :

  • :b file2 opens file2
  • :b file3 opens file3
  • now :b# switches from 3 to 2 and vice versa.

In this situation :bn will go through 1, 2, 3, 1, 2, 3, ...

+5
source

This is a file and buffer management topic. You can check the relevant documents. I come up with some commands that may interest you:

CTRL+^ : go to the last edited file in the same window.

gf : go to the file if you can find the link under the cursor.

:bn :bp : skip to the next or previous buffer.

:n :n : skip to the next or previous arg file.

And there is a plugin called unimpaired that will make you happier!

If you want to go to the file as you like:

:b partial_word , then press Tab , you will get automatic completion.

:ls , then :b a_number to go to this buffer.

Some plugins, such as bufexplorer, nerdtree, are very useful. But in this situation, you can consider CtrlP , which very quickly look for all the files!

+3
source

I do not know the best solution, but one of the possible is simply to follow these steps:

 :e file1.txt :e file2.txt : <commands commands> :e <UP_ARROW> / <DOWN_ARROW> to switch between the files 

This is not what you requested, but uses the autocomplete function.

+2
source

If I understand your question correctly, this is :e#

+2
source

I use: bn to go to the next open file, but since I'm lazy, I remap N, so all I need to do is shift-n ... really fast!

(Bonus question: why is it Z? A: This is a transfer from my SCO days when I would have a thick finger ctrl-z and pop vi to a background task ... I have to delete it, but the memories ...)

This is my gvimrc, which is used to configure Vim on every Windows box I work in:

"custom gvimrc" The commands in this are executed when the GUI starts. "slc 05/05/2013 - by default (usually c: \ program files \ Vim)

set the ruler

set tabstop = 3

set shiftwidth = 3

set expandtab

install nobackup

set backupdir = C: \ Windows \ Temp

set dir = C: \ Windows \ Temp

colorschem torte

install nohlsearch

map N: bn

map ZZ: xa

map ^ Z: No jobs ... NOT used in Vim ...

syntax

0
source

Source: https://habr.com/ru/post/947016/


All Articles