tek, thinks & la strada ☯ॐ☢ csmr@kapsi

Nvim 0.7 custom8ng

I'm returning to some dev stuff. Nvim 0.7 is my text editor and my IDE. On vim I had a Language Server for rust, so it should be possible for nvim as well. And what else should nvimmer customize?

The aim is how-to: minimal UI, nice editor config, folds, autocomplete, autobackups. Plus builtin LSP lint and compile, bit of question mark.

Custom init.vim

Nvim uses ~/.config/nvim/init.vim for the basic editor configuration, in Debian Linux.

I already customized init.vim. The defaults are weird. And I want minimal. The readymade statuslines and lua confs have too much stuff and large huge codebases of lua. I got total of 47 lines, base.

Minimal and clear statusline

statusline example image

So my status line in this init.vim contains bufno, edited flag (with emphasis), filename, help/RO-flags, ft/fenc/ff, tabs and cols. Line numbers I keep on the left gutter, only. 8 lines of init.vim.

The statusline truncates the right side first.

Also, cursorline, text tabs, automatic backups

I edit code without decorations, with editor tabs and splits, folds. I prefer 2 space indents, and invisible whitespace chars. This conf also writes a backup copy on every save, appending a timestamp to the filename. 39 lines of code.

What are LSP client, ALE, linters in nvim?

So these must be either plugins, or external programs, for nvim.

In nvim, plugins can be managed manually or with a plugin manager.

LSP is technically just a protocol, for communicating between a language server and your tools. However, LSP client is a builtin in nvim, so some type of setup should be enough.

ALE is for linting, to make sure the code is idiomatic and syntactically correct.

Plugin manger vim-plug install

Attempting to KISS, I just went with vim-plug. It seems simple, as installing a plugin is just one line in init.vim: Plug 'git-url', inside a call plug#begin()-block.

So, installing vim-plug is "just" download of some vimscript into your ~/.local/nvim... What could go wrong! Let's test ale and rubocop and rspec plugins?

In init.vim, I added this section:

" vim-plug 'ins
call plug#begin()
Plug 'dense-analysis/ale'
Plug 'mogulla3/rspec.nvim'
Plug 'ngmy/vim-rubocop'
call plug#end()

Ale has pretty nice commands behind :ALE<tab>, and rubocop still can't be stopped once it is started with :RuboCop<enter> 8). Note, rubocop requires external install, in path.

I fiddled around with Rubocop, a ruby linter. Somehow its vague. I can't seem to disable it, for example, which seems crazy. Only either never enable, or never disable?

For ruby, the job is done

Rubocop is basically a linter, running a language server. Ie. rubocop --lsp is for starting LSP client, so users don’t manually execute it.

Ruby-lsp project uses rubocop as a base for LSP.

So, LSP client conf for nvim?

So I suppose one should first Read The Free Manual? So, check :h lsp<enter>, peek also at lsp-config.

How? Basically, LSP client needs configuration for your language, in after/ftplugin/langname.lua. There is a project called nvim-lspconfig that collects these configurations.

Also, a language server for your particular language is required. Either install one from the package manager, or use the mason.nvim project to install these language servers.

LSP Zero promises a simple setup for nvim LSP client - but for nvim 0.8, but the repo has "you might not need lsp-zero" for 0.7.

Finally, one would configure autocompletion for the same. Perhaps I'll visit this later.

Copyright C. P. - Last Updated - All Rights Reserved - Ask permission to republish.