Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Hot answers tagged

48 votes
Accepted

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

From Vim's documentation, :x and ZZ are equivalent; they only save the file if it has been modified, then quit Vim: Write current file, if modified, and quit (same as ":x"). (Note: If there are ...
user avatar
  • 5,766
30 votes

Terminal borked after invoking Vim with xargs

This happens when vim is invoked and it's connected to the previous pipeline's output, instead of the terminal and it's receiving different unexpected input (like NULs). The same happens when you run: ...
user avatar
  • 16.5k
28 votes
Accepted

How do I close Vim externally?

Having recently run into this problem (via another way: Vim running on a remote server, and I'd forgotten screen), I decided to hunt for a way. The first idea was to look up the file descriptors used ...
user avatar
  • 23.7k
27 votes
Accepted

Prevent Vim from clearing the terminal after exit

By default VIM, when terminating, sends the string configured with the option t_te to the hosting terminal to tell it to clear the screen. To avoid it just :set t_te= to send nothing to the terminal ...
user avatar
  • 4,452
24 votes

What's the difference between "quit" and "abort"?

Try this: run vim file1 in a terminal, then run vim -p file1 file2 in a different terminal. The second command will prompt you as above. If you answer Quit, you still get to edit file2. If you ...
user avatar
  • 3,568
23 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 ...
user avatar
  • 361
22 votes
Accepted

How to exit vim from split mode?

Use the command :qall!, :qa! for short, or its safer alternative :qall that prevent to discard modified buffers. To save all buffers before quitting use the command :wqall. See :help window-exit for ...
user avatar
  • 4,452
18 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):' ...
user avatar
  • 5,457
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 ...
user avatar
  • 510
13 votes

Terminal borked after invoking Vim with xargs

Workaround suggestion: use a buffer as a filesystem navigator Use the vim - command to read a list of paths from stdin. Vim's :help -- explains this:1 Start editing a new buffer, which is filled ...
user avatar
  • 5,766
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', ...
user avatar
12 votes
Accepted

How to safely quit vim if there's some unsaved changes?

The option confirm does what you describe for modified files. With set confirm in my vimrc, it gives the following prompt when I :quit a modified NoName buffer: Save changes to "Untitled"? [Y]es, ...
user avatar
  • 436
11 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 ...
user avatar
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 ...
user avatar
10 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
user avatar
9 votes

Terminal borked after invoking Vim with xargs

Besides reset, you can try: stty sane which should also make your terminal usable again. See here for explanations. And somehow this can be considered a vim misbehavior, at least Neovim doesn't ...
user avatar
  • 193
8 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, ...
user avatar
  • 15.5k
7 votes

How do I avoid exiting vim to open a new file?

From your post it sounds like you have a problem of exiting Vim. You mention a plugin that may help, but lets get to the root of the problem which is you have a created bad habit. As with all bad ...
user avatar
7 votes
Accepted

How do I avoid exiting vim to open a new file?

Update: I created a confirm_quit.vim plugin; it has some additional options, like only asking for confirmation when quiting the last buffer (rather than closing any buffer). I will leave the below ...
user avatar
7 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 ...
user avatar
  • 27.4k
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 ...
user avatar
  • 515
5 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 ...
user avatar
  • 730
5 votes

What's the difference between "quit" and "abort"?

@FDinoff suggested checking the vim help. In case anyone wanted to see these more easily: WHAT TO DO? *swap-exists-choices* If dialogs are supported you will be ...
user avatar
  • 151
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.
user avatar
  • 16.5k
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" -...
user avatar
  • 6,320
5 votes
Accepted

Swap choices: how can I "skip" instead of "quit" or "abort"?

I agree with you, and this seems like it could be improved, because one of those you would think would not create the buffer, and I just verified that I see the same behavior you describe, but if I ...
user avatar
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 ...
user avatar
  • 23.7k
5 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 ...
user avatar
  • 45.9k
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 ...
user avatar
4 votes

Save/Quit Unprivileged File With Sudo

I don't think there is a save/quit automated, but as a reference to several nix-oriented tasks, there is a plugin that covers much of it (e.g. SudoWrite). (plugin: eunuch) To combine the two tasks ...
user avatar
  • 571

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