Como substituir o enésimo padrão de ocorrência no editor VI

3

O conteúdo do arquivo

This is a demo file
*******************
This is the 1st line the the the.
This is the 2nd line the the.
This is the third line the the.
This is the 5th line.
This is the 6th line.
This is the 7th line.
This is the 8th line.
This is the 9th line.
This is the 10th line.

Na terceira linha, há 4 instâncias de the .

Eu quero alterar apenas a terceira ocorrência de the para THE .

no modo ex se eu digitar

:s/the/THE/g

mudará todo o the para THE , então como mudar o 3º "o" para "O"?

    
por user5499810 26.08.2017 / 13:36

2 respostas

1

Substitua cada ocorrência de PATTERN em uma linha com REPLACE.

:%s/\(.\{-}\zsPATTERN\)\{N}/REPLACE/

Substitua a th ocorrência de PATTERN na linha 3 rd apenas com REPLACE.

:3s/\(.\{-}\zsPATTERN\)\{N}/REPLACE/

No seu exemplo de givin, use o comando da seguinte forma.

:3s/\(.\{-}\zsthe\)\{3}/THE/
    
por αғsнιη 27.08.2017 / 02:59
2

Bem, você pode selecionar a terceira linha usando 3 e usar o modo interativo ( gc )

:3s/the/THE/gc

Você recebe

replace with THE (y/n/a/q/l/^E/^Y)?

pressione n (não) n y (sim) q (sair)

    
por Zanna 26.08.2017 / 13:50