I often keep a :terminal open on the right of a vertical split, and on the left keep a window open for files:

|              |             |
| file buffers | :terminal   |
|              |             |

When navigating through the terminal window in normal mode, I'd like to be able to type gf when the cursor is positioned over a file path and have it opened in the left window. Is anyone aware of a plugin or script that will allow this sort of thing? Even a snippet to get me started would be helpful. :)

Bonus: git diff shows file paths prefixed with a/ and b/. It would be great to somehow use gf on those as well, with the prefixes ignored:

diff --git a/dev/pricing_scenario_service/repl_core.clj b/dev/pricing_scenario_service/repl_core.clj


1 Answer 1


Here is what I would do:

If you leave terminal mode (Ctrl-\n) you can hit Ctrl-wv to duplicate the vertically the tab and hit gf to navigate to the file you would like.

Here is a sequence of key that could make the job:

  • Ctrl-\n Leave terminal mode
  • Ctrl-wv Create a vertical split that duplicate the buffer
  • Ctrl-wShift-h Move the created split to the extreme left
  • gf Open the corresponding file in the created buffer
  • Ctrl-wl Switch to the window that need to be closed
  • q Quit the window

In total: Ctrl-wvCtrl-wShift-hgfCtrl-wl:qEnter

You could create a mapping:

tnoremap gf <C-\><C-n><C-w>v<C-w>Hgf<C-w>l:q<CR>
nnoremap gf &buftype==#'terminal' ? "<C-w>v<C-w>Hgf<C-w>l:q<CR>" : 'gf'

The following answer Open filename under cursor like gf, but in a new tab (or split) gives interesting pointer.

  • 1
    Brilliant. The nnoremap line was messing with gf in non-terminal buffers, so I added a test for &buftype == 'terminal' in a separate function.
    – apostl3pol
    Dec 21, 2022 at 23:16
  • 1
    @apostl3pol Thanks for the feedback. I have integrated your idea into the solution. Dec 22, 2022 at 9:20
  • 1
    One more thing I noticed today is that the tnoremap command is executed whenever I type gd at the terminal prompt! I'm just omitting it because I really do only want it in normal mode.
    – apostl3pol
    Dec 23, 2022 at 20:34
  • 1
    I suppose you mean gf the only way I see is to make the key séquence more rare or to make it dependent of the context. Dec 23, 2022 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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