I intend to create a set of options in vimscript as flags that I can then set at runtime to change the behaviour of my script.
How can I create custom option variables, other plugins like NERDTree for example seem to be able to do it...
The set of Vim options (i.e. the stuff that you manipulate with :set) is fixed. But plugins use variables, usually named g:PluginName_OptionName or so, to get something very close to options. With the different variable scopes (g:, b:, w:), you can even achieve something like the buffer- or window-local options in Vim: This means that the plugin checks for the existence of the local variable first, and falls back to using the global variable if no local one exists.
Plugins should provide default values for their configuration variables, that can be overridden in the user's .vimrc. This is achieved by a test like this:
if ! exists('g:PluginName_ConfigItem')
let g:PluginName_ConfigItem = 'default value'
endif
If you plan to publish your plugin, be sure to document the variables and what values they can hold.
Related
My C code contains #ifdef FOO. Can add something to the SCons command line to set the define, without having to modify the SConstruct/SConscript files?
I know there is a construction variable CFLAGS, and if I could get -DFOO into it, that should work. But, I cannot find a way to set construction variables from the command line.
No, unless your SConstructs/SConscripts support some sort of option/variable that you could give on the command-line (see chap. 10 "Controlling a Build From the Command-Line" in the UserGuide http://www.scons.org/doc/production/HTML/scons-user.html ).
By design, SCons uses "clean" Environments (no shell variables are imported) to protect your builds and make them repeatable. You can't simply override this by suddenly injecting flags and options from the outside.
But you can, in the SConstructs, create your build Environment such that you allow it to "import" certain shell settings (or the whole os.environ). See also #1 of the "most frequently asked FAQ" at https://bitbucket.org/scons/scons/wiki/FrequentlyAskedQuestions#markdown-header-why-doesnt-scons-find-my-compilerlinkeretc-i-can-execute-it-just-fine-from-the-command-line .
Is there a way to unset environment variables with grunt-env? I know I can set them from the module, and there is even a way to set them to a value only if it doesn't exist. However, the project's GitHub page does not seem to show how to unset them. Any solution would be better if it also included a way to unset only if the variable is already set. Suggestions for other modules are welcome, as well.
Is there perhaps a value I could set the variable to, like undefined or null or empty string? Forgive me, I'm not too well-versed in environment variables.
The reason I am asking this is because I am creating an express app, and I may want to set some values, which would be controlled by environment variables, back to the defaults, and this would require either setting the variable to a specific value or unsetting it. I would rather go with unsetting it, if possible, so I don't have to remember which value to set it to.
This plugin is setting env variables only within the grunt process - those variables will not be visible for other processes at all! So you will not be able to set shell environment variables for your express app with this grunt plugin.
I also advice you not to set shell env variables with your build tools, but have them defined in bash file and loaded when the server is booted.
I'm looking for a good practice there. I need to store some global config options in my node.js command-line tool.
For example typing in bash:
$: mycommand set myGlobalOption=value
and then I can use myGlobalOption with another commands, is storing this value in environment variable a good solution?
Store this in a configuration file in the user's home directory like ~/.myprog.json. You can't store persistent data in environment variables because those ultimately come from shell configuration files like ~/.bash_profile which are not machine editable. Allowing these values to be set by environment variables is reasonable, but just have the user set them herself and don't bother trying to have a set command like you describe.
You could also just take these options as command line arguments like mycommand --myglobaloption=value and let users who want to always use the same value set up a shell alias like alias mc="mycommand --myglobaloption=value".
Is there a trick or script that allows me to switch between sets of vim-plugins and -settings easily?
I use vim for very different development and writing. It can be really annoying to have certain webdevelopment-specific plugins turn up, when writing a report in LaTeX, for example.
What I'd like to see is something like RVM.
Have a set of "global" plugins and settings; plugins and settings that are always enabled or used.
Per project plugins and settings; pluginss, configurations and settings that will be loaded after activating that "environment".
You may find localvimrc to be useful for point number two. It allows you to have a .lvimrc in your project folder with settings for that specific project. In that file you could load your project-specific plugins by manipulating the runtimepath or by using pathogen/vundle/whatever.
Using this method you would configure your "global" settings and plugins as you would normally.
Nice question IMHO. By the way, using a plugin manager could simplify this kind of stuff too. For example, with pathogen you can do something like:
" To disable a plugin, add it's bundle name to the following list
let g:pathogen_disabled = []
if your_condition
call add(g:pathogen_disabled, 'myplugin')
call add(g:pathogen_disabled, 'myplugin2')
end
See this answer for a good example about conditional loading. It would be very nice to see this feature implemented in pathogen.
I'd just make aliases
alias mvim='vim -u myvimrc'
alias ovim='gvim -U someothervimrc'
Ans yes you could use runtimepath inside the vimrc-s to setup very different configurations
I've a question that should be fairly simple, but I have yet to find a solution for. I'm editing my .vimrc and would like to set an option using results saved in a variable. For example, I would like to aggregate all my temporary files in ~/.vimetc. Here's what I would like to do,
let s:vimetc=$HOME.'/vimetc/'
set backupdir=s:vimetc.'backups/'
set directory=s:vimetc.'vimswap/'
set viewdir=s:vimetc.'vimswap/'
Of course, set doesn't resolve variables so I just end up with the literal |s:vimetc.'backups/'|, not at all what I would like. I tried using &s:vimetc with similar results. Does anyone know how to do this?
let &backupdir=s:vimetc.'backups/'
http://vimdoc.sourceforge.net/htmldoc/eval.html#:let-option