1

(Originally asked in a wrong place - https://stackoverflow.com/questions/63780235/is-it-possible-to-view-the-current-file-content-during-directory-navigation-in-v)

I am watching this Pluralsight course on helm and the instructor uses vi from the linux console all the time in the directory browsing mode with the current file being automatically open for viewing in the other pane: enter image description here

When I run vi . it does open the directory navigation mode, but I have only one pane and to view a file I need to Enter it and then it shows it instead of the directory view. I can go back with :E, but the experience is not the same.

How can we tell vi to automatically open the current file in a side pane, so both the directory navigator and the file content are available in side by side panes?

I do not have any vi configuration. This is a fresh new Linux 18.04 VM to which I connect with ssh.

  • 1
    Not an answer, but you might want to give this a read: Article on project drawers – D. Ben Knoble Sep 8 at 15:05
  • 1
    @JakeGrossman the command is vi . (edit the current directory), which automatically opens netrw. It appears that while hovering in netrw, they get a side-panel with the file. – D. Ben Knoble Sep 8 at 15:06
  • I used vi .. I do not understand the meaning of "hovering" when working from the console. What I can see is that in the console mode there is no hovering. I can move the selection from file to file and enter folders. But to view a file I need to enter it and that opens the file content instead of the file browser. In short, the default out of the box experience is not the one I wish to have, The accepted answer moves me closer to the desired experience. – mark Sep 8 at 16:37
  • By hovering I meant using the cursor the “hover” (be on top of) a file in netrw. You said automatically, so I assumed no extra action was taken by the instructor. If they pressed v or p the screenshot would actually make more sense to me. I agree that out of box =/= what you described. – D. Ben Knoble Sep 8 at 17:26
  • It could be the instructor presses something. For now I assume he presses p as indicated by the answer. I find it quite confusing - Enter to enter a folder, but p to preview. I find myself often pressing Enter instead of p and then I have no idea how to return back to the file navigator - has to quit vi completely and restart. – mark Sep 8 at 18:06
0

(Originally answered on Stack Overflow.)

This is using the :Lexplore mode of netrw.

Either open it with :Lexplore from inside Vim, or if you want to start Vim with it open, use vim +Lexplore (instead of vim .), or vim +Lex for short.


If you prefer to use the "preview" feature, to open the file in the right window while keeping the cursor on the netrw window, then set the following variable:

" Open the preview window vertically.
let g:netrw_preview = 1

Then open netrw by itself with vim . or :e . and then use the p key to open the file in a "preview" window. The first time you use p will open the preview window.

You might want to also set:

let g:netrw_preview   = 1
let g:netrw_liststyle = 3
let g:netrw_winsize   = 30

See :help netrw-preview for details.

| improve this answer | |
  • What I still do not understand is when I Enter the file and the focus shifts to the other pane - how do I return back to the directory navigator pane? Right now I run the q command to close the file editor pane. I am still to try the preview commands. – mark Sep 8 at 16:49
  • Can I add +Lexplore to ~/.vimrc ? I tried adding Lexplore and +Lexplore and :Lexplore, but none is working. I know I need to RTFM, so if you point me in the right direction I guess I would manage. – mark Sep 8 at 17:02
  • @mark The vimrc file is loaded very early, before plug-ins. You need an autocmd instead, for that. This should work: autocmd VimEnter * Lexplore – filbranden Sep 8 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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