When you want to do some format changes in vim via the
norm! command, instead of doing them in 2 different commands, you can actually exit insert mode inside
norm! by doing
Ctrl-V and then
Let’s say I want to get all these emails into a list so I can do a query with them
email@example.com firstname.lastname@example.org email@example.com firstname.lastname@example.org
The general format is
:[range]g/<pattern>/<cmd>. By default the range is the whole file.
We can execute this command
:g/^/norm!I"\?A", to get what we want; let’s break it down:
:g This specifies that we want to execute a command.
/^/ Match all lines (since all lines do have a beginning of line).
norm! Means we will execute a normal! Command, which means vim will run things you would do to edit a file and execute them on matched lines.
I means go to the beginning of the line in insert mode and insert the
" character, then comes the
<ESC> that looks like
\? to exit insert
A goes to the end of the line and enters insert mode and finally add
Now the file would be like this:
"email@example.com", "firstname.lastname@example.org", "email@example.com", "firstname.lastname@example.org",
To finish, just run
J on all lines and add the brackets at the
beginning and end of the line and you are ready to do that query!
("email@example.com", "firstname.lastname@example.org", "email@example.com", "firstname.lastname@example.org",)