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 Commented Apr 17, 2022 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
    Commented Apr 17, 2022 at 9:51
  • so :exit in the terminal prompt does not close your :terminal window? Commented Apr 17, 2022 at 15:52
  • Maybe you just want to start VsCode with :!code and skip the utilisation of the terminal. Commented Apr 17, 2022 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. Commented Apr 17, 2022 at 20:51

1 Answer 1

1

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
    Commented Apr 17, 2022 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? Commented Apr 17, 2022 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
    Commented Apr 18, 2022 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. Commented Apr 18, 2022 at 5:33
  • 1
    That is why I propose :cquit instead of :qall. The first make vim returns a non zero code and the later a zero code that can be leveraged. Commented Apr 18, 2022 at 11:36

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.