0

I'd like to add ruler marks/virtual columns along the lines of

matchadd('ColorColumn', '\%81v', 100)

while restricting their display to the cursorline.

Any ideas ?

1

Try the following two commands:

" Match when cursor before column
matchadd('ColorColumn', '\%#.*\zs\%81v', 100)

" Match when cursor after column
matchadd('ColorColumn', '\%81v\ze.*\%#', 100)

It should be possible to combine these into a single regular expression, but simply placing them into an alternation with \| doesn't work correctly*, so doing so seems like more trouble than it's worth.

These work by finding the cursor position \%# either following or followed by the specified column, but excluding everything apart from the column from the match with \zs and \ze.

See:

  • :help /\%#
  • :help /\zs
  • :help /\ze

* At a guess, there may be some complexity in the interaction between \zs/\ze and alternation that I'm unaware of—you might have better luck with lookahead \@= and lookbehind \@<=, but note that these are inefficient compared to \zs/\ze.

  • Thanks so much Rich for code that works now and for the entrance to understanding and perhaps expanding on it. – cesces Mar 16 '18 at 15:38
  • I think this idea+impl has a lot of appeal for intra-line navigation: o set marks every 20-30 chars, so there's not more than 3-4 on a line. 3-4 is small enough of a number to make it easy to infer the col number for each mark o to go to a particular word, see the closest mark, and l to the col # that you infer for the mark, there you're likely close enough to get to the begin/end of a word/WORD via one of `[w,W,b,B] etc, maybe w/ a count, likely at most 2 – cesces Mar 16 '18 at 15:49
  • o marks are on current line only, so you don't have a screen of colored column clutter. o less complicated than most other solutions, from both code and operational pov, e.g. no new maps needed – cesces Mar 16 '18 at 15:53
  • @cesces Interesting idea. I generally just use [count]f or f;;; for that sort of movement, though. – Rich Mar 16 '18 at 16: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.