Vimで検索をスキップしてタイトルの後ろの内容を置き換える

Vimで検索をスキップしてタイトルの後ろの内容を置き換える

パターンを変更する必要がありますが、特定の単語の後に続くパターンを変更したくありません。

これは私のプログラムです:

:vnoremap   ::silent! call Bib()

function! Bib()
   %s/\s*\n*{\\&}\s*\n*/ /g
   %s/\([A-Z]\)\.\([A-Z]\)\./\1\. \2\./g
   "%s/\(\w*\-\w*\|\w*\),\s*\n*\([A-Z]\)\./\r\\snm{\1}\r\2\./g 

endfunc

特定の単語の後にこの検索パターンを使用したくありません: "references"

ベストアンサー1

「何か」と一致させるが、特定の「単語」の後に一致しないようにする\@<!

/\(word\)\@<! something/

「something」を「somethingelse」に置き換えます。ただし、「something」が「word」の後に来ない場合にのみ該当します。

:%s/\(word\)\@<! something/ somethingelse/


内部でvim説明を表示:help /\@<!:

\@<!    Matches with zero width if the preceding atom does NOT match just
    before what follows.  Thus this matches if there is no position in the
    current or previous line where the atom matches such that it ends just
    before what follows.  |/zero-width| {not in Vi}
    Like "(?<!pattern)" in Perl, but Vim allows non-fixed-width patterns.
    The match with the preceding atom is made to end just before the match
    with what follows, thus an atom that ends in ".*" will work.
    Warning: This can be slow (because many positions need to be checked
    for a match).  Use a limit if you can, see below.

おすすめ記事