Skip to content
kd
27 Jun 2020
Back to blog

Three built-in `neovim` features

2 min read (270 words)

Table of contents

I want to share three built-in neovim features that I think are under the category of "quality of life improvements". They are live substitution, highlight yanked text, and the built-in language server protocol support.

Live Substitution

By default, vim’s :substitute command only modifies the document when you execute the command by pressing Enter (<CR>). In neovim, you can update the document interactively. neovim also shows you a preview window of all the changes you are going to make in the document.

Just add the following option to your vimrc file.

set inccommand=split

Highlight Yanked Text

[If you want to use this feature in neovim v0.4.x or in vim 8, you can do so with this or this plugin. Also, check out this well written post on how this works under the hood.]{.aside}

With the latest version of neovim, you have the ability to highlight yanked text without using any plugins.

At the time of writing, you'll need a v0.5.0 or the nightly1 release of neovim for this feature.

Terminal window
nvim --version | head -1
NVIM v0.5.0-556-ge78658348

You can add the following in your vimrc to enable this feature:

augroup LuaHighlight
autocmd!
autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank()
augroup END

Language Server Protocol

neovim has a built-in implementation of the Language Server Protocol client and default configurations for over 50 languages.

Completion, diagnostics and jump to references in lua.

At the time of writing, you'll need a v0.5.0 or the nightly release of neovim for this feature.

Terminal window
nvim --version | head -1
NVIM v0.5.0-556-ge78658348

While technically you can configure the LSP client straight from your vimrc file, it is easier to use configurations from the neovim/nvim-lsp repository that the neovim developers maintain.

In order to set this up you need to do 3 things:

  1. Add the neovim/nvim-lsp plugin:

    Plug 'neovim/nvim-lsp'
  2. Run :LspInstall {servername}:

    :LspInstall sumneko_lua
    :LspInstall julials
    :LspInstall nimls
    :LspInstall rust_analyzer
    :LspInstall vimls
    :LspInstall pyls
  3. Set up configurations with options in your vimrc:

    lua <<EOF
    local nvim_lsp = require'nvim_lsp'
    nvim_lsp.sumneko_lua.setup()
    nvim_lsp.julials.setup()
    nvim_lsp.nimls.setup()
    nvim_lsp.vimls.setup()
    nvim_lsp.pyls.setup{
    settings = {
    pyls = {
    configurationSources = {
    pycodestyle,
    flake8
    }
    }
    }
    }
    EOF

Footnotes

  1. Precompiled binaries are available on the github releases page.


Citation

@online{krishnamurthy2020threebuiltinneovimfeatures,
  author = {Dheepak Krishnamurthy},
  title = {Three built-in `neovim` features},
  year = {2020},
  date = {2020-06-27},
  url = {https://kdheepak.com/blog/three-built-in-neovim-features/},
  langid = {en},
}

For attribution, please cite this work as:

Dheepak Krishnamurthy, "Three built-in `neovim` features", June 27, 2020 https://kdheepak.com/blog/three-built-in-neovim-features/


Using `pre-commit` hooks
The egg tower puzzle