Neovim Built-in Features and Tricks

Few Neovim only features and tricks without any plugins.

Neovim Features and Tricks

Overview

In this article let’s go through a few Neovim only features which I find useful.

Show Effects of a Command Incrementally

Type :h icm to read the help of this command.

This is a global option and by default, it is set to blank.

Possible values are

  • nosplit: Shows the effects of a command incrementally, as you type.
  • split: Also shows partial off-screen results in a preview window.

Works for |:substitute|, |:smagic|, |:snomagic|. |hl-Substitute|

split

Type :set icm=split and now try to perform text substitution.

inccommand=split

A preview window is displayed to show you the live substitution result. You can press Escape to cancel it.

nosplit

Type :set icm=nosplit and now try to perform text substitution.

inccommand=nosplit

As you type you can see the substitution effect directly in the buffer. You can press Escape to cancel the command.

Send LSP Diagnostics to Quickfix Window

Latest Neovim supports LSP natively. With this, you can configure the LSP to send diagnostics to the quick fix window.

You can use this feature together with nvim-bqf or telescope.nvim to preview and perform a fuzzy search.

LSP Diagnostic with telescope.nvim
LSP Diagnostics with nvim-bqf

Dim Inactive Window

Use the following commands to set active and inactive windows to different background colors.

Note: Remember to use set termguicolors, or you can set ctermbg and ctermfg.

hi ActiveWindow guibg=#21242b
hi InactiveWindow guibg=#282C34
set winhighlight=Normal:ActiveWindow,NormalNC:InactiveWindow
winhighlight
  • Put the configuration into after/plugin if you don’t see it take effects.
  • Type :hi to check your existing color scheme to adjust your active window color.
  • Type :h winhighlight and :h hl-NormalNC to read the documentation.

Plugins you can use

TextYankPost

Neovim includes a function for highlighting a selection on yank.

To enable it, use

au TextYankPost * silent! lua vim.highlight.on_yank()

You can customize the highlight group and the duration of
the highlight.

au TextYankPost * silent! lua vim.highlight.on_yank {higroup=”IncSearch”, timeout=150}

If you want to exclude visual selections from highlighting on yank, use

au TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false}

A plugin that you can use

Send Commands to a Terminal

  • Open a vertical split with a terminal :vsp | terminal.
  • Open a Python interpreter (type python).
  • Now type :echo b:terminal_job_id to get the terminal job id. In my case the id is 4.
  • Run the command :call chansend(4, [“print(‘hello’)”, “print(‘world’)”, “”]). This will send 2 Python statements to the Python interpreter.
Send Commands to a Terminal

Type :h chansend to read the documentation.

Check out this article on the plugins that we can use for this purpose, including integration with Jupyter notebook.

Programmer and occasional blogger.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store