Is there a way to run these scripts from the :
commandline with a few keystrokes?
Over the last couple of months, I've built a series of files full of vim-commands to auto-generate boilerplate code for my projects. It's allowed me to work faster.
However, the only way I know how to run these scripts is by assigning them to key-combinations in ~/.vimrc
. There's only so many keys I can remap.
Is there a way to run these scripts from the :
commandline with a few keystrokes?
For example, I have a unit_test_cpp.vim
script, which builds a boilerplate unit test cpp file. I'd like to be able to type
:utc
or some other simple combination of letters with a simple mnemonic to run this script on my currently open file.
You can always execute Vimscript by running each command in command mode (the one you prefix with : ), or by executing the file with commands using a :source command. Historically, Vim scripts have a . vim extension. Here, :so is a short version of :source , and % refers to the currently open file.
To go into INSERT mode from COMMAND mode, you type i . To go back to COMMAND mode, you type the esc key. vim starts out in COMMAND mode.
To start using vim, just run the "vim" command on the Linux shell followed by the path of the file that you want to edit. [enter] means to press the return or enter key on your keyboard. The word --insert-- will appear at the bottom of the editor window to show that you are in insert mode now.
qualifier tells Vim to force the operation. For example, if the file was read-only you would use :w! to write it anyway. If the file was modified and you wanted to quit without saving, you would use :q!. :wq! just means force write and quit in one command.
Script or function? If it is a function, try
:call FunctionName()
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