1--- 2title: User's Guide for Vim in Nixpkgs 3author: Marc Weber 4date: 2016-06-25 5--- 6# User's Guide to Vim Plugins/Addons/Bundles/Scripts in Nixpkgs 7 8You'll get a vim(-your-suffix) in PATH also loading the plugins you want. 9Loading can be deferred; see examples. 10 11Vim packages, VAM (=vim-addon-manager) and Pathogen are supported to load 12packages. 13 14## Custom configuration 15 16Adding custom .vimrc lines can be done using the following code: 17 18``` 19vim_configurable.customize { 20 name = "vim-with-plugins"; 21 22 vimrcConfig.customRC = '' 23 set hidden 24 ''; 25} 26``` 27 28## Vim packages 29 30To store you plugins in Vim packages the following example can be used: 31 32``` 33vim_configurable.customize { 34 vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { 35 # loaded on launch 36 start = [ youcompleteme fugitive ]; 37 # manually loadable by calling `:packadd $plugin-name` 38 opt = [ phpCompletion elm-vim ]; 39 # To automatically load a plugin when opening a filetype, add vimrc lines like: 40 # autocmd FileType php :packadd phpCompletion 41 } 42}; 43``` 44 45## VAM 46 47### dependencies by Vim plugins 48 49VAM introduced .json files supporting dependencies without versioning 50assuming that "using latest version" is ok most of the time. 51 52### Example 53 54First create a vim-scripts file having one plugin name per line. Example: 55 56 "tlib" 57 {'name': 'vim-addon-sql'} 58 {'filetype_regex': '\%(vim)$', 'names': ['reload', 'vim-dev-plugin']} 59 60Such vim-scripts file can be read by VAM as well like this: 61 62 call vam#Scripts(expand('~/.vim-scripts'), {}) 63 64Create a default.nix file: 65 66 { nixpkgs ? import <nixpkgs> {}, compiler ? "ghc7102" }: 67 nixpkgs.vim_configurable.customize { name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ]; } 68 69Create a generate.vim file: 70 71 ActivateAddons vim-addon-vim2nix 72 let vim_scripts = "vim-scripts" 73 call nix#ExportPluginsForNix({ 74 \ 'path_to_nixpkgs': eval('{"'.substitute(substitute(substitute($NIX_PATH, ':', ',', 'g'), '=',':', 'g'), '\([:,]\)', '"\1"',"g").'"}')["nixpkgs"], 75 \ 'cache_file': '/tmp/vim2nix-cache', 76 \ 'try_catch': 0, 77 \ 'plugin_dictionaries': ["vim-addon-manager"]+map(readfile(vim_scripts), 'eval(v:val)') 78 \ }) 79 80Then run 81 82 nix-shell -p vimUtils.vim_with_vim2nix --command "vim -c 'source generate.vim'" 83 84You should get a Vim buffer with the nix derivations (output1) and vam.pluginDictionaries (output2). 85You can add your vim to your system's configuration file like this and start it by "vim-my": 86 87 my-vim = 88 let plugins = let inherit (vimUtils) buildVimPluginFrom2Nix; in { 89 copy paste output1 here 90 }; in vim_configurable.customize { 91 name = "vim-my"; 92 93 vimrcConfig.vam.knownPlugins = plugins; # optional 94 vimrcConfig.vam.pluginDictionaries = [ 95 copy paste output2 here 96 ]; 97 98 # Pathogen would be 99 # vimrcConfig.pathogen.knownPlugins = plugins; # plugins 100 # vimrcConfig.pathogen.pluginNames = ["tlib"]; 101 }; 102 103 104Sample output1: 105 106 "reload" = buildVimPluginFrom2Nix { # created by nix#NixDerivation 107 name = "reload"; 108 src = fetchgit { 109 url = "git://github.com/xolox/vim-reload"; 110 rev = "0a601a668727f5b675cb1ddc19f6861f3f7ab9e1"; 111 sha256 = "0vb832l9yxj919f5hfg6qj6bn9ni57gnjd3bj7zpq7d4iv2s4wdh"; 112 }; 113 dependencies = ["nim-misc"]; 114 115 }; 116 [...] 117 118Sample output2: 119 120 [ 121 ''vim-addon-manager'' 122 ''tlib'' 123 { "name" = ''vim-addon-sql''; } 124 { "filetype_regex" = ''\%(vim)$$''; "names" = [ ''reload'' ''vim-dev-plugin'' ]; } 125 ] 126 127 128## Important repositories 129 130- [vim-pi](https://bitbucket.org/vimcommunity/vim-pi) is a plugin repository 131 from VAM plugin manager meant to be used by others as well used by 132 133- [vim2nix](http://github.com/MarcWeber/vim-addon-vim2nix) which generates the 134 .nix code 135