Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Vim, how to insert a word after regex match at the begining of next line

Tags:

vim

A word needs to be injected at the beginning of each line 1. I tried the following, but obviously it does not work :g/^=/+1i/myword/

File structure:

===============
line 1
line 2
...
===============
line 1
line 2
...
like image 697
user1602 Avatar asked Nov 27 '25 05:11

user1602


1 Answers

You are almost there:

:g/^=/+1normal Imyword

Note that +1 could be shortened to + and :normal to :norm:

:g/^=/+norm Imyword

See :help :insert for why your method couldn't work and :help :normal.

like image 184
romainl Avatar answered Nov 29 '25 08:11

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!