In Vim, is it possible to open a file in a window with an open section?
Lately I've been using Vim as my editor when programming Ruby, but I don't know if I can do it in Vim. Let's say, in my Vim, I already have two vertical split windows named A
and B
as follows:
And then I clicked gf
to go to the original file xyz.rb
if I put the cursor in the statement require
, but it will appear in the same window A
by default.
Are there any shortcuts or combos that I can open or show the original file xyz.rb
in the split window that opens B
? (and even if the window B
doesn't exist yet, create it automatically)
I checked the manual and it has several ways to show xyz.rb
in another horizontal split window or new tab, but is it possible if I want to show it in the open split window open B
.
thank:)
source to share
The functionality you are describing is already present in the form of a preview window.
You can map a key (for example gf) to something like
:exec 'pedit ' . expand('<cfile>')
This will open the file name under the cursor in the preview window. A new preview window will open if it doesn't exist. For details see . :he preview-window
Use ^W z(or :pclose
) to close the preview window
source to share