-2

I'm temporarily working on a different machine. Every time I try and quit vim

:q!

after vim was started with more than one file on the command-line, vim is simply going to the next file. I already copied my .vimrc into the home directory.

On both machines it is vim 7.4.

In case this was unclear:

I'm using vi/vim since 30 years and I always used the command I mentioned to quit. It never meant "go to the next file". So any answer that I suddenly need to use something different, needs to tell me, why it worked until now and why it still does on another machine.

Frank Puck
  • 467
  • 1
  • 11

2 Answers2

1

Most likely you have hidden buffers turned on in this case of vim. That allows you to have multiple, unsaved files open (open files in vim are called buffers) and you can flip between them without having to save or abandon the changes. To see more, read up about set hidden.

The important thing to know here, is that each file is asking you 1 by 1 if it's safe to discard the changes and quit or if you want to save the changes and quit. Normally you would save with :w or quit with :q. Since you want to do this to ALL files and not just one, simply append a to the end of the command.

:wa saves all open files.
:qa quits all open files.
:wqa saves and quits all open files.

Stun Brick
  • 1,124
  • 6
  • 17
  • Which config file could have turned on this setting? – Frank Puck Jun 24 '22 at 20:55
  • No -- vim is not asking me "if it is safe to discard changes" -- it is going to the next file in the command-line-argument-list. There were no changes. – Frank Puck Jun 24 '22 at 20:58
  • @FrankPuck the config file would be your .vimrc which is a found at ~/.vimrc (on linux). The setting would be a line that says `set hidden`. Vim might not be asking you if it's safe to discard the files, but you are only closing them one at a time even though you opened lots of files. if you just say `:qa!` instead of only saying `:q!` then your problem will be solved. – Stun Brick Jul 05 '22 at 11:52
  • On your old machine and on your new machine, go into vim and run `:scriptnames`. You may find that more than one vimrc is being loaded (such as different vimrcs for different profiles). See what the behaviour is when you start vim by saying `vim -u NONE` followed by the files you want to open. And logically speaking, the statement " So any answer that I suddenly need to use something different, needs to tell me, why it worked until now and why it still does on another machine" isn't true. First we must establish what is the behaviour before we can tell you why the behaviour happens. – Stun Brick Jul 12 '22 at 09:41
0

No. Vim is not "ignoring :q!.

From :h :q in Vim 7.4:

Quit without writing, also when currently visible
buffers have changes.  Does not exit when this is the
last window and there is a changed hidden buffer.
In this case, the first changed hidden buffer becomes
the current buffer.
Use ":qall!" to exit always.
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Why does it still work with ":q!" on all other machines even in the presence of the same ~/.vimrc and the same vim version? – Frank Puck Jul 06 '22 at 12:04
  • You should compare the whole output of `$ vim --version` before claiming they are the same. Also, I would suggest coming up with a reproducible example so that we are on the same page, with `vim -Nu NONE`. – romainl Jul 06 '22 at 12:12
  • I'm unable to attach or even create a machine image! – Frank Puck Jul 06 '22 at 14:02