Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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.