Saullo G. P. Castro
Saullo G. P. Castro

Reputation: 58895

How to search not matching pattern in VIM

Here is an excerpt of my .py file:

for i in range(1,nxs-2):
    for j in (1, nts-2):
        dg_cc(dg,sina,cosa,s,r2tanb,omega,L,n,m,xs[i],ts[k],pd)
        dot( dg,F,c1,transa=T )
        dot( c1, dg, ansK1, N, N, alpha=2., beta=1. )
        # linear buckling part
        g = g_cc(m,n,L,xs[i],ts[j],pd)
        Bg = fBg(Bg,cosa,s,L,m,n,xs[i],ts[i],pd)
        dot( g, Bg, ansK1, T, N, alpha=2., beta=1. )
        #
        if pd:
            fdg0(dg0,sina,cosa,s,r2tanb,omega,L,xs[i],ts[j])
            dot( dg0, F, c2, transa=T )
            dot( c2, dg, ansK0, N, N, alpha=2., beta=1. )
for i in (1, nxs-2):
    for j in range(1,nts-2):
        dg_cc(dg,sina,cosa,s,r2tanb,omega,L,n,m,xs[i],ts[n],pd)
        dot( dg,F,c1,transa=T )
        dot( c1, dg, ansK1, N, N, alpha=2., beta=1. )
        # linear buckling part
        g = g_cc(m,n,L,xs[i],ts[j],pd)
        Bg = fBg(Bg,cosa,s,L,m,n,xs[i],ts[j],pd)
        dot( g, Bg, ansK1, T, N, alpha=2., beta=1. )

I have to fix all the typos keeping only ts[j] and fixing those with ts[i] or ts[n], for example.

How do I build my searching pattern in order to get everywhere where ts[something] something NOT equal j?

Upvotes: 5

Views: 6831

Answers (3)

FDinoff
FDinoff

Reputation: 31429

If the pattern you wanted to negate was more than one character you could use a negative lookahead. Which matches if the pattern does NOT match the current position.

/ts\[\(j\)\@!.\{-}]

or with very magic

/\vts\[(j)@!.{-}]

Where the pattern being negated if right before @! in this case the j. The .{-} is a non-greedy match that is used to match everything until the next square bracket.

Upvotes: 6

devnull
devnull

Reputation: 123508

The following should work for you:

/ts[[][^j]]

or escaping the [:

/ts\[[^j]]

Upvotes: 1

Kent
Kent

Reputation: 195059

can you try this, see if it works for your requirement?

/ts\[[^j]\]

Upvotes: 9

Related Questions