vimtricks.wiki Concise Vim tricks, one at a time.

How do I open a file in Netrw in a vertical split instead of the current window?

Answer

v (netrw)

Explanation

When browsing files in Vim's built-in file manager (Netrw), pressing v on any file opens it in a vertical split to the right. Netrw offers a full set of single-key shortcuts for controlling how files are opened — knowing them eliminates the need to manually type :vs {filename} after navigating to a file.

How it works

With the cursor on a file or directory entry in Netrw:

  • <CR> or l — open in the current window
  • o — open in a horizontal split
  • v — open in a vertical split
  • t — open in a new tab
  • p — open in the preview window (:pedit)

These shortcuts work in all Netrw views (:Explore, :Vexplore, :Sexplore, :Texplore).

Example

You open Netrw with :Explore and see:

  " ============================================================
  " Netrw Directory Listing
  " ============================================================
   ../
   src/
   README.md
   main.go

Navigate to main.go and press v. The layout becomes:

[Netrw]  │  main.go

Tips

  • Set let g:netrw_altv = 1 in your vimrc to make v open splits on the right side (default is left)
  • Set let g:netrw_preview = 1 to make p open previews vertically instead of horizontally
  • Combine with :Lexplore (left-side explorer) and v to create a two-panel layout without any plugins
  • See :help netrw-v for the full reference

Next

How do I read from and write to files directly in Vimscript without shelling out to external commands?