Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

According to "Practical Vim" and the Vim help the shortcut <C-^> is supposed to return me to the edited file. I enter netrw using :E.

As an experiment I tried remapping the default shortcut as follows:

:nnoremap <C-y> <C-^>

Once I use <C-y> I get feedback:

E23: No alternate file

... but I don't get back to the edited buffer.

How can I return to the edited buffer, or for that matter, how can I debug this issue to find out what prevents me from returning to it according to the documented procedure?

NB: I am setting the mapping on the command prompt, not in .vimrc.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

The alternate file is, practically speaking, the buffer that was open previously in the same window:

:e file1
:e file2
<C-^> shows file1
<C-^> shows file2
<C-^> shows file1
…

<C-^> is used to toggle quickly between two buffers in the same window.

You may not have an "alternate file" to jump to (probably a netrw thing which doesn't really makes sense to me) and <C-^> is of no use here.

Instead, use :bd which deletes the current buffer (netrw) and puts you back in the previous buffer. Note that you can use :Rex to get back the latest netrw window at any time.

If you don't open files (you use netrw to look around for some kind of info), your workflow could be:

:Ex
(exploration)
:bd
if you want to start a new exploration,
    :Ex
    :bd
if you want to explore from where you were,
    :Rex
    :bd

However, you should read :h netrw because it has more commands that would probably help you a lot: :Hex[plore] (opens netrw in an horizontally split window), :Vex[plore] (opens netrw in a vertically split window), :Tex[plore] (opens netrw in a new tab)… These commands will let you go on your safari while keeping some "state".

As an alternative, <C-o> and <C-i> are two handy shortcuts that let you go up and down the jumplist. In your situation, <C-o> may be the quickest way to get back to the previous buffer.

share|improve this answer
1  
excellent answer. :bd is exactly what I was looking for in this case. The other commands are nice in a big window. Since I use tmux to split my workspace, the screen estate Vim gets is actually rather small. –  0xC0000022L Feb 16 '13 at 17:14
add comment

I don't see how the mapping has anything to do with the E23; you should get the same error with the original <C-^> command. Probably, no alternate file has been set yet; some plugins also explicitly use the :keepalt command to avoid recording the buffer change.

You can check the alternate file name via

:echo expand('#')

or, in the output of :ls, look for the line that has a # sigil.

share|improve this answer
    
thanks for taking the time to answer. Alas, it's not helpful. When I use :ls I see the edited file while in netrw listed with #. However, that doesn't allow me to jump back - which is the essence of my question. I tried the remapping mostly because ^ is "harder" to synthesize on an US-English keyboard that a plain letter. –  0xC0000022L Feb 16 '13 at 17:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.