localvimrc.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. *localvimrc* Localvimrc
  2. ===============================================================================
  3. Contents ~
  4. 1. Introduction |localvimrc-introduction|
  5. 2. Commands |localvimrc-commands|
  6. 1. The |LocalVimRC| command
  7. 2. The |LocalVimRCClear| command
  8. 3. The |LocalVimRCEdit| command
  9. 4. The |LocalVimRCEnable| command
  10. 5. The |LocalVimRCDisable| command
  11. 3. Functions |localvimrc-functions|
  12. 1. The |LocalVimRCFinish| command
  13. 4. Variables |localvimrc-variables|
  14. 1. The |g:localvimrc_file| variable
  15. 2. The |g:localvimrc_file_dir| variable
  16. 3. The |g:localvimrc_script| variable
  17. 4. The |g:localvimrc_script_dir| variable
  18. 5. The |g:localvimrc_script_unresolved| variable
  19. 6. The |g:localvimrc_script_dir_unresolved| variable
  20. 7. The |g:localvimrc_sourced_once| variable
  21. 8. The |g:localvimrc_sourced_once_for_file| setting
  22. 5. Settings |localvimrc-settings|
  23. 1. The |g:localvimrc_enable| setting
  24. 2. The |g:localvimrc_name| setting
  25. 3. The |g:localvimrc_event| setting
  26. 4. The |g:localvimrc_event_pattern| setting
  27. 5. The |g:localvimrc_reverse| setting
  28. 6. The |g:localvimrc_count| setting
  29. 7. The |g:localvimrc_file_directory_only| setting
  30. 8. The |g:localvimrc_sandbox| setting
  31. 9. The |g:localvimrc_ask| setting
  32. 10. The |g:localvimrc_persistent| setting
  33. 11. The |g:localvimrc_persistence_file| setting
  34. 12. The |g:localvimrc_whitelist| setting
  35. 13. The |g:localvimrc_blacklist| setting
  36. 14. The |g:localvimrc_autocmd| setting
  37. 15. The |g:localvimrc_debug| setting
  38. 6. Autocommands |localvimrc-autocommands|
  39. 1. The |LocalVimRCPre| autocommand
  40. 2. The |LocalVimRCPost| autocommand
  41. 7. Contribute |localvimrc-contribute|
  42. 8. Credits |localvimrc-credits|
  43. 9. Changelog |localvimrc-changelog|
  44. 10. References |localvimrc-references|
  45. ===============================================================================
  46. *localvimrc-introduction*
  47. Introduction ~
  48. This plugin searches for local vimrc files in the file system tree of the
  49. currently opened file. It searches for all ".lvimrc" files from the directory
  50. of the file up to the root directory. By default those files are loaded in
  51. order from the root directory to the directory of the file. The filename and
  52. amount of loaded files are customizable through global variables.
  53. For security reasons it the plugin asks for confirmation before loading a local
  54. vimrc file and loads it using |:sandbox| command. The plugin asks once per
  55. session and local vimrc before loading it, if the file didn't change since
  56. previous loading.
  57. It is possible to define a whitelist and a blacklist of local vimrc files that
  58. are loaded or ignored unconditionally.
  59. The plugin can be found on Bitbucket [1], GitHub [2] and VIM online [3].
  60. ===============================================================================
  61. *localvimrc-commands*
  62. Commands ~
  63. -------------------------------------------------------------------------------
  64. The *LocalVimRC* command
  65. Resource all local vimrc files for the current buffer.
  66. -------------------------------------------------------------------------------
  67. The *LocalVimRCClear* command
  68. Clear all stored decisions made in the past, when the plugin asked about
  69. sourcing a local vimrc file.
  70. -------------------------------------------------------------------------------
  71. The *LocalVimRCEdit* command
  72. Open the local vimrc file for the current buffer in an split window for
  73. editing. If more than one local vimrc file has been sourced, the user can
  74. decide which file to edit.
  75. -------------------------------------------------------------------------------
  76. The *LocalVimRCEnable* command
  77. Globally enable the loading of local vimrc files if loading has been disabled
  78. by |LocalVimRCDisable| or by setting |g:localvimrc_enable| to '0' during
  79. startup.
  80. Enabling local vimrc using this command will trigger loading of local vimrc
  81. files for the currently active buffer. It will _not_ load the local vimrc files
  82. for any other buffer. This will be done by an autocommand later when another
  83. buffer gets active and the configured |g:localvimrc_event| autocommand gets
  84. active. This is the case for the default |BufWinEnter|.
  85. -------------------------------------------------------------------------------
  86. The *LocalVimRCDisable* command
  87. Globally disable the loading of local vimrc files if loading has been disabled
  88. by |LocalVimRCEnable| or by setting |g:localvimrc_enable| to '1' during
  89. startup.
  90. ===============================================================================
  91. *localvimrc-functions*
  92. Functions ~
  93. -------------------------------------------------------------------------------
  94. The *LocalVimRCFinish* command
  95. After a call to this function the sourcing of any remaining local vimrc files
  96. will be skipped. In combination with the |g:localvimrc_reverse| option it is
  97. possible to end the processing of local vimrc files for example at the root of
  98. the project by adding the following command to the local vimrc file in the root
  99. of the project:
  100. >
  101. call LocalVimRCFinish()
  102. <
  103. ===============================================================================
  104. *localvimrc-variables*
  105. Variables ~
  106. The plugin provides several convenience variables to make it easier to set up
  107. path dependent setting like for example makeprg. These variables are only
  108. available inside your local vimrc file because they are only unambiguous there.
  109. Adding the following lines to a local vimrc in the root directory of a project
  110. modify the behavior of |:make| to change into a build directory and call make
  111. there:
  112. >
  113. let &l:makeprg="cd ".g:localvimrc_script_dir_unresolved."/build && make"
  114. <
  115. **NOTE:**
  116. This is only possible if you disable sandbox mode.
  117. Other variables provide a way to prevent multiple execution of commands. They
  118. can be used to implement guards:
  119. >
  120. " do stuff you want to do on every buffer enter event
  121. " guard to end loading if it has been loaded for the currently edited file
  122. if g:localvimrc_sourced_once_for_file
  123. finish
  124. endif
  125. " do stuff you want to do only once for a edited file
  126. " guard to end loading if it has been loaded for the running vim instance
  127. if g:localvimrc_sourced_once
  128. finish
  129. endif
  130. " do stuff you want to do only once for a running vim instance
  131. <
  132. -------------------------------------------------------------------------------
  133. The *g:localvimrc_file* variable
  134. Fully qualified file name of file that triggered loading the local vimrc file.
  135. -------------------------------------------------------------------------------
  136. The *g:localvimrc_file_dir* variable
  137. Fully qualified directory of file that triggered loading the local vimrc file.
  138. -------------------------------------------------------------------------------
  139. The *g:localvimrc_script* variable
  140. Fully qualified and resolved file name of the currently loaded local vimrc
  141. file.
  142. -------------------------------------------------------------------------------
  143. The *g:localvimrc_script_dir* variable
  144. Fully qualified and resolved directory of the currently loaded local vimrc
  145. file.
  146. -------------------------------------------------------------------------------
  147. The *g:localvimrc_script_unresolved* variable
  148. Fully qualified but unresolved file name of the currently loaded local vimrc
  149. file.
  150. -------------------------------------------------------------------------------
  151. The *g:localvimrc_script_dir_unresolved* variable
  152. Fully qualified but unresolved directory of the currently loaded local vimrc
  153. file.
  154. -------------------------------------------------------------------------------
  155. The *g:localvimrc_sourced_once* variable
  156. Set to '1' if the currently loaded local vimrc file had already been loaded in
  157. this session. Set to '0' otherwise.
  158. -------------------------------------------------------------------------------
  159. The *g:localvimrc_sourced_once_for_file* setting
  160. Set to '1' if the currently loaded local vimrc file had already been loaded in
  161. this session for the currently edited file. Set to '0' otherwise.
  162. ===============================================================================
  163. *localvimrc-settings*
  164. Settings ~
  165. To change settings from their default add similar line to your global |vimrc|
  166. file.
  167. >
  168. let g:option_name=option_value
  169. <
  170. -------------------------------------------------------------------------------
  171. The *g:localvimrc_enable* setting
  172. Globally enable/disable loading of local vimrc files globally. The behavior can
  173. be changed during runtime using the commands |LocalVimRCEnable| and
  174. |LocalVimRCDisable|.
  175. - Value '0': Disable loading of any local vimrc files.
  176. - Value '1': Enable loading of local vimrc files.
  177. - Default: '1'
  178. -------------------------------------------------------------------------------
  179. The *g:localvimrc_name* setting
  180. List of filenames of local vimrc files. The given name can include a directory
  181. name such as ".config/localvimrc".
  182. Previous versions of localvimrc only supported a single file as string. This is
  183. still supported for backward compatibility.
  184. - Default: '[ ".lvimrc" ]'
  185. -------------------------------------------------------------------------------
  186. The *g:localvimrc_event* setting
  187. List of autocommand events that trigger local vimrc file loading.
  188. - Default: '[ "BufWinEnter" ]'
  189. For more information see |autocmd-events|.
  190. **NOTE:**
  191. BufWinEnter is the default to enable lines like
  192. >
  193. setlocal colorcolumn=+1
  194. <
  195. in the local vimrc file. Settings "local to window" need to be set for every
  196. time a buffer is displayed in a window.
  197. -------------------------------------------------------------------------------
  198. The *g:localvimrc_event_pattern* setting
  199. String defining the pattern for which the autocommand events trigger local
  200. vimrc file loading.
  201. - Default: '"*"'
  202. For more information see |autocmd-patterns|.
  203. -------------------------------------------------------------------------------
  204. The *g:localvimrc_reverse* setting
  205. Reverse behavior of loading local vimrc files.
  206. - Value '0': Load files in order from root directory to directory of the
  207. file.
  208. - Value '1': Load files in order from directory of the file to root
  209. directory.
  210. - Default: '0'
  211. -------------------------------------------------------------------------------
  212. The *g:localvimrc_count* setting
  213. On the way from root, the last localvimrc_count files are sourced.
  214. **NOTE:**
  215. This might load files not located in the edited files directory or even not
  216. located in the projects directory. If this is of concern use the
  217. |g:localvimrc_file_directory_only| setting.
  218. - Default: '-1' (all)
  219. -------------------------------------------------------------------------------
  220. The *g:localvimrc_file_directory_only* setting
  221. Just use local vimrc file located in the edited files directory.
  222. **NOTE:**
  223. This might end in not loading any local vimrc files at all. If limiting the
  224. number of loaded local vimrc files is of concern use the |g:localvimrc_count|
  225. setting.
  226. - Value '0': Load all local vimrc files in the tree from root to file.
  227. - Value '1': Load only file in the same directory as edited file.
  228. - Default: '0'
  229. -------------------------------------------------------------------------------
  230. The *g:localvimrc_sandbox* setting
  231. Source the found local vimrc files in a sandbox for security reasons.
  232. - Value '0': Don't load vimrc file in a sandbox.
  233. - Value '1': Load vimrc file in a sandbox.
  234. - Default: '1'
  235. -------------------------------------------------------------------------------
  236. The *g:localvimrc_ask* setting
  237. Ask before sourcing any local vimrc file. In a vim session the question is only
  238. asked once as long as the local vimrc file has not been changed.
  239. - Value '0': Don't ask before loading a vimrc file.
  240. - Value '1': Ask before loading a vimrc file.
  241. - Default: '1'
  242. -------------------------------------------------------------------------------
  243. The *g:localvimrc_persistent* setting
  244. Make the decisions given when asked before sourcing local vimrc files
  245. persistent over multiple vim runs and instances. The decisions are written to
  246. the file defined by and |g:localvimrc_persistence_file|.
  247. - Value '0': Don't store and restore any decisions.
  248. - Value '1': Store and restore decisions only if the answer was given in
  249. upper case (Y/N/A).
  250. - Value '2': Store and restore all decisions.
  251. - Default: '0'
  252. -------------------------------------------------------------------------------
  253. The *g:localvimrc_persistence_file* setting
  254. Filename used for storing persistent decisions made when asked before sourcing
  255. local vimrc files.
  256. - Default (_Unix_): "$HOME/.localvimrc_persistent"
  257. - Default (_Windows_): "$HOME/_localvimrc_persistent"
  258. -------------------------------------------------------------------------------
  259. The *g:localvimrc_whitelist* setting
  260. If a local vimrc file matches the regular expression given by
  261. |g:localvimrc_whitelist| this file is loaded unconditionally.
  262. Files matching |g:localvimrc_whitelist| are sourced even if they are matched by
  263. |g:localvimrc_blacklist|.
  264. See |regular-expression| for patterns that are accepted.
  265. Example:
  266. >
  267. " whitelist all local vimrc files in users project foo and bar
  268. let g:localvimrc_whitelist='/home/user/projects/\(foo\|bar\)/.*'
  269. " whitelist can also use lists of patterns
  270. let g:localvimrc_whitelist=['/home/user/project1/', '/opt/project2/', '/usr/local/projects/vim-[^/]*/']
  271. <
  272. - Default: No whitelist
  273. -------------------------------------------------------------------------------
  274. The *g:localvimrc_blacklist* setting
  275. If a local vimrc file matches the regular expression given by
  276. |g:localvimrc_blacklist| this file is skipped unconditionally.
  277. Files matching |g:localvimrc_whitelist| are sourced even if they are matched by
  278. |g:localvimrc_blacklist|.
  279. See |regular-expression| for patterns that are accepted.
  280. Example:
  281. >
  282. " blacklist all local vimrc files in shared project directory
  283. let g:localvimrc_blacklist='/share/projects/.*'
  284. " blacklist can also use lists of patterns
  285. let g:localvimrc_blacklist=['/share/projects/.*', '/usr/share/other-projects/.*']
  286. <
  287. - Default: No blacklist
  288. -------------------------------------------------------------------------------
  289. The *g:localvimrc_autocmd* setting
  290. Emit autocommands |LocalVimRCPre| before and |LocalVimRCPost| after sourcing
  291. every local vimrc file.
  292. - Default: '1'
  293. -------------------------------------------------------------------------------
  294. The *g:localvimrc_debug* setting
  295. Debug level for this script.
  296. - Default: '0'
  297. ===============================================================================
  298. *localvimrc-autocommands*
  299. Autocommands ~
  300. If enabled localvimrc emits autocommands before and after sourcing an local
  301. vimrc file.
  302. -------------------------------------------------------------------------------
  303. The *LocalVimRCPre* autocommand
  304. This autocommand is emitted right before sourcing each local vimrc file.
  305. -------------------------------------------------------------------------------
  306. The *LocalVimRCPost* autocommand
  307. This autocommands is emitted right after sourcing each local vimrc file.
  308. ===============================================================================
  309. *localvimrc-contribute*
  310. Contribute ~
  311. To contact the author (Markus Braun), please send an email to
  312. markus.braun@krawel.de
  313. If you think this plugin could be improved, fork on Bitbucket [1] or GitHub [2]
  314. and send a pull request or just tell me your ideas.
  315. ===============================================================================
  316. *localvimrc-credits*
  317. Credits ~
  318. - Simon Howard for his hint about "sandbox"
  319. - Mark Weber for the idea of using checksums
  320. - Daniel Hahler for various patches
  321. - Justin M. Keyes for ideas to improve this plugin
  322. - Lars Winderling for whitelist/blacklist patch
  323. - Michon van Dooren for autocommands patch
  324. ===============================================================================
  325. *localvimrc-changelog*
  326. Changelog ~
  327. v2.7.0 : 2018-03-19
  328. - add setting |g:localvimrc_enable| and commands |LocalVimRCEnable| and
  329. |LocalVimRCDisable| to globally disable processing of local vimrc files.
  330. - add setting |g:localvimrc_event_pattern| to change the pattern for which
  331. the autocommand is executed.
  332. v2.6.1 : 2018-02-20
  333. - fix a bug with missing uniq() in Vim version 7.4
  334. v2.6.0 : 2018-01-22
  335. - add command |LocalVimRCEdit| to edit sourced local vimrc files for the
  336. current buffer.
  337. v2.5.0 : 2017-03-08
  338. - add unit tests.
  339. - settings |g:localvimrc_whitelist| and |g:localvimrc_blacklist| now takes
  340. optionally a list of regular expressions.
  341. - add convenience variables |g:localvimrc_script_unresolved| and
  342. |g:localvimrc_script_dir_unresolved|.
  343. - add ability to view local vimrc before sourcing when |g:localvimrc_ask| is
  344. enabled.
  345. - emit autocommands before and after sourcing files.
  346. - add |g:localvimrc_file_directory_only| to limit sourcing to local vimrc
  347. files in the same directory as the edited file.
  348. - add |LocalVimRCFinish| function to stop loading of remaining local vimrc
  349. files from within a local vimrc file.
  350. v2.4.0 : 2016-02-05
  351. - add setting |g:localvimrc_event| which defines the autocommand events that
  352. trigger local vimrc file loading.
  353. - don't lose persistence file on full partitions.
  354. - make it possible to supply a list of local vimrc filenames in
  355. |g:localvimrc_name|.
  356. - ask user when sourcing local vimrc fails and |g:localvimrc_sandbox| and
  357. |g:localvimrc_ask| is set whether the file should be sourced without
  358. sandbox.
  359. - fix a bug where local vimrc files are sourced in wrong order when some of
  360. them are symlinks to a different directory.
  361. v2.3.0 : 2014-02-06
  362. - private persistence file to enable persistence over concurrent vim
  363. instances.
  364. - add convenience variables |g:localvimrc_sourced_once| and
  365. |g:localvimrc_sourced_once_for_file|.
  366. v2.2.0 : 2013-11-09
  367. - remove redraw calls for better performance and fixing a bug on windows.
  368. - load local vimrc on event BufWinEnter to fix a bug with window local
  369. settings.
  370. - add |g:localvimrc_reverse| to change order of sourcing local vimrc files.
  371. - add convenience variables |g:localvimrc_file|, |g:localvimrc_file_dir|,
  372. |g:localvimrc_script| and |g:localvimrc_script_dir|.
  373. v2.1.0 : 2012-09-25
  374. - add possibility to make decisions persistent.
  375. - use full file path when storing decisions.
  376. v2.0.0 : 2012-04-05
  377. - added |g:localvimrc_whitelist| and |g:localvimrc_blacklist| settings.
  378. - ask only once per session and local vimrc before loading it, if it didn't
  379. change.
  380. v2758 : 2009-05-11
  381. - source .lvimrc in a sandbox to better maintain security, configurable using
  382. |g:localvimrc_sandbox|.
  383. - ask user before sourcing any local vimrc file, configurable using
  384. |g:localvimrc_ask|.
  385. v1870 : 2007-09-28
  386. - new configuration variable |g:localvimrc_name| to change filename.
  387. - new configuration variable |g:localvimrc_count| to limit number of loaded
  388. files.
  389. v1613 : 2007-04-05
  390. - switched to arrays in vim 7.
  391. - escape file/path names correctly.
  392. v1.2 : 2002-10-09
  393. - initial version
  394. ===============================================================================
  395. *localvimrc-references*
  396. References ~
  397. [1] https://bitbucket.org/embear/localvimrc
  398. [2] https://github.com/embear/vim-localvimrc
  399. [3] http://www.vim.org/scripts/script.php?script_id=441
  400. vim: ft=help