Giter Site home page Giter Site logo

embear / vim-localvimrc Goto Github PK

View Code? Open in Web Editor NEW
476.0 10.0 27.0 425 KB

Search local vimrc files (".lvimrc") in the tree (root dir up to current dir) and load them.

Home Page: http://www.vim.org/scripts/script.php?script_id=441

License: GNU General Public License v3.0

Shell 5.15% Makefile 2.11% Vim Script 92.75%

vim-localvimrc's Introduction

Localvimrc

This plugin searches for local vimrc files in the file system tree of the currently opened file. It searches for all ".lvimrc" files from the directory of the file up to the root directory. By default those files are loaded in order from the root directory to the directory of the file. The filename and amount of loaded files are customizable through global variables.

For security reasons it the plugin asks for confirmation before loading a local vimrc file and loads it using |:sandbox| command. The plugin asks once per session and local vimrc before loading it, if the file didn't change since previous loading.

It is possible to define a whitelist and a blacklist of local vimrc files that are loaded or ignored unconditionally.

The plugin can be found on GitHub and VIM online.

Installation

Using a vimball archive

Download the archive at VIM online and run

vim -c 'so %|q' localvimrc.vmb

Using Vim 8 package management

This is an elegant way to separate plugins from each other and be easily able to completely remove a plugin later.

mkdir -p ~/.vim/pack/localvimrc/start/
git clone --depth 1 https://github.com/embear/vim-localvimrc.git ~/.vim/pack/localvimrc/start/localvimrc
vim -c 'packloadall|helptags ALL'

Using a third party package manager

If the installed vim is older than version 8 it is possible to use a third party package manager. For example install vim-plug and add the following to your global vimrc:

call plug#begin()

Plug 'embear/vim-localvimrc'

call plug#end()

Then actually install the plugin:

vim -c 'PlugInstall'

Other options for a package manager are vundle, dein, neobundle, pathogen or packer.

Commands

The LocalVimRC command

Resource all local vimrc files for the current buffer.

The LocalVimRCClear command

Clear all stored decisions made in the past, when the plugin asked about sourcing a local vimrc file.

The LocalVimRCCleanup command

Remove all stored decisions for local vimrc files that no longer exist.

The LocalVimRCForget command

Remove stored decisions for given local vimrc files.

The LocalVimRCEdit command

Open the local vimrc file for the current buffer in an split window for editing. If more than one local vimrc file has been sourced, the user can decide which file to edit.

The LocalVimRCEnable command

Globally enable the loading of local vimrc files if loading has been disabled by |LocalVimRCDisable| or by setting |g:localvimrc_enable| to 0 during startup.

Enabling local vimrc using this command will trigger loading of local vimrc files for the currently active buffer. It will not load the local vimrc files for any other buffer. This will be done by an autocommand later when another buffer gets active and the configured |g:localvimrc_event| autocommand gets active. This is the case for the default |BufWinEnter|.

The LocalVimRCDisable command

Globally disable the loading of local vimrc files if loading has been disabled by |LocalVimRCEnable| or by setting |g:localvimrc_enable| to 1 during startup.

The LocalVimRCDebugShow command

Show all stored debugging messages. To see any message with this command debugging needs to be enabled with |g:localvimrc_debug|. The number of messages stored and printed can be limited using the setting |g:localvimrc_debug_lines|.

The LocalVimRCDebugDump command

Write all stored debugging messages to given file. To write any message with this command debugging needs to be enabled with |g:localvimrc_debug|. The number of messages stored and written can be limited using the setting |g:localvimrc_debug_lines|.

Functions

The LocalVimRCFinish function

After a call to this function the sourcing of any remaining local vimrc files will be skipped. In combination with the |g:localvimrc_reverse| option it is possible to end the processing of local vimrc files for example at the root of the project by adding the following command to the local vimrc file in the root of the project:

call LocalVimRCFinish()

Variables

The plugin provides several convenience variables to make it easier to set up path dependent setting like for example makeprg. These variables are only available inside your local vimrc file because they are only unambiguous there.

Adding the following lines to a local vimrc in the root directory of a project modify the behavior of |:make| to change into a build directory and call make there:

let &l:makeprg="cd ".g:localvimrc_script_dir_unresolved."/build && make"

NOTE:

This is only possible if you disable sandbox mode.


Other variables provide a way to prevent multiple execution of commands. They can be used to implement guards:

" do stuff you want to do on every buffer enter event

" guard to end loading if it has been loaded for the currently edited file
if g:localvimrc_sourced_once_for_file
  finish
endif

" do stuff you want to do only once for a edited file

" guard to end loading if it has been loaded for the running vim instance
if g:localvimrc_sourced_once
  finish
endif

" do stuff you want to do only once for a running vim instance

The g:localvimrc_file variable

Fully qualified file name of file that triggered loading the local vimrc file.

The g:localvimrc_file_dir variable

Fully qualified directory of file that triggered loading the local vimrc file.

The g:localvimrc_script variable

Fully qualified and resolved file name of the currently loaded local vimrc file.

The g:localvimrc_script_dir variable

Fully qualified and resolved directory of the currently loaded local vimrc file.

The g:localvimrc_script_unresolved variable

Fully qualified but unresolved file name of the currently loaded local vimrc file.

The g:localvimrc_script_dir_unresolved variable

Fully qualified but unresolved directory of the currently loaded local vimrc file.

The g:localvimrc_sourced_once variable

Set to 1 if the currently loaded local vimrc file had already been loaded in this session. Set to 0 otherwise.

The g:localvimrc_sourced_once_for_file setting

Set to 1 if the currently loaded local vimrc file had already been loaded in this session for the currently edited file. Set to 0 otherwise.

Settings

To change settings from their default add similar line to your global |vimrc| file.

let g:option_name=option_value

The g:localvimrc_enable setting

Globally enable/disable loading of local vimrc files globally. The behavior can be changed during runtime using the commands |LocalVimRCEnable| and |LocalVimRCDisable|.

  • Value 0: Disable loading of any local vimrc files.
  • Value 1: Enable loading of local vimrc files.
  • Default: 1

The g:localvimrc_name setting

List of filenames of local vimrc files. The given name can include a directory name such as ".config/localvimrc".

Previous versions of localvimrc only supported a single file as string. This is still supported for backward compatibility.

By default the local vimrc files are expected to contain vim script. For Neovim there is additional support for Lua. In order to use Lua code in the local vimrc, the file name must have the extension .lua.

  • Default: [ ".lvimrc" ]

The g:localvimrc_event setting

List of autocommand events that trigger local vimrc file loading.

  • Default: [ "BufWinEnter" ]

For more information see |autocmd-events|.


NOTE:

BufWinEnter is the default to enable lines like

setlocal colorcolumn=+1

in the local vimrc file. Settings "local to window" need to be set for every time a buffer is displayed in a window.

Because the plugin searches local vimrc files in the path of the currently opened file not all autocommand events make sense. For example the event |VimEnter| might cause problems. When that event is emitted it is possible that no file is opened but some temporary buffer is currently shown. This will lead to an unexpected behavior. If you would like to apply settings only once per running Vim instance please use |g:localvimrc_sourced_once_for_file| and |g:localvimrc_sourced_once|. An example how to use those variables in a local vimrc file is described in the introduction to |localvimrc-variables|.


The g:localvimrc_event_pattern setting

String defining the pattern for which the autocommand events trigger local vimrc file loading.

  • Default: "*"

For more information see |autocmd-patterns|.

The g:localvimrc_reverse setting

Reverse behavior of loading local vimrc files.

  • Value 0: Load files in order from root directory to directory of the file.
  • Value 1: Load files in order from directory of the file to root directory.
  • Default: 0

The g:localvimrc_count setting

On the way from root, the last localvimrc_count files are sourced.

NOTE:

This might load files not located in the edited files directory or even not located in the projects directory. If this is of concern use the g:localvimrc_file_directory_only setting.

  • Default: -1 (all)

The g:localvimrc_file_directory_only setting

Just use local vimrc file located in the edited files directory.

NOTE:

This might end in not loading any local vimrc files at all. If limiting the number of loaded local vimrc files is of concern use the g:localvimrc_count setting.

  • Value 0: Load all local vimrc files in the tree from root to file.
  • Value 1: Load only file in the same directory as edited file.
  • Default: 0

The g:localvimrc_sandbox setting

Source the found local vimrc files in a sandbox for security reasons.

  • Value 0: Don't load vimrc file in a sandbox.
  • Value 1: Load vimrc file in a sandbox.
  • Default: 1

The g:localvimrc_ask setting

Ask before sourcing any local vimrc file. In a vim session the question is only asked once as long as the local vimrc file has not been changed.

  • Value 0: Don't ask before loading a vimrc file.
  • Value 1: Ask before loading a vimrc file.
  • Default: 1

The g:localvimrc_persistent setting

Make the decisions given when asked before sourcing local vimrc files persistent over multiple vim runs and instances. The decisions are written to the file defined by and |g:localvimrc_persistence_file|.

  • Value 0: Don't store and restore any decisions.
  • Value 1: Store and restore decisions only if the answer was given in upper case (Y/N/A).
  • Value 2: Store and restore all decisions.
  • Default: 0

The g:localvimrc_persistence_file setting

Filename used for storing persistent decisions made when asked before sourcing local vimrc files.

  • Default (Unix): "$HOME/.localvimrc_persistent"
  • Default (Windows): "$HOME/_localvimrc_persistent"

The g:localvimrc_whitelist setting

If a local vimrc file matches the regular expression given by |g:localvimrc_whitelist| this file is loaded unconditionally.

Files matching |g:localvimrc_whitelist| are sourced even if they are matched by |g:localvimrc_blacklist|.

See |regular-expression| for patterns that are accepted.

Example:

" whitelist all local vimrc files in users project foo and bar
let g:localvimrc_whitelist='/home/user/projects/\(foo\|bar\)/.*'

" whitelist can also use lists of patterns
let g:localvimrc_whitelist=['/home/user/project1/', '/opt/project2/', '/usr/local/projects/vim-[^/]*/']
  • Default: No whitelist

The g:localvimrc_blacklist setting

If a local vimrc file matches the regular expression given by |g:localvimrc_blacklist| this file is skipped unconditionally.

Files matching |g:localvimrc_whitelist| are sourced even if they are matched by |g:localvimrc_blacklist|.

See |regular-expression| for patterns that are accepted.

Example:

" blacklist all local vimrc files in shared project directory
let g:localvimrc_blacklist='/share/projects/.*'

" blacklist can also use lists of patterns
let g:localvimrc_blacklist=['/share/projects/.*', '/usr/share/other-projects/.*']
  • Default: No blacklist

The g:localvimrc_autocmd setting

Emit autocommands |LocalVimRCPre| before and |LocalVimRCPost| after sourcing every local vimrc file.

  • Default: 1

The g:localvimrc_python2_enable setting

Enable probing whether python 2 is available and usable for calculating local vimrc file checksums, in case |sha256()| is not available.

  • Default: 1

The g:localvimrc_python3_enable setting

Enable probing whether python 3 is available and usable for calculating local vimrc file checksums, in case |sha256()| is not available.

  • Default: 1

The g:localvimrc_debug setting

Debug level for this script. The messages can be shown with |LocalVimRCDebugShow| or written to a file with |LocalVimRCDebugDump|.

  • Default: 0

The g:localvimrc_debug_lines setting

Limit for the number of debug messages stored. The messages can be shown with |LocalVimRCDebugShow| or written to a file with |LocalVimRCDebugDump|.

  • Default: 100

Autocommands

If enabled localvimrc emits autocommands before and after sourcing a local vimrc file. The autocommands are emitted as |User| events. Because of that commands need to be registered in the following way:

autocmd User LocalVimRCPre  echom 'before loading local vimrc'
autocmd User LocalVimRCPost echom 'after loading local vimrc'

The LocalVimRCPre autocommand

This autocommand is emitted right before sourcing each local vimrc file.

The LocalVimRCPost autocommand

This autocommands is emitted right after sourcing each local vimrc file.

Frequently Asked Questions

modeline settings are overwritten by local vimrc

Depending on the |g:localvimrc_event| that is used to trigger loading local vimrc files it is possible that |modeline| already had been parsed. This might be cause problems. If for example there is set ts=8 sts=4 sw=4 et in the local vimrc and a Makefile contains # vim: ts=4 sts=0 sw=4 noet this modeline will not get applied with default settings of localvimrc. There are two possibilities to solve this.

The first solution is to use |BufRead| as value for |g:localvimrc_event|. This event is emitted by Vim before modelines are processed.

The second solution is to move all those settings to the local vimrc file and use different settings depending on the |filetype|:

if &ft == "make"
  setl ts=4 sts=0 sw=4 noet
else
  setl ts=8 sts=4 sw=4 et
endif

Project specific settings for other plugins are ignored

Most plugins require to have their configuration variables set when the plugin is loaded. If you want to have project specific settings for those plugins you run into a chicken and egg problem. This is because localvimrc is only able to load the project specific configuration when a buffer in the project is loaded. By that time the other plugins are already loaded and the project specific configurations are most likely ignored. A solution to this is to make the plugin you want to configure an optional plugin (see |:packadd|). This way it is possible to do the settings in the local vimrc file and activate the plugin afterwards. To do so add something like this to your local vimrc file:

" NOTE: <PLUGIN> needs to be replaced with the directory name of the plugin
if !g:localvimrc_sourced_once
  " add your <PLUGIN> settings here
  let g:plugin_setting = 1000

  " late loading of plugin
  packadd <PLUGIN>
endif

Contribute

To contact the author (Markus Braun), please send an email to [email protected]

If you think this plugin could be improved, fork on GitHub and send a pull request or just tell me your ideas.

If you encounter a bug please enable debugging, export debugging messages to a file and create a bug report on GitHub. Debug messages can be enabled temporary and exported to a file called localvimrc_debug.txt on command line with the following command:

vim --cmd "let g:localvimrc_debug=99" -c "LocalVimRCDebugDump localvimrc_debug.txt" your_file

Credits

  • Simon Howard for his hint about "sandbox"
  • Mark Weber for the idea of using checksums
  • Daniel Hahler for various patches
  • Justin M. Keyes for ideas to improve this plugin
  • Lars Winderling for whitelist/blacklist patch
  • Michon van Dooren for autocommands patch
  • Benoit de Chezell for fix with nested execution
  • Huy Le for patch to support Lua scripts in Neovim

Changelog

vX.X.X : XXXX-XX-XX

  • add command |LocalVimRCDebugDump| to write debug messages to a file.
  • add support for Lua scripts when using Neovim.
  • for search path fallback to the current working directory, it checks for an existing directory of the current buffer rather than an empty directory name.

v3.1.0 : 2020-05-20

  • add option to disable probing of Python versions
  • prevent recursive sourcing of local vimrc files
  • better handling of syntax errors in sourced local vimrc files

v3.0.1 : 2018-08-21

  • fix a compatibility issue with unavailable |v:true| and |v:false| in Vim version 7.4

v3.0.0 : 2018-08-14

  • use SHA256 as for calculating checksums and use FNV-1 as fallback.
  • add command |LocalVimRCCleanup| to remove all unusable persistence data.
  • add command |LocalVimRCForget| to remove persistence data for given files.
  • add command |LocalVimRCDebugShow| to show debug messages.
  • add setting |g:localvimrc_debug_lines| to limit the number of stored debug messages.

v2.7.0 : 2018-03-19

  • add setting |g:localvimrc_enable| and commands |LocalVimRCEnable| and |LocalVimRCDisable| to globally disable processing of local vimrc files.
  • add setting |g:localvimrc_event_pattern| to change the pattern for which the autocommand is executed.

v2.6.1 : 2018-02-20

  • fix a bug with missing uniq() in Vim version 7.4

v2.6.0 : 2018-01-22

  • add command |LocalVimRCEdit| to edit sourced local vimrc files for the current buffer.

v2.5.0 : 2017-03-08

  • add unit tests.
  • settings |g:localvimrc_whitelist| and |g:localvimrc_blacklist| now takes optionally a list of regular expressions.
  • add convenience variables |g:localvimrc_script_unresolved| and |g:localvimrc_script_dir_unresolved|.
  • add ability to view local vimrc before sourcing when |g:localvimrc_ask| is enabled.
  • emit autocommands before and after sourcing files.
  • add |g:localvimrc_file_directory_only| to limit sourcing to local vimrc files in the same directory as the edited file.
  • add |LocalVimRCFinish| function to stop loading of remaining local vimrc files from within a local vimrc file.

v2.4.0 : 2016-02-05

  • add setting |g:localvimrc_event| which defines the autocommand events that trigger local vimrc file loading.
  • don't lose persistence file on full partitions.
  • make it possible to supply a list of local vimrc filenames in |g:localvimrc_name|.
  • ask user when sourcing local vimrc fails and |g:localvimrc_sandbox| and |g:localvimrc_ask| is set whether the file should be sourced without sandbox.
  • fix a bug where local vimrc files are sourced in wrong order when some of them are symlinks to a different directory.

v2.3.0 : 2014-02-06

  • private persistence file to enable persistence over concurrent vim instances.
  • add convenience variables |g:localvimrc_sourced_once| and |g:localvimrc_sourced_once_for_file|.

v2.2.0 : 2013-11-09

  • remove redraw calls for better performance and fixing a bug on windows.
  • load local vimrc on event BufWinEnter to fix a bug with window local settings.
  • add |g:localvimrc_reverse| to change order of sourcing local vimrc files.
  • add convenience variables |g:localvimrc_file|, |g:localvimrc_file_dir|, |g:localvimrc_script| and |g:localvimrc_script_dir|.

v2.1.0 : 2012-09-25

  • add possibility to make decisions persistent.
  • use full file path when storing decisions.

v2.0.0 : 2012-04-05

  • added |g:localvimrc_whitelist| and |g:localvimrc_blacklist| settings.
  • ask only once per session and local vimrc before loading it, if it didn't change.

v2758 : 2009-05-11

  • source .lvimrc in a sandbox to better maintain security, configurable using |g:localvimrc_sandbox|.
  • ask user before sourcing any local vimrc file, configurable using |g:localvimrc_ask|.

v1870 : 2007-09-28

  • new configuration variable |g:localvimrc_name| to change filename.
  • new configuration variable |g:localvimrc_count| to limit number of loaded files.

v1613 : 2007-04-05

  • switched to arrays in vim 7.
  • escape file/path names correctly.

v1.2 : 2002-10-09

  • initial version

vim-localvimrc's People

Contributors

bew avatar blueyed avatar chaoren avatar embear avatar georgetaveras1231 avatar huynle avatar jszakmeister avatar kahalemakai avatar lethal-guitar avatar s0undt3ch avatar uniqp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-localvimrc's Issues

Environment variable for specifying path to localvimrc file

It would be great if localvimrc could read $LOCALVIMRC_FILE (or some other environment variable) for a path to the .lvimrc file, falling back to the current search directories/filenames if the variable is unset.

This would be beneficial for users of Nix development shells to be able to define their .lvimrc file as part of their development shell and have localvimrc use it without any further manual intervention (e.g. symlinking the path from $LOCALVIMRC_FILE to .lvimrc whenever you change the development shell).

For example, when working on rustc, I have a .lvimrc file - I define this file in my development shell alongside all the other stuff, and I update the symlink to that file in the working directory whenever the file changes - if I didn't have to do that, and could just enter the development shell and always have localvimrc use the most recent version of the .lvimrc file, then that'd be great.

Thanks!

feature request: prompt for sandbox disable, remember choice

Seems g:localvimrc_sandbox is only a global option. I'd rather not enable it globally, but I would like to enable it for an explicit lvimrc. It'd be great if the plugin detected E48: Not allowed in sandbox and then prompted the user to allow the sandbox for that specific vimrc. That choice should also be persisted.

P.S.: This is the nicest implementation of the "local vimrc" concept that I've seen, so thank you!

After commit f35ee18959bd9405b8416c8ac2c42040a61cdbd3 started getting errors upon load in neovim

Fedora 28, both python 2.7.15 and python 3.6.6 are installed, in neovim:

NVIM v0.3.0
Build type: RelWithDebInfo
Lua 5.3
Compilation: /usr/bin/cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wconversion -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -DNVIM_UNIBI_HAS_VAR_FROM -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/builddir/build/BUILD/neovim-0.3.0/build/config -I/builddir/build/BUILD/neovim-0.3.0/src -I/usr/include -I/builddir/build/BUILD/neovim-0.3.0/build/src/nvim/auto -I/builddir/build/BUILD/neovim-0.3.0/build/include
Compiled by mockbuild

Features: +acl +iconv +jemalloc +tui

when started getting errors like:

Failed to load python host. You can try to see what happened by starting nvim with $NVIM_...LE set and opening the generated log file. Also, the host stderr is available in messages.            
Error detected while processing function <SNR>28_LocalVimRC[95]..<SNR>28_LocalVimRCCheckChecksum[2]..<SNR>28_LocalVimRCCalcChecksum[5]..<SNR>28_LocalVimRcCalcSHA256:                             
line   21:                                                                                                                                                                                        
E121: Undefined variable: l:checksum                                                                                                                                                              
E15: Invalid expression: l:checksum                                                                                                                                                               
Error detected while processing function <SNR>28_LocalVimRC[350]..<SNR>28_LocalVimRCCalcChecksum[5]..<SNR>28_LocalVimRcCalcSHA256:                                                                
line   21:                                                                                                                                                                                        
E121: Undefined variable: l:checksum                                                                                                                                                              
E15: Invalid expression: l:checksum

My configuration

Add a warning about how to use this with Janus?

Hi there,

I'm not sure this is something you'd want to do, but even if not it can be logged here even as a closed issue for anyone who happens to come across this problem.

I use https://github.com/carlhuda/janus with vim, and when I started using localvimrc I wanted to add the option to make the decision persistent. I tried it out at first, as well as the sandbox and the whitelist and couldn't get it to work.

After a few tries I thought that something else could be interfering with it, so I decided to add it to the .vimrc.before file, which Janus provides. This fixed the problem.

I'm not entirely sure why this happens, and if someone could shed some light here that would be great, but it does fix the problem.

My suggestion would be to add a tip about this to the readme, or possibly a suggestion of things that could interfere with this.

Allow to remember decision for specific local vimrc files

Since localvimrc appears to have a function for checksumming already, it would be nice having the option to remember the decision to (not) load a specific file, across multiple vim sessions.

localvimrc might save a list of approved or unapproved files in viminfo or a local file. This list would contain the checksum of the file and re-ask the user if it was changed.

Syntax error in catch clause

The following line in localvimrc.vim generates a syntax error:

catch ^Vim\%((\a\+)\)\=:E48

The correct syntax should include delimiters:

catch /^Vim\%((\a\+)\)\=:E48/

(This is seen in Neovim v0.4.3. Maybe vim itself is a bit more lax on the syntax?)

LocalVimRCMatchAny: No previous substitute regular expression

Thanks for this great plugin! When opening a file affected by a .lvimrc file, I am seeing the following error:

<SNR>34_LocalVimRCMatchAny:
line    2:
E33: No previous substitute regular expression
Press ENTER or type command to continue

The plugin recovers well and everything else appears to work.

Vim version:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Dec 19 2020 21:23:05)
macOS version
Included patches: 1-2164
Compiled by [email protected]
Huge version with MacVim GUI.  Features included (+) or not (-):

Get directory/path of .lvimrc file from within

I would like to extend path in a .lvimrc file, and the directory to be added should be relative to the .lvimrc file.

Is it possible to get path of the currently processed file in VimL?
If not, would it possible/feasible for vim-localvimrc to provide a variable containing this information?

Symlink problem

Helloe

My localvimrc in my project is a symlink.
Because of that, when localvimrc is sourced, g:localvimrc_script and g:localvimrc_script_dir contains the resolved path of the symlink, but I need a way to know the symlink path. I have failed to find that path. Is there a way, other than to hard-code the path in the localvimrc file?

Thank you

Windows 10 issue

Hi,
I am using your plugin on Windows 10 (yeah, I know :( ). And it pops up the confirmation dialog on every file open, even if in the same directory. The dialog also doesn't accept 'y' or 'yes' -- it re-displays the dialog. It will only disappear with ENTER. My .lvimrc is a couple of directories up the tree (root of the project). This is probably pilot error, but help is appreciated.

My need for this plugin is (at least initially), to reset the ctags, and NERDTree bookmarks.
I will attach my .lvimrc and _vimrc

lvimrc.txt
vimrc.txt

It will also sometimes display this as well -- usually after the first dialog is closed:

image

g:localvimrc_persistence_file might end up empty if partition is full

It just happened to me that my home partition ran full, and this caused the file storing the persistent choices (g:localvimrc_persistence_file) to end up empty.

It would be nice if vim-localvimrc would handle this better, e.g. by writing it to a temporary file first and then moving this one.

Also, currently the return code of writefile() is not being checked at all.

Ordering of files incorrect when using symlinks

I have a project with the following lvimrc files:

/home/nick/project/.lvimrc -> /home/nick/dotfiles/project/lvimrc
/home/nick/project/foo/bar/.lvimrc

When building l:rcfiles, it seems that symlinks are resolved before sorting such that my root-level lvimrc file is sourced after the subdirectory-level file. Since my nested lvimrc file only exists to override options from the root-level file, having the ordering wrong makes the nested file useless.

I can use g:localvimrc_reverse to work around this, but it's a misuse of the setting.

Helper to check if the lvimrc file has been sourced already

I am using the in my .lvimrc files to prevent certain blocks (usually the whole file) not to be sourced multiple times:

if MyLocalVimrcAlreadySourced("<sfile>")
    finish
endif

This is the function:

" Helper method for .lvimrc files to finish
fun! MyLocalVimrcAlreadySourced(sfile)
    let sfile = expand(a:sfile)
    let guard_key = expand(sfile).getftime(sfile)
    if exists('b:local_vimrc_sourced')
        if type(b:local_vimrc_sourced) != type({})
            echomsg "warning: b:local_vimrc_sourced is not a dict!"
            let b:local_vimrc_sourced = {}
        endif
        if has_key(b:local_vimrc_sourced, guard_key)
            return 1
        endif
    else
        let b:local_vimrc_sourced = {}
    endif
    let b:local_vimrc_sourced[guard_key] = 1
    return 0
endfun

This is what I had in mind with my proposal at #7 (comment) .

Add setting to disable auto-loading on start

Hello,

I don't want to save my loading decision in a persistent file, but I don't want either to choose what to do at every vim startup (for example when editing an unrelated file, or writing a commit message).

Can you add a setting like g:localvimrc_load_on_startup that would be defaulted to 1.

Thank you

Autoload verified files only

Hello, is there a way to auto load (on vim's startup) only verified files from persistent file?

(from the docs it seems it's not possible)

feature request: g:localvimrc_name should allow a list

Some projects have an lvimrc in source control, in a subdirectory such as contrib/. To detect that, I can set:

 let g:localvimrc_name = "contrib/.lvimrc"

This works well. But it would be much nicer if I could give the plugin a list, like this:

 let g:localvimrc_name = [".lvimrc", "contrib/.lvimrc"]

So that it searches for both. Of course, the non-list variant can still be supported by just checking type(g:localvimrc_name) == 1.

By the way, it's extremely useful that subdirectories (like "contrib/.lvimrc")--not just filenames--are supported. Not sure if that was intended, but I hope it continues to be officially supported, and I suggest documenting it explicitly :)

Opens the Terminal.app while I'm using iTerm

Hi,
I could not find any issue which targets this topic and I don't know where to look for a solution, so ..
This plugin seems to start the Terminal.app always after I confirm the question localvimrc: source .lvimrc? ([y]es/[n]o/[a]ll/[s]how/[q]uit). I have always to close it, since I'm using iTerm. Is there a way to prevent this behavior?
Thanks in advance.

E714/E715/E706 during startup

I do not know how I messed things up, but I am currently getting the following errors during startup and when accepting a file permanently:

Error detected while processing function <SNR>65_LocalVimRC..<SNR>65_LocalVimRCReadPersistent:
line    4:
E715: Dictionary required
E714: List required
line   12:
E706: Variable type mismatch for: s:localvimrc_checksums
Error detected while processing function <SNR>65_LocalVimRC..<SNR>65_LocalVimRCWritePersistent:
line   12:
E706: Variable type mismatch for: g:LOCALVIMRC_ANSWERS
line   14:
E706: Variable type mismatch for: g:LOCALVIMRC_CHECKSUMS
Error detected while processing function <SNR>65_LocalVimRC..<SNR>65_LocalVimRCReadPersistent:
line    4:
E715: Dictionary required
Error detected while processing function <SNR>65_LocalVimRC..<SNR>65_LocalVimRCReadPersistent:
line    4:
E714: List required
Error detected while processing function <SNR>65_LocalVimRC..<SNR>65_LocalVimRCReadPersistent:
line   12:
E706: Variable type mismatch for: s:localvimrc_checksums
Error detected while processing function <SNR>65_LocalVimRC..<SNR>65_LocalVimRCWritePersistent:
line   12:
E706: Variable type mismatch for: g:LOCALVIMRC_ANSWERS
Error detected while processing function <SNR>65_LocalVimRC..<SNR>65_LocalVimRCWritePersistent:
line   14:
E706: Variable type mismatch for: g:LOCALVIMRC_CHECKSUMS

The entries from ~/.viminfo:

!LOCALVIMRC_CHECKSUMS   STR !FLOAT_TYPE NUM 5
!LOCALVIMRC_ANSWERS STR !DICT_TYPE  NUM 4

This is with tag v2.1.0 (3c55db2).

localvimrc should handle "corrupted data" better - and of course make sure that the data is being written/provided correctly in the first place.
(I might have triggered it while fiddling with some "echoerr" in a VimEnter function)

How do I disable searching lvimrc in the file tree?

Case 1
I have a .lvimrc in root of my project ~/project/.lvimrc. I open Vim from root of the project and the plugin loads the file. Which is the perfect behaviour.

Case 2
On the other hand, if I change directory to ~/project/child/ and open Vim there. The plugin searches upward and finds and load .lvimrc file.

In case 2, I want to disable searching upward. I want plugin to search just in the current directory. How do I disable "search upward through the file tree" feature of the plugin?

Thank you

Breaking Python Loading Sequence

Hi,

I have noticed that if none of the plugins that are loading before vim-localvimrc are not invoking py2, vim-localvimrc chooses to invoke py3. This breaks any of the plugins that still rely on py2 and are being loaded after vim-localvimrc.

Could you please add an option for explicitly setting the python version to py2. The option can be empty by default and users who would still rely on py2 can use that entry point to set the python to 2.x.

Thanks.

localvimrc_persistence_file related errors.

Since I updated my local repo of localvimrc this morning I've had some strange errors showing :

~/ $ gvim
Error detected while processing ...../vim-localvimrc/plugin/localvimrc.vim:
line  100:
E121: Undefined variable: win16
E116: Invalid arguments for function has(win16) || has(win32) || has(win64) || has(win95)
E15: Invalid expression: has(win16) || has(win32) || has(win64) || has(win95)

To be honest, I have never done any kind of vim scripting so I'll rely on your expertise. However, I tried to do my homework and I found a similar way to do the OS detection. The only difference seems to be that the code snippet I found was single-quotes around the winXX names.
After applying the changes locally, no more errors.

Would you like me to fill a proper PR for this?

Thanks for the work on this. Much appreciated.

path_mapping not working when using local vimrc

I've been using your plugin for a while already, without any issues. Thanks for that!!

But nowadays i'm trying to move all my development servers to a dockerized environmnent.
The problem that arises with this, is that each one of the projects will have different path_maps. For instance, one will have

let g:vdebug_options['path_maps'] = {"/var/www/": "/home/juan/sandbox/project1/"} 

while another might have

let g:vdebug_options['path_maps'] = {"/var/www/": "/home/juan/sandbox/project2/"} 

In order to make it work, I introduced the plugin https://github.com/embear/vim-localvimrc which allows me to configure those things in a by project basis, just adding a .lvimrc file with that content in the corresponding project.

Now, the problem I'm facing, is that the path_map is not taken into account the first time I run de debugger. If I open vim, run the debbuger, stop it and then set the breakpoint and start the debbuger again, it works as intended. But if I just open vim, set the breakpoint and run the debugger, it doesn't work

You can see the logs in this gist: https://gist.github.com/Epilgrim/28a7eb010b8135d4e781

Explanation of the files:
vdebug.no_lvimrc.log: log without anything to do with lvimrc. the options defined in the good old ~/.vimrc

vdebug.lvimrc.1.log: log using lvimrc. The breakpoint was not taken into account. Steps: open vim, set breakpoint, start vdebug (F5)

vdebug.lvimrc.2.log: log using lvimrc. The breakpoint was taken into account. Steps: open vim, start vdebug (F5), stop vdebug (ctrl+c), set breakpoint, start vdebug (F5)

Although basically everything works if I start and stop the debugger, it's a bit annoying sometimes. Do you have any clue what might be going on here?

Error with Sandbox

I am getting this all the time

localvimrc: unable to use 'sandbox' for

autocmd are not called

I am unable to set up an autocmd with the LocalVimRCPre or LocalVimRCPost commands.

Sample configuration:

" ...after plug#begin()
Plug 'embear/vim-localvimrc'
autocmd LocalVimRCPost echom 'loaded local vimrc'

Output:

Error detected while processing <REDACTED>:
line  132:
E216: No such group or event: LocalVimRCPost echom 'loaded local vimrc'

Errors on Mac OS 10.12.5

When doing ":so %" I encountered the following errors:

Vimball Archive
extracted <README.md>: 383 lines
Error detected while processing function vimball#Vimball:
line  146:
"~/.vim/README.md" E212: Can't open file for writing
wrote /Users/robert/.vim/README.md
extracted <RELEASE.md>: 16 lines
"~/.vim/RELEASE.md" E212: Can't open file for writing
wrote /Users/robert/.vim/RELEASE.md
extracted <doc/localvimrc.txt>: 490 lines
line  113:
E739: Cannot create directory: /Users/robert/.vim/doc
line  146:
"~/.vim/doc/localvimrc.txt" E212: Can't open file for writing
wrote /Users/robert/.vim/doc/localvimrc.txt
extracted <plugin/localvimrc.vim>: 782 lines
line  113:
E739: Cannot create directory: /Users/robert/.vim/plugin
line  146:
"~/.vim/plugin/localvimrc.vim" E212: Can't open file for writing
wrote /Users/robert/.vim/plugin/localvimrc.vim
line  174:
E150: Not a directory: /Users/robert/.vim/doc
did helptags
Press ENTER or type command to continue

I'm using version 2.5.0 by https://vim.sourceforge.io/scripts/download_script.php?src_id=25017 And my VIM version is 7.4.8056. I do have a .vim directory under /Users/robert, but it's empty.

LocalVimRCWritePersistent is called always

I noticed, that LocalVimRCWritePersistent is called always - this could be skipped if there were no interactive questions being asked or if the answers/checksums haven't changed?!

(extracted from comment of issue #14)

Read/Write viminfo data (rviminfo/wviminfo)

When you start a second instance of Vim, it will not pickup any persistent answers from the first (still running) instance.

This could be achieved by (reading and) writing the viminfo file explicitly.

Since reading gets done automatically during startup, this is not necessary in this particular use case, but only if you want to get persistent answers from the second instance into the first one.

Here is how tmru does it, using a setting for this:
https://github.com/tomtom/tmru_vim/blob/master/plugin/tmru.vim#L65

This might help with the strange issue in #11.

The patch is rather simple, but should/might want to use a setting for this:

diff --git i/plugin/localvimrc.vim w/plugin/localvimrc.vim
index 5972b32..345caff 100644
--- i/plugin/localvimrc.vim
+++ w/plugin/localvimrc.vim
@@ -350,6 +350,7 @@ endfunction
function! s:LocalVimRCReadPersistent()
if (s:localvimrc_persistent >= 1)
    if stridx(&viminfo, "!") >= 0
+      rviminfo
    if exists("g:LOCALVIMRC_ANSWERS")
        " force g:LOCALVIMRC_ANSWERS to be a dictionary
        if (type(g:LOCALVIMRC_ANSWERS) != type({}))
@@ -398,6 +399,8 @@ function! s:LocalVimRCWritePersistent()
        call s:LocalVimRCDebug(3, "write answer persistent data: " . string(g:LOCALVIMRC_ANSWERS))
        let g:LOCALVIMRC_CHECKSUMS = l:persistent_checksums
        call s:LocalVimRCDebug(3, "write checksum persistent data: " . string(g:LOCALVIMRC_CHECKSUMS))
+
+        wviminfo
    else
        call s:LocalVimRCDebug(3, "viminfo setting has no '!' flag, no persistence available")
        call s:LocalVimRCError("viminfo setting has no '!' flag, no persistence available")

Use external file to store persistent answers (workaround for viminfo merge issues)

The viminfo file is not really useful across multiple instances of Vim, and therefore the persistent answers and checksums get overwritten / not remembered.

Using an external file optionally, configurable via a setting, would work around this.

Another option might be to not use a dict, but a separate variable pair for each localvimrc file being remembered - although I only guess that non-existent variables get merged (while a dict gets overwritten).

Reload .lvimrc

Hi, is it possible to reload the .lvimrc file without having to restart Vim?

persistent decisions should include cryptographically secure hash of the rc file

Currently the ~/.localvimrc_persistent file contains

/home/user/projectdir/.lvimrc|Y|Y|14rw-r--r--1515086833

It contains the rc file path and its metadata. I haven't looked at the source code yet but I assume that the metadata are used to detect changes to the rc file. I think that's a weak check. All that is needed is assurance that the sourced file is the same as when it was sourced for the first time and for that a cryptographic hash of the file is enough. I propose the following format:

version:metadata filename

which would look like this for the previous case

2:flags=YY:hash=037f1086f7296e09c28b7f7ef6e905094fca6e3e90af7549a69e3e8a43876c9e /home/user/projectdir/.lvimrc

The version field will allow making changes to the format of the file (for instance changing the default hash function). The metadata contains the SHA-256 hash of the file. I chose a different format because a) Having the filename at the end of the line makes it easy to store filenames with special characters and : is better for parsing (also, Vim's modeline uses it).

The only problem is that sha256sum or other utility (for example Python with crypto lib) may not be present on the system. In that case the plugin could fall back to using a mtime field (mtime=1515086833) but not by default.

For extra paranoid security: The plugin should create private copy in a temporary directory of every .lvimrc file it's going to source, and source it after it successfully validates its hash. The file on a filesystem can change between validating its hash and sourcing it. For example it may be on a Samba shared folder. Temporary directories are memory backed on contemporary distros and rc files are generally small.

Errors with non-sandboxed scripts when the script triggers a recursive lvimrc load

Repro steps:

I modified the plugin to add more debug bew/vim-localvimrc@da04133.

Minimal bug.vimrc (using vim-plug):

set nocompatible
call plug#begin('~/.config/nvim/plugged')
Plug 'embear/vim-localvimrc'
call plug#end()

let g:localvimrc_enable = 0
let g:localvimrc_debug = 1

Minimal .lvimrc:

call <SNR>12_LocalVimRCDebug(1, "from .lvimrc: before `bufdo write`")
bufdo write
call <SNR>12_LocalVimRCDebug(1, "from .lvimrc: after `bufdo write`")

Notice that I call the s:LocalVimRCDebug from the executed script, the script number is 12 for me on vim (it is 9 on neovim), but it might differ for you.

Open vim using: vim -u bug.vimrc file1 file2
Now run: :LocalVimRCEnable

It'll ask twice to load the .lvimrc file and accept the non-sandbox run. (not sure if it's intended)
Edit: With the fix I describe at the end, it asks only once, so I guess it was not intended.

Then you'll see the errors:

Error detected while processing function <SNR>12_LocalVimRCEnable[6]..<SNR>12_LocalVimRC:
line  343:
E108: No such variable: "g:localvimrc_file"
line  344:
E108: No such variable: "g:localvimrc_file_dir"
line  345:
E108: No such variable: "g:localvimrc_script"
line  346:
E108: No such variable: "g:localvimrc_script_dir"
line  347:
E108: No such variable: "g:localvimrc_script_unresolved"
line  348:
E108: No such variable: "g:localvimrc_script_dir_unresolved"
line  349:
E108: No such variable: "g:localvimrc_sourced_once"
line  350:
E108: No such variable: "g:localvimrc_sourced_once_for_file"

The debug logs (from :LocalVimRCDebugShow):

== START settings ================================
localvimrc_enable = "0"
localvimrc_name = "['.lvimrc']"
localvimrc_event = "['BufWinEnter']"
localvimrc_event_pattern = "'*'"
localvimrc_reverse = "0"
localvimrc_count = "-1"
localvimrc_file_directory_only = "0"
localvimrc_sandbox = "1"
localvimrc_ask = "1"
localvimrc_whitelist = "['^$']"
localvimrc_blacklist = "['^$']"
localvimrc_persistent = "0"
localvimrc_persistence_file = "'/home/lesell_b/.localvimrc_persistent'"
localvimrc_autocmd = "1"
localvimrc_python2_enable = "1"
localvimrc_python3_enable = "1"
localvimrc_debug = "1"
localvimrc_debug_lines = "100"
localvimrc_checksum_func = "function('sha256')"
localvimrc_python_command = "'not checked for python'"
== END settings ==================================
autocommand triggered on event BufWinEnter
== START LocalVimRC() ============================
localvimrc.vim 1
== END LocalVimRC() (localvimrc is disabled) =====


enable processing of local vimrc files
== START LocalVimRC() ============================
localvimrc.vim 1
found files: [{'resolved': '/tmp/lvimrc_bug/.lvimrc', 'unresolved': '/tmp/lvimrc_bug/.lvimrc'}]
candidate files: [{'resolved': '/tmp/lvimrc_bug/.lvimrc', 'unresolved': '/tmp/lvimrc_bug/.lvimrc'}]
from .lvimrc: before `bufdo write`
unable to use sandbox on '/tmp/lvimrc_bug/.lvimrc': Vim(bufdo):E48: Not allowed in sandbox: bufdo write (/tmp/lvimrc_bug/.lvimrc, line 2)

foo before execute file without sandbox
foo command is: source /tmp/lvimrc_bug/.lvimrc

from .lvimrc: before `bufdo write`

autocommand triggered on event BufWinEnter
== START LocalVimRC() ============================
localvimrc.vim 1
found files: [{'resolved': '/tmp/lvimrc_bug/.lvimrc', 'unresolved': '/tmp/lvimrc_bug/.lvimrc'}]
candidate files: [{'resolved': '/tmp/lvimrc_bug/.lvimrc', 'unresolved': '/tmp/lvimrc_bug/.lvimrc'}]
from .lvimrc: before `bufdo write`
unable to use sandbox on '/tmp/lvimrc_bug/.lvimrc': Vim(bufdo):E48: Not allowed in sandbox: bufdo write (/tmp/lvimrc_bug/.lvimrc, line 2)

foo before execute file without sandbox
foo command is: source /tmp/lvimrc_bug/.lvimrc

from .lvimrc: before `bufdo write`
from .lvimrc: after `bufdo write`

foo after execute file without sandbox
sourced (without sandbox) /tmp/lvimrc_bug/.lvimrc
foo remove global vars
foo after remove global vars
== END LocalVimRC() ==============================

from .lvimrc: after `bufdo write`

foo after execute file without sandbox
sourced (without sandbox) /tmp/lvimrc_bug/.lvimrc
foo remove global vars
foo after remove global vars
== END LocalVimRC() ==============================

(I added some spaces for reading convenience)

You can see that there is 2 invocation of LocalVimRC()!
This is visible in the logs: the second invocation is after from .lvimrc: before `bufdo write` and before the last from .lvimrc: after `bufdo write` .

What happens is that bufdo write will trigger the BufWinEnter event which will trigger the 2nd LocalVimRC().
I wonder why it only recurse once, maybe it is a security in autocmd

Solution?

I think a possible solution would be to add a guard around the .lvimrc script execution and at the beginning of LocalVimRC() to make sure it's not called (or it returned at the guard) during a .lvimrc execution.

WDYT?


Edit: With the mentionned fix it works perfectly, checkout my branch bew/vim-localvimrc@fix-recursive-call.
I can make a PR if you think it's a good way to fix this

Also, the debug logs are much cleaner:

[...]
enable processing of local vimrc files
== START LocalVimRC() ============================
localvimrc.vim 1
found files: [{'resolved': '/tmp/lvimrc_bug/.lvimrc', 'unresolved': '/tmp/lvimrc_bug/.lvimrc'}]
candidate files: [{'resolved': '/tmp/lvimrc_bug/.lvimrc', 'unresolved': '/tmp/lvimrc_bug/.lvimrc'}]
Executing script, command is: sandbox source /tmp/lvimrc_bug/.lvimrc
from .lvimrc: before `bufdo write`
unable to use sandbox on '/tmp/lvimrc_bug/.lvimrc': Vim(bufdo):E48: Not allowed in sandbox: bufdo write (/tmp/lvimrc_bug/.lvimrc, line 2)
Executing script, command is: source /tmp/lvimrc_bug/.lvimrc
from .lvimrc: before `bufdo write`
autocommand triggered on event BufWinEnter
== START LocalVimRC() ============================
localvimrc.vim 1
== END LocalVimRC() (exec already running) =======
from .lvimrc: after `bufdo write`
sourced (without sandbox) /tmp/lvimrc_bug/.lvimrc
== END LocalVimRC() ==============================

autocmd only works after changing buffer

If I put this content in .lvimrc:
au BufRead,BufNewFile *.c set sw=3

It only takes effect after I change buffers. To reproduce:

Open a foo.c in the same directory as the above .lvimrc

$ vim foo.c bar.c

Now when indenting foo.c, it'll use the default settings. If I change to bar.c (:bn) the new autocmd rule works, and I get shiftwidth 3. Going back to foo.c (:bp) makes it work on foo.c as well.

uniq function not found

Hello,

Thanks for the plugin! There are warnings due to uniq function missing in vim versions <= 7.3 (which is the default system vim in some OS X versions). Perhaps you could check for this explicitly as in other plugins?

Would like to have a file's modeline override what is in .lvimrc

If I have set ts=8 sts=4 sw=4 et in a project's .lvimrc file, then editing the projects' Makefiles becomes annoying, since make insists that the lines for recipes begin with a tab character.

I would like for the modeline (e.g., # vim: ts=4 sts=0 sw=4 noet) in a file to override the settings from the .lvimrc.

Example

I'm trying to au BufRead,BufNewFile,BufReadPost *.html set filetype=javascript but I really don't know how to do it in the _vimrc_local.vim file. I've also tryied to do it in a _vimrc_local.html file, but seams not to work.

How to reload the .lvimrc file through a specific function or event?

Hi,

I would like to have a variable in my .lvimrc file located in the root of my project that has a variable, let's say, a variable that sets a command like this:

g:my_variable = "testPython.py -my-args"

Let's assume that this is something I execute in a tmux session to test things. So I would like to be able to update that variable at any time, to, let's say, something like this:

g:my_variable = "testPython.py --with-aFuture"

And then when I call the function that executes my command, obviously I would like to refresh that variable.

Is there a way to force a refresh on the .lvimrc with a function? or attach it to a custom event? (I cannot think of a custom event that I can attach to a function like executeCommand()

Thanks.

LocalVimRCWritePersistent: E716: Key not present in Dictionary (s:localvimrc_checksums)

Error detected while processing function <SNR>83_LocalVimRC..<SNR>83_LocalVimRCWritePersistent:
line    6:
E716: Key not present in Dictionary: /foo/bar/.lvimrc

The code there is:

for l:rcfile in keys(l:persistent_answers)
    let l:persistent_checksums[l:rcfile] = s:localvimrc_checksums[l:rcfile]
endfor

This might get surrounded by try, but I think it's odd that this happens after all.

  try
    let l:persistent_checksums[l:rcfile] = s:localvimrc_checksums[l:rcfile]
  catch /^E716: /  " E716: Key not present in Dictionary
  endtry

This happened after :tj tagname in a running Vim instance.

I have removed the local :rviminfo/:wviminfo patch I had before, but other plugins (especially tmru) might interfere here by calling it.

I usually have multiple Vim instances running in parallel.

Problems finding lvimrc file on Windows

I'm fairly new to Vim, and having trouble getting this working under gvim 7.4 on Windows 7. At first the plugin wasn't able to find my _lvimrc files at all (I have g:localvimrc_name set to look for both _ and . prefixed files).

Eventually I was able to get it partially working by changing changing lines 181 & 183 (let l:directory = ...) to remove the calls to fnameescape(). However, the plugin still only seems to find _lvimrc files in the current directory, not in any parent directories.

My localvimrc settings are:

let g:localvimrc_event = ["VimEnter"]
let g:localvimrc_name = [".lvimrc","_lvimrc"]
let g:localvimrc_sandbox = 0
let g:localvimrc_persistent = 1
let g:localvimrc_debug = 100

It's probably also worth noting that I'm using the plugin through pathogen, and the project folder I'm working with is at a location which contains spaces in it's path.

I'm not sure if the problem is with the plugin, my setup or Vim itself, but let me know if you need more info. I will try to do some more investigation when I get a chance to see if another plugin or setting is possibly interfering with things somehow.

errors when starting vim

When I run vim on my server to edit a file, I recently get this error:

pepp@jet:~$ LANG=C vim .ssh/authorized_keys
Error detected while processing /home/pepp/.vim/plugged/vim-localvimrc/plugin/localvimrc.vim:
line  984:
E121: Undefined variable: v:false
E15: Invalid expression: v:false
line  986:
E121: Undefined variable: s:localvimrc_python_available
E15: Invalid expression: !s:localvimrc_python_available && has("pythonx")
line  996:
E121: Undefined variable: s:localvimrc_python_available
E15: Invalid expression: !s:localvimrc_python_available && has("python")
line 1006:
E121: Undefined variable: s:localvimrc_python_available
E15: Invalid expression: !s:localvimrc_python_available && has("python3")
Press ENTER or type command to continue

I use this version of vim:

pepp@jet:~$ LANG=C vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:43:18)
Included patches: 1-52
Extra patches: 8.0.0056
Modified by [email protected]
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
-clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   -perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            -ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl    -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions      

Please let me know if you need more information.

localvimrc globals lost/reset after Vim crash: "E15: Invalid expression: !LIST_TYPE^INUM^I3"

After Vim just crashed, I got these errors during startup:

E15: Invalid expression: !LIST_TYPE^INUM^I3
E15: Invalid expression: !DICT_TYPE^INUM^I4
Press ENTER or type command to continue

These refer to the localvimrc related viminfo entries:

# global variables:
!NUMBER_TYPE    NUM 0
!VCSCOMMAND_IDENTIFY_INEXACT    NUM -1
!VCSCOMMAND_IDENTIFY_EXACT  NUM 1
!LOCALVIMRC_CHECKSUMS   DIC !LIST_TYPE  NUM 3
!STRING_TYPE    NUM 1
!FUNCREF_TYPE   NUM 2
!LOCALVIMRC_ANSWERS DIC !DICT_TYPE  NUM 4
!FLOAT_TYPE NUM 5

This is not the first time this happened (see also issue #4), and as far as I can see only affects localvimrc.

I wonder if there's a pattern in how localvimrc handles the setting of its globals, which then results in these strange/invalid entries being written to ~/.viminfo?!

FWIW, this is the backtrace of the Vim crash, which apparently happened through Powerline (a status bar plugin):

#0  0x00007ffd56797257 in kill () at ../sysdeps/unix/syscall-template.S:81
#1  0x000000000054a11f in may_core_dump () at os_unix.c:3232
#2  0x000000000054a0c3 in mch_exit (r=1) at os_unix.c:3198
#3  0x00000000006393d0 in getout (exitval=1) at main.c:1504
#4  0x0000000000505e37 in preserve_exit () at misc1.c:9166
#5  0x000000000054813a in deathtrap (sigarg=11) at os_unix.c:1115
#6  <signal handler called>
#7  __GI___libc_free (mem=0x6f6d2365646f6d79) at malloc.c:2892
#8  0x000000000050a415 in vim_free (x=0x6f6d2365646f6d79) at misc2.c:1744
#9  0x00000000004a4eef in discard_exception (excp=0x21b09c0, was_finished=0) at ex_eval.c:603
#10 0x00000000004a4f45 in discard_current_exception () at ex_eval.c:616
#11 0x0000000000613908 in VimTryEnd () at if_py_both.h:562
#12 0x00000000006180f7 in FunctionCall (self=0x1d28090, argsObject=0x1e5c250, kwargs=0x0) at if_py_both.h:2674
#13 0x00007ffd50eb4483 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#14 0x00007ffd50ec4216 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#15 0x00007ffd50ec8b4d in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#16 0x00007ffd50ec8db5 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#17 0x00007ffd50eb4483 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#18 0x00007ffd50ec2db1 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#19 0x00007ffd50ec8b4d in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#20 0x00007ffd50ec67d8 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#21 0x00007ffd50ec8b4d in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#22 0x00007ffd50ec67d8 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#23 0x00007ffd50ec8b4d in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#24 0x00007ffd50ec67d8 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#25 0x00007ffd50ec8b4d in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#26 0x00007ffd50ec8e32 in PyEval_EvalCode () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#27 0x00007ffd50df55c9 in PyRun_StringFlags () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#28 0x000000000061cd74 in run_eval (cmd=0x1e9c420 "powerline.statusline(3)", rettv=0x7fff1aa05ac0, pygilstate=0x7fff1aa05284) at if_py_both.h:5162
#29 0x000000000061f944 in DoPyCommand (cmd=0x1e9c420 "powerline.statusline(3)", init_range=0x61c7b7 <init_range_eval>, run=0x61cd40 <run_eval>, arg=0x7fff1aa05ac0)
    at if_python.c:1023
#30 0x0000000000620315 in do_pyeval (str=0x1e9c420 "powerline.statusline(3)", rettv=0x7fff1aa05ac0) at if_python.c:1517
#31 0x000000000046baee in f_pyeval (argvars=0x7fff1aa05450, rettv=0x7fff1aa05ac0) at eval.c:14687
#32 0x0000000000462ab4 in call_func (funcname=0x1f47d22 "pyeval('powerline.statusline(3)')", len=6, rettv=0x7fff1aa05ac0, argcount=1, argvars=0x7fff1aa05450, 
    firstline=17, lastline=17, doesrange=0x7fff1aa055e4, evaluate=1, selfdict=0x0) at eval.c:8536
#33 0x000000000046251f in get_func_tv (name=0x1f47d22 "pyeval('powerline.statusline(3)')", len=6, rettv=0x7fff1aa05ac0, arg=0x7fff1aa05a78, firstline=17, lastline=17, 
    doesrange=0x7fff1aa055e4, evaluate=1, selfdict=0x0) at eval.c:8349
#34 0x000000000045dd3a in eval7 (arg=0x7fff1aa05a78, rettv=0x7fff1aa05ac0, evaluate=1, want_string=0) at eval.c:5158
#35 0x000000000045d5ef in eval6 (arg=0x7fff1aa05a78, rettv=0x7fff1aa05ac0, evaluate=1, want_string=0) at eval.c:4810
#36 0x000000000045d123 in eval5 (arg=0x7fff1aa05a78, rettv=0x7fff1aa05ac0, evaluate=1) at eval.c:4626
#37 0x000000000045c437 in eval4 (arg=0x7fff1aa05a78, rettv=0x7fff1aa05ac0, evaluate=1) at eval.c:4319
#38 0x000000000045c27a in eval3 (arg=0x7fff1aa05a78, rettv=0x7fff1aa05ac0, evaluate=1) at eval.c:4231
#39 0x000000000045c0f9 in eval2 (arg=0x7fff1aa05a78, rettv=0x7fff1aa05ac0, evaluate=1) at eval.c:4160
#40 0x000000000045bf38 in eval1 (arg=0x7fff1aa05a78, rettv=0x7fff1aa05ac0, evaluate=1) at eval.c:4085
#41 0x000000000045be97 in eval0 (arg=0x1f47d22 "pyeval('powerline.statusline(3)')", rettv=0x7fff1aa05ac0, nextcmd=0x0, evaluate=1) at eval.c:4042
#42 0x0000000000456ef1 in eval_to_string (arg=0x1f47d22 "pyeval('powerline.statusline(3)')", nextcmd=0x0, convert=0) at eval.c:1353
#43 0x0000000000457078 in eval_to_string_safe (arg=0x1f47d22 "pyeval('powerline.statusline(3)')", nextcmd=0x0, use_sandbox=0) at eval.c:1401
#44 0x0000000000436f40 in build_stl_str_hl (wp=0x20e5220, out=0x7fff1aa082f0 "\001", outlen=4096, fmt=0x1f47d20 "%!pyeval('powerline.statusline(3)')", use_sandbox=0, 
    fillchar=32, maxwidth=85, hltab=0x7fff1aa06ef0, tabtab=0x7fff1aa078f0) at buffer.c:3574
#45 0x000000000058ad59 in win_redr_custom (wp=0x20e5220, draw_ruler=0) at screen.c:6760
#46 0x000000000058a779 in redraw_custom_statusline (wp=0x20e5220) at screen.c:6547
#47 0x000000000058a27a in win_redr_status (wp=0x20e5220) at screen.c:6409
#48 0x000000000057e7b1 in update_screen (type=40) at screen.c:689
#49 0x00000000005959f3 in showmatch (c=41) at search.c:2473
#50 0x00000000004fb685 in ins_char_bytes (buf=0x7fff1aa094f0 ")", charlen=1) at misc1.c:2309
#51 0x00000000004fb295 in ins_char (c=41) at misc1.c:2146
#52 0x0000000000450364 in insertchar (c=41, flags=0, second_indent=-1) at edit.c:6077
#53 0x000000000044fc20 in insert_special (c=41, allow_modmask=0, ctrlv=0) at edit.c:5812
#54 0x00000000004483be in edit (cmdchar=97, startln=0, count=0) at edit.c:1491
#55 0x0000000000529f92 in invoke_edit (cap=0x7fff1aa097a0, repl=0, cmd=97, startln=0) at normal.c:9243
#56 0x0000000000529f2b in nv_edit (cap=0x7fff1aa097a0) at normal.c:9216
#57 0x000000000051c274 in normal_cmd (oap=0x7fff1aa09840, toplevel=1) at normal.c:1200
#58 0x00000000006390b3 in main_loop (cmdwin=0, noexmode=0) at main.c:1329
#59 0x00000000006389bf in main (argc=1, argv=0x7fff1aa09b48) at main.c:1020

(Vim hg5491 with local patches)

Vimball installs README.md and RELEASE.md into ~/.vim

I don't think the README.md and RELEASE.md files should be installed into the ~/.vim directory when using the Vimball installation since that might conflict with other plugins. Perhaps they should go into a different directory or be omitted altogether?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.