0

When I'm using the terminal feature on nvim sometimes I run the last command again out of habit (thinking that I'll re-run the unittests for what I'm coding at the moment or something), but the latest command in my shell's history is something like nvim path/to/my/project-folder

Naturally, what happens is It opens nvim inside of the nvim terminal. I've found it's fairly easy to exit from the inner nvim, but I was wondering if there's a better approach here.

Would it be advisable to just make vim exit when this happens? How would I do that?

3
  • Are you talking about using !! to run the last command? If so, get in the habit of using <Esc>k instead and you'll know what you're about to execute before you execute it. :) (This assumes you're using set -o vi.)
    – B Layer
    Nov 16 '21 at 17:11
  • Nah, I'm pressing the up arrow key in fish then hitting enter. I for sure see the command, but muscle memory is sometimes too fast for me to not hit enter first. Nov 16 '21 at 18:26
  • Can't help you with that problem. Try self-discipline. :D
    – B Layer
    Nov 16 '21 at 18:27
2

This little snippet of code works for me if I put it in my vimrc:

if exists('$VIMRUNNING') && ! has('gui_running')
    qall!
else
    let $VIMRUNNING = 1
endif

I included the check for gui_running so you can start gVim from inside a terminal, but not a console vim.

3
  • This works great. I tried adding echo "dummy! read before running!" before qall! but that was really just a shot in the dark... Would it be possible to echo to the term like what I imagined? Nov 16 '21 at 18:32
  • 2
    LOL. Don't be so hard on yourself.
    – B Layer
    Nov 16 '21 at 18:35
  • oh actually a sleep between echo and qall works great. Nov 16 '21 at 18:36

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.