Search code examples
vimvi

Is it possible to view the current file content during directory navigation in vi (command line, not GUI)?


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.


Solution

  • 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.