I was searching for the vim scripts to clear the registers in vim, I found this helpful script
right now i am inserting the code withing a function and putting it in my .vimrc file
function ClearReg()
let regs='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"'
let i=0
while (i<strlen(regs))
exec 'let @'.regs[i].'=""'
let i=i+1
endwhile
unlet regs
endfunction
my question is
1. is the right way to create a function and put it in a .vimrc file?
2. If i would like to use this script as a plugin which path should i put this script?
Prefer to put functions in autoload plugins. They act as lazily loaded library plugins.
&rtp/autoload/lh, and the functions have names likelh#foo#bar(). Thanks to that, there is no risk of conflict with another plugin that defines afoo#bar()function.foo#bar#titi()is defined somewhere in&rtp/autoload/foo/bar.vim.Thanks to autoload plugins I can also control the logging level of my functions, plugin (library) per (by?) plugin (library). For instance in the recent
autoload/lh/async.vim, I start the script with:which permits me to fetch the internal value of any script variable (or function) with
lh#aynch#debug('s:job_queue')for instance, and also to trace what is done with:Which will display me in the quickfix windows after a
:call lh#async#verbose(1)(and a:LHLogs qf) (when I use this library to generate tags in the background):I can require logs to be produced in lh-tags plugin also, or instead of async-library.
This is of course a little bit overkill for very simple scripts. But the more complex the code becomes, the more useful this approach is.
Regarding the where to put it. By default, you can store your autoload plugin (or any other file) into
$HOME/.vim/autoload/under *nix, or$HOME/vimfiles/autoload/under Windows. However, if some day you wish to share it, or to put it into its own repository, the exact directory where to store the plugin will depend of the packages managers you use. First start with:help 'rtp', then read the documentation of your package manager.