Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 488
Saullo G. P. Castro Avatar asked Dec 15 '22 07:12

Saullo G. P. Castro


2 Answers

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

/ts\[[^j]\]
like image 186
Kent Avatar answered Dec 17 '22 20:12

Kent


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.

like image 34
FDinoff Avatar answered Dec 17 '22 21:12

FDinoff