Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
1 ああああああああ 2 aaa ccccccccc aaa 3 あああああああ
各行の2 番目の aaa を yyyに置き換える方法
1 aaa bbb yyy 2 aaa ccccccccc yyy 3 aaa xx yyy
もう 1 つの方法は、パターン内の一致の開始と終了を示す and を使用することです\zs。\zeしたがって、次のことができます。
\zs
\ze
:%s/aaa.*\zsaaa\ze/yyy
つまり、「aaa」の後に何かが続き、さらに別の「aaa」が続き、それを「yyy」に置き換えます。
ただし、1 行に 3 つの「aaa」がある場合、これは機能しません。\{-}代わりに を使用する必要があります*。( を参照:h non-greedy)
\{-}
*
:h non-greedy