diff --git a/README.md b/README.md index 3aba0bc..0715788 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,23 @@ Merge this setting into your `coc-settings.json`, which can be opened by `:CocCo See also [the example config for testing](dev/vim-coc.nix). +### Vim with [`vim-lsp`] + +[`vim-lsp`]: https://github.com/prabirshrestha/vim-lsp + +Add the following code to your `vimrc` to register the LSP server. +Thanks @mitchmindtree + +```vim +if executable('nil') + autocmd User lsp_setup call lsp#register_server({ + \ 'name': 'nil', + \ 'cmd': {server_info->['nil']}, + \ 'whitelist': ['nix'], + \ }) +endif +``` + ### Emacs with [`eglot`] [`eglot`]: https://github.com/joaotavora/eglot diff --git a/dev/neovim-lsp.nix b/dev/nvim-lsp.nix similarity index 100% rename from dev/neovim-lsp.nix rename to dev/nvim-lsp.nix diff --git a/dev/vim-lsp.nix b/dev/vim-lsp.nix new file mode 100644 index 0000000..d514857 --- /dev/null +++ b/dev/vim-lsp.nix @@ -0,0 +1,45 @@ +{ pkgs ? import { } }: +pkgs.vim_configurable.customize { + name = "vim-lsp"; + + vimrcConfig = { + packages.myVimPackage.start = with pkgs.vimPlugins; [ + vim-nix # File type and syntax highlighting. + vim-lsp + ]; + + # vim + customRC = '' + source ${./vimrc.vim} + + au BufRead,BufNewFile *.nix setf nix + + autocmd User lsp_setup call lsp#register_server({ + \ 'name': 'nil', + \ 'cmd': {server_info->[$NIL_PATH]}, + \ 'whitelist': ['nix'], + \ }) + autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() + + function! s:on_lsp_buffer_enabled() + setlocal omnifunc=lsp#complete + setlocal tagfunc=lsp#tagfunc + + nmap gd (lsp-definition) + nmap gr (lsp-references) + nmap gs (lsp-document-symbol-search) + nmap gS (lsp-workspace-symbol-search) + nmap gy (lsp-type-definition) + nmap r (lsp-rename) + nmap [g (lsp-previous-diagnostic) + nmap ]g (lsp-next-diagnostic) + nmap (lsp-hover) + nnoremap lsp#scroll(+4) + nnoremap lsp#scroll(-4) + + let g:lsp_format_sync_timeout = 1000 + autocmd BufWritePre *.nix call execute('LspDocumentFormatSync') + endfunction + ''; + }; +} diff --git a/flake.nix b/flake.nix index 5d5dfab..1e20d13 100644 --- a/flake.nix +++ b/flake.nix @@ -71,8 +71,9 @@ jq pre-commit nixpkgs-fmt - (import ./dev/neovim-lsp.nix { inherit pkgs; }) + (import ./dev/nvim-lsp.nix { inherit pkgs; }) (import ./dev/vim-coc.nix { inherit pkgs; }) + (import ./dev/vim-lsp.nix { inherit pkgs; }) ] ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform vscodium) [ (import ./dev/vscodium.nix { inherit pkgs; }) ];