Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted
/A T.

searches for A T followed by a non-newline character (. is the standard regex operator that matches any character (except newline)).

/A T\n\@!

searches for A T not-followed by a newline character (you'll see the difference if you set 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 in A T (and no newline).

You could also use the positive look-ahead:

/A T.\@=

(A T as long as it's followed by a non-newline character).

You can also do:

/A T\ze.

Same as /A T. except that the end of the matched string is after the T. \zs and \ze are again vim 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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