8

Occasionally when I type : to quit or write my file the prompt already contains the characters :'<,'> without me typing anything. It causes an error if I type w or q. I cannot replicate this problem. It happens at the oddest times and I have not been able to determine what is causing it.

It took me forever to figure out that my accidentally typing q: instead of :q was causing me to have trouble quitting. Now that I know about that little quirk, I'm trying to figure out what causes this other behavior. I can't find anything on it, though I've seen it somewhere in someone's colon command.

Is this an expected behavior? What could be causing it?

15

Seeing '<,'> in the command line when you press : indicates that you currently have a visual range selected (e. g. with v, V, or Ctrl-v), and vim is helpfully prefixing the markers for 'beginning of selection' through 'end of selection' in order to apply those limitations to the scope of the command you are presumably about to enter.

See :h visual-operators:

Note that the '<,'> will appear automatically when you press : in Visual mode.

Since you can't "quit" only a certain part of a file, that is why you get an Invalid address when you try to :'<,'>q.

If you do want to run a command not suchly limited, you can press Ctrl-U to erase everything to the left of the cursor before entering q, or simply use the ZZ or ZQ alias.

  • 3
    Note that ZZ will write all the changes to the files before quitting. If you want to discard the changes, use ZQ. – Ruslan Oct 4 '18 at 10:31
  • @Ruslan. Great tip. I've always just typed :q! which is always a problem for the context of the question. Now ZQ is in my arsenal! – malan Oct 4 '18 at 12:23
  • "not suchly limited" would make a good band name – Omar Oct 6 '18 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.