I have two search/replace commands that I find myself running in vim fairly often to clean up html code so I can copy/paste it online. The commands are:
:%s!<!\<!g
:%s!>!\>!g
I wanted a way I could map both of these commands to be run together ... I did some searching for how to use the :map
commands in vimrc, however, I can't see how to combine the two lines into a single command that is run with a single keystroke (or a single sequence of strokes).
Thanks!
To map a sequence of keys to execute another sequence of keys, use the ':map' command. For example, the following command maps the <F2> key to display the current date and time. The ':map' command creates a key map that works in normal, visual, select and operator pending modes.
The second line says: pressing Ctrl - S within a document while in 'insert' mode will escape to normal mode, perform a :w <enter , then press a to get back into insert mode.
noremap is the "root" of all non-recursive mapping commands. The root form applies to the same modes as map . (Think of the nore prefix to mean "non-recursive".) (Note that there are also the ! modes like map! that apply to insert & command-line.)
It's either short for "runcom", which is an abbreviation for "run commands"; or it's "run control". Other uses for the abbreviation are: runtime configuration. resource control. release candidate.
You can put the commands on a single line separated with a bar.
:%s!<!\<!g|%s!>!\>!g
But you'll have to escape it in the map
command
:map <F3> :%s!<!\<!g\|:%s!>!\>!g<CR>
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