Hello,
I'm new to Nim and I wanted to use Vim/NeoVim as my main editor.
Here's my setup with language server support, etc.
Maybe it helps someone else.
Prerequisites:
The original blog post (with better formatting) is here: https://www.rockyourcode.com/setup-nim-with-neovim/
Install a language server protocol implementation for Vim. [LanguageClient-neovim][languageclient] is the only one I could get working with several languages (Elixir, Reason, JavaScript, Nim).
For example, with vim-plug:
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'bash install.sh',
\ }
Install [nimlsp][nimlsp]. Run this command in your terminal:
nimble install nimlsp
Configure the plugins within your vim configuration (~/.vimrc or similar):
set hidden
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
let g:LanguageClient_serverCommands = {
\ 'nim': ['~/.nimble/bin/nimlsp'],
\ }
The setup specifies the location of nimlsp. On your computer, it might be different.
Now you can open a Nim file, and hit F5. The LanguageClient menu will pop up.
You can fine-tune the LanguageClient configuration to your liking.
Use :h LanguageClient within Vim to get more information.
[nimlsp][nimlsp] can be a bit peculiar about its setup. The language server needs some of Nim's files in order to work properly..
You might want to check out the [GitHub repository][nimlsp] for further trouble-shooting.
You can use [Vim's inbuilt completion][vimtyping], but the easier way is to install a completion plugin.
[VimCompletesMe][vimcompletesme] is a minimal plugin that does everything I need.
Plug 'ajh17/VimCompletesMe'
[ALE (Asynchronous Lint Engine)][ale] is a plugin providing linting (syntax checking and semantic errors) in NeoVim 0.2.0+ and Vim 8 while you edit your text files.
Install it with your package manager (or find alternative instructions on GitHub):
Plug 'dense-analysis/ale'
Example setup in your init.vim (or ~/.vimrc, etc.):
let g:ale_sign_error = '✘'
let g:ale_sign_warning = '⚠'
highlight ALEErrorSign ctermbg =NONE ctermfg=red
highlight ALEWarningSign ctermbg =NONE ctermfg=yellow
let g:ale_linters_explicit = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_enter = 0
let g:ale_lint_on_save = 1
let g:ale_fix_on_save = 1
let g:ale_linters = {
\ 'nim': ['nimlsp', 'nimcheck'],
\}
let g:ale_fixers = {
\ 'nim': ['nimpretty'],
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\}
Improve ALE's performance by setting the linters you need and don't lint every time you type in something.
Fix a file when you save or call :ALEFix manually.
See :h ale for more information.
One thing I really hate about Nim is its use of whitespace, particularly in regards for disallowing tabs. I've been going pluginless for a couple of years now, and want to keep it that. I like to be able to get my installations from 0 to working in as little time as possible.
For some reason, I couldn't get vim embedded instructions to do the tabs properly. I don't what the problem was. I tried using nvim, and it seemed more cooperative.
Nowadays, with vim 8 & neovim's packages feature (see :h packages) it has never been easier to maintain a full setup that you can just clone from your git and got everything working right after :)
For some reason, I couldn't get vim embedded instructions to do the tabs properly. I don't what the problem was. I tried using nvim, and it seemed more cooperative.
How did you set it up?
hello, if you are using neovim, maybe you can have a try with SpaceVim, which is a module configuration for neovim and vim8. checkout my old post for more info.