If I wanted to process a batch of text files with the same set of commands for example:
:set tw=50
gggqG
Can I save the above and run it with a shortcut command?
If you want to use it only once, use a macro as specified in some of the other answers. If you want to do it more often, you can include the following line in your .vimrc
file:
:map \r :set tw=50<CR>gggqG
This will map \r
to cause your two lines to be executed whenever you press \r
. Of course you can also choose a different shortcut, like <C-R>
(Ctrl+R) or <F12>
or something.
The following in .vimrc will define a new command Wrap
that does what you want.
command! Wrap :set tw=50 | :normal gggqG
Call it with :Wrap
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