Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a vim script interactively from vim command line?

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.

like image 511
J. Polfer Avatar asked Jul 30 '10 17:07

J. Polfer


People also ask

How do I run a Vim script in terminal?

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.

How do I use Vim in command mode?

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.

How do I run a .Vim file in Linux?

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.

What does exclamation mark do in Vim?

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.


1 Answers

Script or function? If it is a function, try

:call FunctionName() 
like image 99
Doon Avatar answered Sep 30 '22 18:09

Doon