Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - search for lines with (or without) character at a specific offset from the start of a line

Tags:

regex

vim

I want to find all lines where column 78 (the 78th character on the line) is not a space.

Ideally, I'd like to use it like a normal search.

like image 553
merlin2011 Avatar asked Oct 20 '12 03:10

merlin2011


3 Answers

You can use this pattern:

\%78c\S
  • \%78c matches position at column78 (Actually, the column is the byte number thus it's not exactly right for multi-byte characters). Use \%78v to match virtual column.
  • \S matches non-space
like image 190
kev Avatar answered Oct 20 '22 00:10

kev


I guess you need not what @kev or you suggest: while you correctly find 78’th character (with character+diacritics counting for one) and @kev correctly finds 78’t byte it looks like you are solving something like “text beyond 78 column border”. If my assumption about your task is true then you should use

\%78v\S

(\%{number}v matches virtual (screen) column). If not, better to use your answer, I never saw a need in using \%{number}c except for in some generated patterns.

like image 37
ZyX Avatar answered Oct 19 '22 23:10

ZyX


I figured it out, leaving as an example in case someone tries this in the future:

If I want to match column "n", I just need to match anything of column "n-1" and then do my criteria for column n. The following expression finds all lines that have column 35 not equal to space.

^.\{34}[^ ]
like image 32
merlin2011 Avatar answered Oct 20 '22 00:10

merlin2011