Skip to main content
30 votes

What are the differences between :wq<cr> :x<cr> and ZZ when exiting vim?

As akshay pointed out, Vim's documentation explains, that :x and ZZ are equivalent and only save a file if the associated buffer has been changed. Whereas :wq saves the buffer to the corresponding ...
m4110c's user avatar
  • 451
20 votes
Accepted

Why is it not possible to kill Vim using the TERM signal from inside Vim itself?

A process can block, ignore, or catch signals. You can see how a given process handles signals with this shell command: $ cat /proc/PID/status | grep -E '^Sig(Blk|Ign|Cgt):' ...
user938271's user avatar
  • 5,987
14 votes

How do I close Vim externally?

Install the reptyr command using the system's package manager, such as: sudo apt install reptyr pacman -Sy reptyr Then use the reptyr command to switch the remote tty to the local (new) tty, as ...
Dave Jarvis's user avatar
13 votes

How do I close Vim externally?

You can send commands to vim externally if you're running... Vim servers For example, doing: vim --servername vim will cause vim to launch a server with the name "vim". Call it twice and the new ...
JoL's user avatar
  • 570
13 votes
Accepted

Cannot exit Vim even using q!

To solve this nuisance with netrw permanently, I added this to my .vimrc: " Per default, netrw leaves unmodified buffers open. This autocommand " deletes netrw's buffer once it's hidden (using ':q', ...
Matthias Braun's user avatar
12 votes

Any way to retrieve lost undo tree after closing window (but buffer is still open)

You can set a persistent undo with the following settings: set undodir=~/.vim/undodir set undofile This is avaible in Vim 7.3 an above
B.G.'s user avatar
  • 1,156
10 votes

Cannot exit Vim even using q!

This usually happens, if there are two or more buffers which are modified and Vim then usually toggles between them and shows the error message. So when :q! would abort the current buffer, it wouldn't ...
Christian Brabandt's user avatar
9 votes
Accepted

Job still running in buffer while :qa

Running process in a terminal buffer is treated mostly the same way as "an unsaved file". So you can do :qa! or :set confirm etc.etc. Well, anything to allow exit from Vim with buffers unsaved. But, ...
Matt's user avatar
  • 20.9k
9 votes

How can I ensure Vim doesn't quit entirely when the last window is closed, unless it's empty?

This is something I wanted when I first started using Vim, but I no longer do. From looking at your account, I can see you've been using Vim for several years, but for the benefit of other readers who ...
Rich's user avatar
  • 32.2k
8 votes

Terminal borked after invoking Vim with xargs

The reason is that xargs sets stdin to /dev/null, whereas vim needs stdin to be /dev/tty. BSD xargs (e.g. Mac) solution: echo -e 'file1\nfile2' | xargs -o vim -o sets the stdin of xarg's child ...
wisbucky's user avatar
  • 960
7 votes
Accepted

How do I quit vi/Vim/Neovim?

In short, hit the Esc key to make sure you're in "Normal" mode, then type :q (which will appear on the last line of the screen) and press the Enter. If Vim complains that you have unsaved ...
6 votes

How do you disable saving in vim unless you quit as well?

You could play with the write option. From :h 'write': 'write' boolean (default on) global {not in Vi} Allows writing files. When not set, writing a file is not ...
statox's user avatar
  • 50.1k
6 votes
Accepted

Why do I need to use q! after `find ... | vim -`, i.e., reading from stdin?

You can change vim - to vim -R -. From the manual: Read-only mode. The 'readonly' option will be set. You can still edit the buffer, but will be prevented from accidently overwriting a ...
Drew's user avatar
  • 605
5 votes

I'm stuck in Vim; I see "Command Line" at the bottom and nothing makes Vim respond

You probably pressed q: instead of :q. The q: command opens the commandline window. You can close it like any other window by using :q, :close, or <C-w>w. Some people like to disable this ...
Martin Tournoij's user avatar
5 votes

Cannot exit Vim even using q!

Try :bdelete! or :bd! for short. This stands for "buffer delete" and will close the buffer you have open. (Credit goes to Emil Asmussen) After that, you should be able to do :q! as normal.
DJMcMayhem's user avatar
  • 17.7k
5 votes

Why do I need to use q! after `find ... | vim -`, i.e., reading from stdin?

You are piping content into Vim, so it's starting a new unsaved buffer. If you don't need to save the content, you can add +'set buftype=nofile' to your command: find $HOME -type f -name "*.tex" -...
Tommy A's user avatar
  • 6,790
5 votes
Accepted

How to detect whether Vim has been invoked by another shell command?

Since vipe, git commit (and many other programs which invoke an editor) use the VISUAL and EDITOR variables (unless you specify an editor for git with git config core.editor), you can use that ...
muru's user avatar
  • 25k
5 votes

How to detect whether Vim has been invoked by another shell command?

I don't know how reliable it is but I found how to get the PID of the parent of a process here: ps -o ppid= -p <pid of the process> And how to get the name of a process from its PID here: ps -...
user9433424's user avatar
  • 6,158
5 votes
Accepted

Save all changed and unchanged buffers then exit

:wa and :wqa will write all changed buffers; from :help :wqa: :wqa[ll] [++opt] :wqa :wqall :xa :xall :xa[ll] Write all changed buffers and exit Vim. If there ...
Martin Tournoij's user avatar
4 votes

mapping to quit using "<Ctrl> + q" not coming into effect

Why do you need the call to execute? This should work just fine: nnoremap <C-q> :q<CR> Of course if your file has been edited vim will give you a warning and won't quit.
Tumbler41's user avatar
  • 7,756
4 votes

How do you disable saving in vim unless you quit as well?

As you have stated in the comments that you need to prevent the automatic saves you perform under muscle memory, you could just remap the particular combination(s) that you perform without thinking. ...
Rich's user avatar
  • 32.2k
4 votes

Quit subsequent files opened with gvim *.c?

When I tried the same thing, I got this error message: E173: 3 more files to edit I ran :help E173 and read *E173* > {number} more files to edit You are trying to ...
StandardEyre's user avatar
  • 1,128
4 votes
Accepted

Which highlight group is responsible for the confirmation dialog?

For some unknown reason it's :h hl-MoreMsg. BTW. If you're unhappy with some colors it might be worth to give a try to a different color scheme, as there's a ton of them.
Matt's user avatar
  • 20.9k
4 votes

How to cancel quitting in a QuitPre autocmd

Is this possible using QuitPre? "Quit" means quitting a buffer as in :quit. You probably want ExitPre instead. can I implement such functionality using Vimscript? No, AFAIK, the action ...
Matt's user avatar
  • 20.9k
3 votes
Accepted

Any way to retrieve lost undo tree after closing window (but buffer is still open)

What is most likely happening in your case is that the buffer is automatically unloaded because you don't have the option 'hidden' enabled. This option not only resolves the issue you reported, but ...
Vitor's user avatar
  • 1,752
3 votes

How do you disable saving in vim unless you quit as well?

You could key an event to an Autocommand: autocmd BufWritePost :q This will quit if you ever try to write the buffer. EDIT: Got it the wrong way around, thought you wanted to not be able to quit ...
Wolfie's user avatar
  • 667
3 votes
Accepted

Buffer scope variable not exists when run autocmd BufUnload

As you can see in :help BufUnload: NOTE: When this autocommand is executed, the current buffer % may be different from the buffer being unloaded <afile>. So you should use getbufvar() to ...
filbranden's user avatar
  • 29k
3 votes

Vim: how to make :q shut up about unvisited files?

The :cabbrev-answer has downsides because the abbreviation is active everywhere in the : command line, even if restricted to that type of command using the <expr> mechanism. Ideally, Vim would ...
Kaz's user avatar
  • 491
2 votes

How to exit Vim, without saving changes using the shortcut Ctrl-Q?

This is what fixed this problem for me, I unknowingly had bound to something else in my ~/.vimrc, when I removed it and added: silent !stty -ixon > /dev/null 2>/dev/null map <C-Q> :qa!&...
Josh Pinto's user avatar
2 votes

How do I close Vim externally?

What if you gracefully kill Vim? kill -s 15 -p [PID for Vim] kill -s (signal) 15 is called SIGTERM wich tells that process to gracefully shut itself down. To get the PID (Process ID) of Vim use: ...
Gustav Blomqvist's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible