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.

If I open Vim's file explorer to the current directory, I can open a file using the o key in a new window. I change focus between the opened file and the file listing using CTRL-w w key sequence. So far, so good.

However, if I change focus to the file explorer and open another file using the o key, this happens: a new window showing the file listing is created, and the window showing the previously opened file is focussed. I cannot switch to either of the file listing windows with CTRL-w w key sequence. Why does this happen?

How can I open a second file in a new window, and how can I move the cursor between the different windows?

share|improve this question
    
Which Vim and netrw versions? Did you try the latest available version?! –  Ingo Karkat Feb 14 '13 at 11:45
    
@IngoKarkat: 2:7.3.547-4ubuntu1.1 and netrw v145. I'll try upgrading because it looks like a bug or a configuration mistake. –  Flimm Feb 14 '13 at 13:11
    
Upgrading vim to 7.3 patches 1-816 and netrw to v146 solved this. Looks like a bug. –  Flimm Feb 14 '13 at 13:51
    
Ah, great! I've added a proper answer for you to accept. –  Ingo Karkat Feb 14 '13 at 14:00
add comment

2 Answers 2

up vote 1 down vote accepted

When encountering "strange" behavior like this, two things are important:

  1. Try to minimize other influences; i.e. temporarily disable other plugins and irrelevant configuration in your ~/.vimrc
  2. It may be a bug; upgrade to the latest available versions of Vim (depending on your platform) and the plugin (the latest netrw version can be found here).
  3. If you can't possibly upgrade, at least locate and search the change log / issue tracker / mailing list; there may be hints about the problem.
share|improve this answer
add comment

Starting with a blank slate (* shows focus)…

+------------------------------+
| *                            |
|                              |
|                              |
|                              |
|                              |
|                              |
|                              |
|                              |
+------------------------------+
  1. :Ex should replace the currently empty buffer with the netrw listing:

    +------------------------------+
    | * netrw                      |
    |                              |
    |                              |
    |                              |
    |                              |
    |                              |
    |                              |
    |                              |
    +------------------------------+
    
  2. Hitting o should open the selected file in a new horizontally split window and give it focus:

    +------------------------------+
    | * file 1                     |
    |                              |
    |                              |
    |                              |
    +------------------------------+
    | netrw                        |
    |                              |
    |                              |
    +------------------------------+
    
  3. The mapping for going back to the previous window (whatever and wherever it is) is <C-w>p. At this point, using this shortcut should give focus to the netrw listing:

    +------------------------------+
    | file 1                       |
    |                              |
    |                              |
    |                              |
    +------------------------------+
    | * netrw                      |
    |                              |
    |                              |
    +------------------------------+
    
  4. Choosing a new file and hitting o should open it in a second horizontally split window (located right above the netrw window, between it and the window of the first file) and give it focus:

    +------------------------------+
    | file 1                       |
    |                              |
    +------------------------------+
    | * file 2                     |
    |                              |
    +------------------------------+
    | netrw                        |
    |                              |
    +------------------------------+
    
  5. At this point, you can go back to the netrw listing with <C-w>p or cycle through your windows with <C-w>w (forward) or <C-w>W (backward) or use <C-w>hjkl or read :h window-move-cursor.

share|improve this answer
    
This is useful but doesn't solve my problem. At step 4, I get three windows, file1, netrw and netrw in that order. <C-w>p allows me to focus on the third window, but I can't focus on the second one with <C-w>w, <C-w>W, or <C-w>p. –  Flimm Feb 14 '13 at 13:09
    
This shouldn't happen if you hit o over a file. What you describe sounds like you've hit o over a directory. Do you use a plugin distribution or do you manage your config yourself? Could you show us your ~/.vimrc? –  romainl Feb 14 '13 at 13:19
    
I get this problem even when I delete ~/.vimrc and ~/.vim. Upgrading vim fixed it though. –  Flimm Feb 14 '13 at 13:52
    
+1 for the effort and nice ASCII-art! –  Ingo Karkat Feb 14 '13 at 14:00
    
Thanks Ingo. It's so easy to draw ASCII tables with Vim… it makes you want to use them everywhere! –  romainl Feb 14 '13 at 14:06
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.