2

When I first started using Vim 10 years ago, I found myself typing

:'a,'fs/target/replacement/g

a lot. I was used to using 'a and 'f as my go-to marks. So I also had this in my .vimrc:

map qq :'a,'f

Are there any special kinds of marks in Vim that act more like "quick" or "temporary" marks, accompanied by a shortcut or notation that means "the last two quick-marks"?

I looked through the documentation on marks but did not see any. Does anyone have a more elegant shortcut than mine?

1 Answers1

3

Using 2 marks to operate on the text between those lines is the 'vi'-compatible way of the more modern and (literally) visual way of operating in Vim (and probably why visual mode was invented in the 1st place): visually select a range with whatever means (motion, text-object), then start your ex command, which operates line-wise: when you hit :, you will see those two quick marks automatically inserted before the : (the start and the end marks of the visual selection).

Quick access to "the last two quick-marks" in this case would translate to "restoring the last visual selection", which can be accomplished with gv.

And now for the funny part: if you really want it, you can explicitly set those two marks (< and >), manually, using m< and m>, as with any letter-based mark. I.e. you don't need to go to visual mode for that; then, either use gv to restore that selection and start your ex command, or manually insert :'<,'>some-ex-command-here to (similarly) operate on that line range. In another words, visual marks can operate exactly as in your request (quick or temporary marks that can be set - a pair of them), with the advantage of also allowing a more visual way of assignation.

So, maybe this mapping, to execute on a selection:

noremap g: gv:
VanLaser
  • 9,700
  • 2
  • 24
  • 34