I want to add [](
to the beginning of a line and )
to the end of a line that starts with http
in Vim.
To do this I am using the following g command:
g/^htt/norm I[](
Now, I want to press Esc
key now inside g
and put A)
. How can I do that?
If you have an American English keyboard, pressing Ctrl-[ (control plus left square bracket) is equivalent to pressing Esc.
To exit from 'insert' mode, hit ESC (the escape key). If you want to force a quit (i.e. quit without saving) type: :q! You should by now have a file called data.
Pressing ESC quits from insert mode to normal mode, where you can press : to type in a command.
Normal mode is where one should spend most of their time while using Vim. Remember, this is what makes Vim different. In normal mode, there are multiple ways to move around an open file. In addition to using the cursor keys to move around, you can use h (left), j (down), k (up), and l (right) to move as well.
You can escape the Esc key by using ctrl+vfollowed by esc.
ctrl+v will insert the next non-digit literally.
Note: You may have to use ctrl+q depending on your system. (Nice mnemonic is quote)
See help for more information
:h c_Ctrl-V
To be able to use two :normal
commands in sequence, you have to wrap them in :execute
. When you use double quotes, you can then write the Escape as \<Esc>
, like this:
:g/^htt/exe "norm I[](\<Esc>" | norm A)
Notes:
:normal!
(with the bang) is preferred, because it's more robust.:substitute
here.This is easier to do with :s
:
:%s/^htt.*/[](&)/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With