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?

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

1 Answers1

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.

Heptite
  • 1,046
  • 6
  • 14
  • 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? – Lazerbeak12345 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. – Lazerbeak12345 Nov 16 '21 at 18:36
  • I've devised this ingenious /bin/sh script to do something simmilar for another purpose... I wonder if this could be repurposed as a different answer to this question? [ $(ps -jh | grep vim | wc -l) -gt 1 ] – Lazerbeak12345 Jan 28 '22 at 20:15
  • More concise and faster, if you're using Bash or zsh: [[ $(ps -C vim -o pid h) ]] – Heptite Jan 29 '22 at 20:20