Vim: Difference between revisions
mNo edit summary |
Improve translation support |
||
| Line 10: | Line 10: | ||
On unstable: | On unstable: | ||
</translate> | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
programs.vim.enable = true; | programs.vim.enable = true; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
or | or | ||
</translate> | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
programs.vim = { | programs.vim = { | ||
| Line 22: | Line 25: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
On 24.05 or older: | On 24.05 or older: | ||
< | </translate> | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
environment.systemPackages = with pkgs; [ vim ]; | environment.systemPackages = with pkgs; [ vim ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:5--> | <!--T:5--> | ||
or | or | ||
< | </translate> | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
environment.systemPackages = with pkgs; [ vim_configurable ]; | environment.systemPackages = with pkgs; [ vim_configurable ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== Using Home Manager === <!--T:7--> | === Using Home Manager === <!--T:7--> | ||
| Line 42: | Line 48: | ||
<!--T:8--> | <!--T:8--> | ||
Vim can easily be set up using [[Special:MyLanguage/Home Manager|Home Manager]]. Here's a minimal example: | Vim can easily be set up using [[Special:MyLanguage/Home Manager|Home Manager]]. Here's a minimal example: | ||
</translate> | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
programs.vim = { | programs.vim = { | ||
| Line 52: | Line 60: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:9--> | <!--T:9--> | ||
| Line 61: | Line 70: | ||
You can configure home-manager to install spelling files into your user directory by packaging individual spell files. Here' an example for neovim and French: | You can configure home-manager to install spelling files into your user directory by packaging individual spell files. Here' an example for neovim and French: | ||
< | </translate> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
let | let | ||
| Line 69: | Line 78: | ||
}; | }; | ||
nvim-spell-fr-utf8-suggestions = builtins.fetchurl { | nvim-spell-fr-utf8-suggestions = builtins.fetchurl { | ||
url = "http://ftp.vim.org/vim/runtime/spell/fr.utf-8.sug"; | url = "http://ftp.vim.org/vim/runtime/spell/fr.utf-8.sug"; | ||
| Line 75: | Line 83: | ||
}; | }; | ||
nvim-spell-fr-latin1-dictionary = builtins.fetchurl { | nvim-spell-fr-latin1-dictionary = builtins.fetchurl { | ||
url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.spl"; | url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.spl"; | ||
| Line 81: | Line 88: | ||
}; | }; | ||
nvim-spell-fr-latin1-suggestions = builtins.fetchurl { | nvim-spell-fr-latin1-suggestions = builtins.fetchurl { | ||
url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.sug"; | url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.sug"; | ||
| Line 94: | Line 100: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
==== NeoVim with Coc for Python ==== <!--T:16--> | ==== NeoVim with Coc for Python ==== <!--T:16--> | ||
| Line 108: | Line 115: | ||
On unstable: | On unstable: | ||
</translate> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
| Line 116: | Line 124: | ||
package = (pkgs.vim_configurable.override { }).customize{ | package = (pkgs.vim_configurable.override { }).customize{ | ||
name = "vim"; | name = "vim"; | ||
<translate> | |||
# Install plugins for example for syntax highlighting of nix files | # Install plugins for example for syntax highlighting of nix files | ||
</translate> | |||
vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | ||
start = [ vim-nix vim-lastplace ]; | start = [ vim-nix vim-lastplace ]; | ||
| Line 122: | Line 132: | ||
}; | }; | ||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
<translate> | |||
" your custom vimrc | " your custom vimrc | ||
</translate> | |||
set nocompatible | set nocompatible | ||
set backspace=indent,eol,start | set backspace=indent,eol,start | ||
<translate> | |||
" Turn on syntax highlighting by default | " Turn on syntax highlighting by default | ||
</translate> | |||
syntax on | syntax on | ||
" ... | " ... | ||
| Line 133: | Line 147: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
On 24.05 or older: | On 24.05 or older: | ||
</translate> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
{ | { | ||
environment.variables = { EDITOR = "vim" | environment.variables = { EDITOR = "vim"; | ||
environment.systemPackages = with pkgs; [ | |||
environment.systemPackages = with pkgs; [ | |||
((vim_configurable.override { }).customize{ | ((vim_configurable.override { }).customize{ | ||
name = "vim"; | name = "vim"; | ||
<translate> | |||
# Install plugins for example for syntax highlighting of nix files | # Install plugins for example for syntax highlighting of nix files | ||
</translate> | |||
vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | ||
start = [ vim-nix vim-lastplace ]; | start = [ vim-nix vim-lastplace ]; | ||
| Line 152: | Line 167: | ||
}; | }; | ||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
<translate> | |||
" your custom vimrc | " your custom vimrc | ||
</translate> | |||
set nocompatible | set nocompatible | ||
set backspace=indent,eol,start | set backspace=indent,eol,start | ||
<translate> | |||
" Turn on syntax highlighting by default | " Turn on syntax highlighting by default | ||
</translate> | |||
syntax on | syntax on | ||
" ... | " ... | ||
| Line 173: | Line 192: | ||
configure = { | configure = { | ||
customRC = '' | customRC = '' | ||
<translate> | |||
" your custom vimrc | " your custom vimrc | ||
</translate> | |||
set nocompatible | set nocompatible | ||
set backspace=indent,eol,start | set backspace=indent,eol,start | ||
| Line 186: | Line 207: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:23--> | <!--T:23--> | ||
import these in your <code>configuration.nix</code> and | import these in your <code>configuration.nix</code> and | ||
</translate> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ | { | ||
| Line 198: | Line 221: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
== Custom setup without using Home Manager == <!--T:24--> | == Custom setup without using Home Manager == <!--T:24--> | ||
| Line 218: | Line 242: | ||
Add the following code to your <code>~/.nixpkgs/config.nix</code>: | Add the following code to your <code>~/.nixpkgs/config.nix</code>: | ||
< | </translate> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ | { | ||
| Line 224: | Line 248: | ||
myVim = vim_configurable.customize { | myVim = vim_configurable.customize { | ||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
<translate> | |||
# add here code from the example section | # add here code from the example section | ||
</translate> | |||
}; | }; | ||
myNeovim = neovim.override { | myNeovim = neovim.override { | ||
configure = { | configure = { | ||
customRC = '' | customRC = '' | ||
<translate> | |||
# here your custom configuration goes! | # here your custom configuration goes! | ||
</translate> | |||
''; | ''; | ||
packages.myVimPackage = with pkgs.vimPlugins; { | packages.myVimPackage = with pkgs.vimPlugins; { | ||
<translate> | |||
# see examples below how to use custom packages | # see examples below how to use custom packages | ||
</translate> | |||
start = [ ]; | start = [ ]; | ||
opt = [ ]; | opt = [ ]; | ||
| Line 241: | Line 271: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:32--> | <!--T:32--> | ||
| Line 252: | Line 283: | ||
NB: you ''must'' use <code>vimrcConfig.customRC</code> rather than installing a <code>~/.vimrc</code> by hand, since the customized Vim will silently ignore any vimrc in your home directory. | NB: you ''must'' use <code>vimrcConfig.customRC</code> rather than installing a <code>~/.vimrc</code> by hand, since the customized Vim will silently ignore any vimrc in your home directory. | ||
< | </translate> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
vim_configurable.customize { | vim_configurable.customize { | ||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
<translate> | |||
# add custom .vimrc lines like this: | # add custom .vimrc lines like this: | ||
</translate> | |||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
set hidden | set hidden | ||
| Line 263: | Line 296: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:37--> | <!--T:37--> | ||
| Line 269: | Line 303: | ||
=== Using vim's builtin packaging capability === <!--T:38--> | === Using vim's builtin packaging capability === <!--T:38--> | ||
< | </translate> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
vim_configurable.customize { | vim_configurable.customize { | ||
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { | vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { | ||
<translate> | |||
# loaded on launch | # loaded on launch | ||
</translate> | |||
start = [ YouCompleteMe fugitive ]; | start = [ YouCompleteMe fugitive ]; | ||
<translate> | |||
# manually loadable by calling `:packadd $plugin-name` | # manually loadable by calling `:packadd $plugin-name` | ||
</translate> | |||
opt = [ phpCompletion elm-vim ]; | opt = [ phpCompletion elm-vim ]; | ||
<translate> | |||
# To automatically load a plugin when opening a filetype, add vimrc lines like: | # To automatically load a plugin when opening a filetype, add vimrc lines like: | ||
</translate> | |||
# autocmd FileType php :packadd phpCompletion | # autocmd FileType php :packadd phpCompletion | ||
} | } | ||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:40--> | <!--T:40--> | ||
| Line 290: | Line 331: | ||
<!--T:42--> | <!--T:42--> | ||
There is a pathogen implementation as well, but its startup is slower and [VAM] has more features. | There is a pathogen implementation as well, but its startup is slower and [VAM] has more features. | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
vimrcConfig.pathogen.knownPlugins = vimPlugins; # optional | vimrcConfig.pathogen.knownPlugins = vimPlugins; # optional | ||
vimrcConfig.pathogen.pluginNames = [ "vim-addon-nix" "youcompleteme" ]; | vimrcConfig.pathogen.pluginNames = [ "vim-addon-nix" "youcompleteme" ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== Using Vim-Plug as manager === <!--T:43--> | === Using Vim-Plug as manager === <!--T:43--> | ||
< | </translate> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
vimrcConfig.plug.plugins = with pkgs.vimPlugins; [vim-addon-nix youcompleteme]; | vimrcConfig.plug.plugins = with pkgs.vimPlugins; [vim-addon-nix youcompleteme]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== Adding new plugins === <!--T:45--> | === Adding new plugins === <!--T:45--> | ||
| Line 323: | Line 368: | ||
Sometimes you do not want to change upstream plugins, for this you can use <code>vimUtils.buildVimPlugin</code> to create your own: | Sometimes you do not want to change upstream plugins, for this you can use <code>vimUtils.buildVimPlugin</code> to create your own: | ||
< | </translate> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
let | let | ||
| Line 335: | Line 380: | ||
}; | }; | ||
}; | }; | ||
in { | in { | ||
users.users.<yourNickname>.packages = [ | users.users.<yourNickname>.packages = [ | ||
| Line 347: | Line 390: | ||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
==== Using flake ==== <!--T:53--> | ==== Using flake ==== <!--T:53--> | ||
< | </translate> | ||
<code>configuration.nix</code>: | <code>configuration.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 375: | Line 419: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<code>flake.nix</code>: | <code>flake.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 387: | Line 430: | ||
}; | }; | ||
outputs = inputs@{ nixpkgs, ... }: { | |||
outputs = inputs@{ nixpkgs, ... }: { | |||
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { | nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { | ||
system = "x86_64-linux"; | system = "x86_64-linux"; | ||
| Line 401: | Line 443: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:57--> | <!--T:57--> | ||
| Line 412: | Line 455: | ||
==== Using language client ==== <!--T:60--> | ==== Using language client ==== <!--T:60--> | ||
< | </translate> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
vim_configurable.customize { | vim_configurable.customize { | ||
| Line 433: | Line 476: | ||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:62--> | <!--T:62--> | ||
Then put the following expression in <code>environment.systemPackages</code> or in the home-manager package list, | Then put the following expression in <code>environment.systemPackages</code> or in the home-manager package list, | ||
to install python-language-server: | to install python-language-server: | ||
</translate> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
(python3.withPackages(ps: [ | (python3.withPackages(ps: [ | ||
ps.python-language-server | ps.python-language-server | ||
<translate> | |||
# the following plugins are optional, they provide type checking, import sorting and code formatting | # the following plugins are optional, they provide type checking, import sorting and code formatting | ||
</translate> | |||
ps.pyls-mypy ps.pyls-isort ps.pyls-black | ps.pyls-mypy ps.pyls-isort ps.pyls-black | ||
])) | ])) | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
=== Real life examples === <!--T:63--> | === Real life examples === <!--T:63--> | ||
| Line 465: | Line 513: | ||
<!--T:69--> | <!--T:69--> | ||
If you have defined your vim configuration in a `./my_vim.nix` file you can install vim with the python 3 support instead of python2 by overriding the python version like the following: | If you have defined your vim configuration in a `./my_vim.nix` file you can install vim with the python 3 support instead of python2 by overriding the python version like the following: | ||
</translate> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
(pkgs.callPackage ./my_vim.nix { | (pkgs.callPackage ./my_vim.nix { | ||
| Line 471: | Line 520: | ||
}) | }) | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
== gvim and gview == <!--T:70--> | == gvim and gview == <!--T:70--> | ||
| Line 476: | Line 526: | ||
<!--T:71--> | <!--T:71--> | ||
<code>gvim</code> and <code>gview</code> may be installed using the <code>[https://search.nixos.org/packages/?query=vimHugeX vimHugeX]</code> attribute name (package name <code>[https://search.nixos.org/packages/?query=vim_configurable vim_configurable]</code>). | <code>gvim</code> and <code>gview</code> may be installed using the <code>[https://search.nixos.org/packages/?query=vimHugeX vimHugeX]</code> attribute name (package name <code>[https://search.nixos.org/packages/?query=vim_configurable vim_configurable]</code>). | ||
</translate> | |||
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
$ nix-env -iA nixos.vimHugeX | $ nix-env -iA nixos.vimHugeX | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:72--> | <!--T:72--> | ||
If you are using <code>vim_configurable.customize</code>, you can enable <code>wrapGui</code> to make <code>gvim</code> available, though this won't give you <code>gview</code>: | If you are using <code>vim_configurable.customize</code>, you can enable <code>wrapGui</code> to make <code>gvim</code> available, though this won't give you <code>gview</code>: | ||
</translate> | |||
<syntaxhighlight lang=nix> | <syntaxhighlight lang=nix> | ||
vim_configured = pkgs.vim_configurable.customize { | vim_configured = pkgs.vim_configurable.customize { | ||
| Line 487: | Line 542: | ||
wrapGui = true; | wrapGui = true; | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight | ||
<translate> | |||
</translate> | </translate> | ||
[[Category:Applications]] | [[Category:Applications]] | ||
[[Category:Text Editor{{#translation:}}]] | [[Category:Text Editor{{#translation:}}]] | ||