Neovim for Beginners — User Interface

Explore the Neovim UI APIs.

alpha2phi

--

Neovim for Beginners — User Interface

Neovim provides the Lua UI APIs (:h lua-ui) for user interaction. However, the default interface is very primitive. In this article, we will explore the Lua UI APIs and also the plugins to enhance the user interface.

This article is part of the Neovim for Beginners series.

The Neovim configuration files can be found in this repository.

The Basics

In Neovim we have these Lua APIs.

  • vim.ui.input (:h vim.ui.input()) to prompt the user for input. This is similar to the Vimscript input (:h input()) function.
  • vim.ui.select (:h vim.ui.select()) to prompt the user to pick a single item from a collection of entries. This is similar to the Vimscript confirm (:h confirm()) function.

vim.ui.input

Let’s start with the vim.ui.input API.

  • Start Neovim without any plugins.
$ nvim -u NONE
  • Run the Lua file using the command :luafile %
vim.ui.input

The following options are available for the vim.ui.input API.

  • prompt — Text of the prompt.
  • default — Default value.
  • completion — Type of completion (:h command-completion). For our code, we set the completion to “file”. When we press <Tab>, the files and directories are displayed.
  • highlight — A function that will be used for highlighting user input. For our code, we highlight the first 8 characters using the InputHighlight group.
  • on_confirm — A function that is called once the user confirms or aborts the input. The input value is nil if the…

--

--

alpha2phi

Software engineer, Data Science and ML practitioner.