https://wiki.vifm.info/api.php?action=feedcontributions&user=176.14.204.181&feedformat=atomVifm Wiki - User contributions [en]2024-03-29T02:18:21ZUser contributionsMediaWiki 1.35.1https://wiki.vifm.info/index.php?title=Configuration_model&diff=354Configuration model2015-07-25T21:44:08Z<p>176.14.204.181: /* Location of configuration files */ /etc is not mentioned anywhere, added</p>
<hr />
<div>There are several commands that can be used to configure Vifm (e.g.<br />
<code>:set</code>, <code>:colorscheme</code>), but, if you restart it, all<br />
settings are reset to their previous values. To make changes permanent one<br />
needs to put them into configuration file or ask Vifm to store them<br />
automatically. Intent of this section is to describe things related to configuration.<br />
<br />
==== Configuration files ====<br />
<br />
Vifm follows the same configuration scheme as Vim and many other Unix<br />
applications use:<br />
* main configuration file should be edited manually as it is only read by the application and is never modified by it;<br />
* state of the application that is preserved across session is stored in separate file(s) and is not meant to be modified by a user.<br />
<br />
For Vifm the first file is called <code>vifmrc</code> (located at<br />
<code>~/.vifm/vifmrc</code> by default) and the second one is<br />
<code>vifminfo</code> (located at <code>~/.vifm/vifminfo</code>).<br />
<br />
<code>vifmrc</code> consists of regular commands that can be entered on the<br />
command line. Any settings that are expected to be persistent for sure should<br />
be set in this file via appropriate command-line commands.<br />
<br />
<code>vifminfo</code> is [[#Writing vifminfo manually|usually]] written<br />
automatically. Which settings are written and applied on startup depends on<br />
<code>'vifminfo'</code> option. Instead of just overwriting all settings, Vifm<br />
tries to merge previously stored state with the new one. Such strategy helps a<br />
lot in managing multiple instances running at the same time. New settings have<br />
higher priority than older ones, still Vifm tries to preserve as much of old<br />
state as it can to do not forget history items or other settings that user might<br />
want to reuse later.<br />
<br />
==== Location of configuration files ====<br />
<br />
''TODO: describe all possible variants (except envvars covered below) for different OSes''<br />
<br />
Support for /etc was implemented in 0.8.<br />
<br />
==== Writing <code>vifminfo</code> manually ====<br />
<br />
Sometimes (e.g. before running external application that might affect<br />
configuration of Vifm) it's useful to write <code>vifminfo</code> file without<br />
closing Vifm. <code>:write</code> command is exactly for that.<br />
<br />
==== Omitting writing of <code>vifminfo</code> ====<br />
<br />
By default <code>vifminfo</code> is written on exit, i.e. <code>:q[uit]</code><br />
is equal to <code>:wq</code>, this means that requested changes are saved<br />
automatically. Although it's quite convenient, sometimes one might want to drop<br />
current runtime state in favor of previously stored one or state of another<br />
instance. In such rare cases <code>:quit!</code> command-line command or<br />
<code>ZQ</code> normal mode shortcut can be used.<br />
<br />
==== Moving and finding configuration files ====<br />
<br />
There are two environment variables that can be used in both cases:<br />
<br />
* <code>$VIFM</code> points to main configuration directory (usually <code>~/.vifm/</code>);<br />
* <code>$MYVIFMRC</code> points to main configuration file (usually <code>~/.vifm/vifmrc</code>).<br />
<br />
These environment variables are valid inside Vifm and also can be used to<br />
configure it by setting some of them before running Vifm.<br />
<br />
When <code>$MYVIFMRC</code> isn't set, it's made as<br />
<code>$VIFM/vifmrc</code> (exception for Windows: vifmrc in the same directory<br />
as <code>vifm.exe</code> has higher priority than <code>$VIFM/vifmrc</code>).<br />
<br />
==== Skipping load of configuration files ====<br />
<br />
To ease diagnosing issues caused by configuration and provide a way to start<br />
Vifm with sane defaults <code>--no-configs</code> command-line option is<br />
supported.<br />
<br />
Passing it to Vifm blocks reading of both <code>vifmrc</code> and<br />
<code>vifminfo</code> files. They can be read later via <code>:restart</code><br />
command. You probably ''do '''not''''' want to save <code>vifminfo</code> file<br />
after running Vifm in this mode, so consider reading<br />
[[#Omitting writing of vifminfo|related section of this page]].<br />
<br />
==== Reloading configuration ====<br />
<br />
Here are several scenarios when one might want to reload configuration:<br />
<br />
* one of configuration files is changed;<br />
* something made in current session is better to be undone, but restarting Vifm in inconvenient;<br />
* testing of something (e.g. new command) that is better to repeat in same environment multiple times.<br />
<br />
<code>:restart</code> command is there to make these usage scenarios possible.<br />
<br />
It tries to repeat the same process that happens on startup, e.g.:<br />
<br />
# Pretend it doesn't have much context (forget the one it has ''almost'' completely).<br />
# Reread <code>vifmrc</code> and <code>vifminfo</code> files.<br />
# Parse command-line arguments again to execute startup commands (<code>+cmd</code> or <code>-c cmd</code>).<br />
<br />
For convenience reasons some parts of runtime state is not erased:<br />
<br />
# Current directories of panes.<br />
# Cursor positions and top items of file lists.<br />
<br />
These are minor things which are better to leave as they are to preserve current context from user's point of view.<br />
<br />
===== <code>:restart</code> usage example =====<br />
<br />
Here is definition of <kbd>,c</kbd> shortcut to edit configuration file:<br />
<br />
<source lang="vim"><br />
nnoremap ,c :write | execute ':!%n${EDITOR:-vim} $MYVIFMRC' | restart<cr><br />
</source><br />
<br />
It does the following:<br />
<br />
# Saves current state to <code>vifminfo</code>.<br />
# Spawns editor (we don't want it to be detached from current console when inside terminal multiplexer, hence <code>%n</code> macro is used).<br />
# Reloads all configuration.<br />
<br />
Alternatively one could use <code>:source</code> command instead:<br />
<br />
<source lang="vim"><br />
nnoremap ,c :execute ':!%n${EDITOR:-vim} $MYVIFMRC' | source $MYVIFMRC<cr><br />
</source><br />
<br />
It's fine too, but is somewhat less predictable because previous state is<br />
combined with the new one. Using <code>:restart</code> ensures that new<br />
settings are applied to much more sane environment that saves one from possible<br />
unexpected side effects of combining previous configuration with the new one.<br />
<br />
[[Category:Manual]]</div>176.14.204.181