I'd like to make a script that executes a series of commands (basically just two lines):
:v/\S/d :w
But i cant find a tutorial about how's done. Anyone?
|
|
There are many ways to proceed. A- You can write a simple script that contains the lines you want to execute, and invoke it manually. ex:
B- You can have a plugin that contains something that will trigger what you want to execute. If the action is a little bit complex, we usually prefer to define a function for maintenance purposes. B.1. If the function is short enough and used every time you use vim, you can define it into your plugin. B.1.1. If you prefer to invoke the function directly (usually never the case) with
(That solution pollutes the global namespace, moreover other plugins may overrule it.) B.1.2 Usually, we define either a mapping, or a command that will call the function. This way, the function can be made local to the current script -- its name starts with
Now you can either define a command:
or a mapping:
B.2. If the function is really long by itself, or because of the other functions it requires to accomplish its work, and/or if the function is seldom used, we prefer to define it in an autoload plugin:
and the call to the (public) function from the plugin is done using the ... function name:
Last notes: We usually provide anti-inclusion guards on plugins (and ftplugins), but not on plain scripts nor on autoload plugins. This is because one may want to prevent, from their .vimrc, some plugins to be loaded. Remark: the plugin muTemplate I'm maintaining has skeletons for the different kinds of vim scripts. However we may sometime want to reload one particular plugin we are maintaining in order to use/test/tune the (new) function(s) we are developing. In that case it is important that the functions and commands definitions are banged with a |
||||
|
|
|
|||
|