0

I am trying to close the terminal window directly from vim.

The final purpose of this is to have a command (shortcut) that opens VSCode in the current directory from vim (when I need a GUI editor) and closes my terminal window.

8
  • Hi Welcome to Vim. Would be nice if you could explain us what you did try and why it doesn't work the way you want Apr 17 at 5:58
  • 1
    @VivianDeSmedt I actually did not find any way to do it, so for the moment I haven't try a solution yet, I am looking for one
    – gruvw
    Apr 17 at 9:51
  • so :exit in the terminal prompt does not close your :terminal window? Apr 17 at 15:52
  • Maybe you just want to start VsCode with :!code and skip the utilisation of the terminal. Apr 17 at 16:21
  • 1
    Do I understand correctly, that you want to have vim and the terminal in which it runs also closed? In that case, you need to use manually quit Vim first and then close the terminal. Apr 17 at 20:51

1 Answer 1

0

I propose to:

  • Start vim using a script.

  • Launch VsCode using: On Windows I propose you to use:

    :execute '!start code "%:p:h"' | cquit 2

    or on Linux:

    :execute '!code "%:p:h" &' | cquit 2

  • Detect the return code 2 in the script that launch vim to kill the parent terminal.

6
  • 1
    First of all, I am on Linux. Second, there seems to be a misunderstanding of the question: I am looking for a way to close the terminal running vim, the VSCode part is just to give some context. I know I can write :!code . to open VSCode but I need the terminal running vim to close after opening VSCode (or after executing any other command)
    – gruvw
    Apr 17 at 20:04
  • 1
    You want a command that: 1. start VsCode , 2. close vim and 3. close the terminal that started vim. Do I have the correct understanding? Apr 17 at 20:23
  • 1
    Yes, however, your current solution does not close the terminal (step 3). And as I already said, I just need a way to close the terminal window running vim from within vim. Drop the VSCode part, it was just to give some context.
    – gruvw
    Apr 18 at 5:10
  • I see no ways in Vim. I would be you I would starts vim with a script, use cquit instead of qall to quit vim and detect the return code in the script to kill the parent terminal. Apr 18 at 5:33
  • Yes I thought about that but the issue is that I don't know when I start vim if I will want to start VSCode later on... The rest of the time I don't want vim to close the terminal when I exit. Is there a way to pass some data to the bash script that launched vim ? Then the shell script could know when to exit the terminal after hearing back from vim and when not to.
    – gruvw
    Apr 18 at 9:22

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.