1

Since I have a terminal inside vim I can't do :wq or I get 'job' running.

I got around this using:

vim --clean "+term" "+qa!"

Then I'd have to do :w then :qa!

In my ~/.vimrc I then done this map:

command Q qa!

So now I do :w then :Q

I'd like to do: :wq or at least have a map for it.

I tried mapping: command Q wqa! but got 'job running'; I couldn't exit because of the terminal.

It's not possible to do vim --clean "+term" "+wqa!

Question

Is there a way I can exit vim with terminal inside using :wq or a map of it?

It's a minor inconvenience to do :w then :Q, help is appreciated.

4
  • Some helpful ideas: :help E947, :help :term and look at ++kill and the last few paragraphs between :help :term and :help terminal-close, :help terminal-typing and use C-w C-\ (which usually sends sigquit)
    – D. Ben Knoble
    Jun 28, 2023 at 15:07
  • thank you, could you write an answer so I cam give credit? I'll try this.
    – Nickotine
    Jun 28, 2023 at 15:31
  • Tried to do :term_setkill={SIGKILL} but I get 'executing job failed: no such file or directory'
    – Nickotine
    Jun 28, 2023 at 15:52
  • :term_setkill()={SIGKILL}
    – Nickotine
    Jun 28, 2023 at 16:14

2 Answers 2

2

I got what I wanted by doing:

:w|:Q

For context Q is a command in my ~/.vimrc:

command Q qa!


All the steps to write and exit vim with terminal inside:

On terminal:

vim --clean "+term" "+qa!"

In ~/.vimrc:

command Wq w|qa!

Then you can write and exit vim with terminal running inside:

:Wq

1

I would do:

function! CorrectCmd()
  if getcmdtype() != ':'
    echo 'foo'
    return "\<CR>"
  endif

  if matchstr(getcmdline(), '^wq\%[all]!\?\>') == ''
    return "\<CR>"
  endif

  return "\<C-u>" . 'w|qa' . "\<CR>"
endfunction
cnoremap <expr> <CR> CorrectCmd()

The command mapping map Enter in command mode.

If the command match wq or something equivalent (e.g.: wqall) it translate it into w|qa otherwise it keep it as it is before executing it.

1
  • echo 'foo': debugging?
    – D. Ben Knoble
    Jun 28, 2023 at 15:17

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.