To search for A T\n
in vim I can just do
/A T\n
What would be the equivalent for not newline at the end?
/A T[^\n]
did not work.
regular expressionvim
To search for A T\n
in vim I can just do
/A T\n
What would be the equivalent for not newline at the end?
/A T[^\n]
did not work.
Best Answer
searches for
A T
followed by a non-newline character (.
is the standard regex operator that matches any character (except newline)).searches for
A T
not-followed by a newline character (you'll see the difference if youset hls
).\@!
is a vim-specific regexp operator that provides with similar functionality as the(?!...)
perl/PRCE regexp operator (negative look-ahead). That one would work in the case of a non-text file that ends inA T
(and no newline).You could also use the positive look-ahead:
(
A T
as long as it's followed by a non-newline character).You can also do:
Same as
/A T.
except that the end of the matched string is after theT
.\zs
and\ze
are againvim
specific and can be used to narrow the matched string (as seen with highlight search) within the pattern. The perl/PCRE equivalent of\zs
is\K
(in recent versions).Having said that,
/A T[^\n]
works for me (vim 7.4.52), though[...]
would never match a newline anyway (you'd need\_[...]
to include the newline), so.
is simpler.