What’s Next for Neovim

Neovim is an ambitious project. In the following sections, I’ll discuss some of the features that you can expect to see in a future release of Neovim.

Externalizing the User Interface

Vim’s user interface (UI) can appear differently depending on the environment in which it runs. Most commonly, Vim runs inside a terminal user interface (TUI), where everything must be rendered using ASCII text. You can also run Vim within a graphical user interface (GUI), where certain parts of the interface can be rendered using graphical elements.

To begin with, we’ll look closely at Vim’s tab bar. This UI element has had the capability to be rendered graphically since version 7.0 of Vim, making this example relevant for both Vim 8 and Neovim. Next, we’ll consider other parts of the UI that could benefit from similar treatment. Externalizing these UI elements is on Neovim’s roadmap.

The Tab Bar

By default, the tab bar becomes visible at the top of the screen when you open two or more tab pages. It lets you know how many tab pages are open and which one is currently active. If you have mouse support enabled, you can select or rearrange the tab pages by clicking or dragging the items in the tab bar.

When Vim runs inside a TUI, it renders the tab bar using ASCII text. Inside a GUI, the tab bar is rendered as a graphical widget. Compare how these look in the following figure (terminal Vim is on the top; MacVim is on the bottom):

images/tabs-screenshots_1.png

images/tabs-screenshots_2.png

These differ in appearance, but the functionality is the same. In the TUI, the ASCII tab bar is your only option. But in the GUI, you can have it whichever way you like (:set guioptions-=e will disable the graphical tab bar).

GVim has had the capability for a long time to render a graphical tab bar, instead of showing the ASCII text version. Other parts of Vim’s user interface could benefit from being rendered graphically. In the next section, we’ll consider the pop-up menu.

The Pop-Up Menu

Vim’s pop-up menu (PUM) appears when you invoke completion, for example, by pressing <C-n> in Insert mode. The PUM presents you with a list of options, allowing you to select an item and insert it into the document at the current cursor position. You can see how it looks in the following figure:

images/completion-screenshots.png

The top screenshot shows how the PUM looks in terminal Vim: it’s constrained to a grid whose cell dimensions are determined by the font size. The colors of the selected item and the other items are determined by the active color scheme. With Vim 8, the pop-up menu always looks the same, whether running in the terminal or in a GUI. But Neovim has made it so that the PUM can be rendered externally by a GUI.

The bottom screenshot shows the same scene using a Neovim GUI called gonvim,[69] which renders the PUM using a graphical widget. This version of the PUM is not constrained to the ASCII grid, so the font size and line spacing can be changed independently from those used elsewhere in the UI.

This opens up new possibilities. For example, suppose you configured Neovim so that when you invoke completion, each suggestion in the menu has some associated metadata. Instead of simply showing a list of possible completions, the PUM could display the metadata alongside each suggestion. In this screenshot, each item in the menu is prefixed with the letter “b,” which indicates that the suggestion was generated by scanning the list of open buffers.

Tiled Windows and Status Line

With Vim you can divide your workspace into a tiled layout by creating vertical or horizontal splits. Vim draws dividing lines between windows using ASCII characters: a line of | characters separates vertical splits, while horizontal splits are divided with a status line. That’s appropriate in the context of a TUI environment, but what about in a GUI? Wouldn’t it be neat if the graphical environment could take care of rendering the tiling windows? For example, the GUI could use a visual effect to highlight the window that is currently active (or to de-emphasize the inactive windows). Neovim plans to externalize the window drawing UI, which would make it possible for GUIs to do this.

Vim’s status line appears at the bottom of each split window. By default, the status line shows the file path of the current buffer. You can customize this to show other information, such as the name of the current branch if you’re working in a Git repository.

The Vim-Airline plugin[70] customizes the appearance of Vim’s status line in a way that’s quite eye-catching. To achieve this effect, not only do you have to install the Vim plugin, but you also need to install a patched font and use it in your terminal. On GitHub, you can find a repository of patched fonts for various monospaced fonts.[71] Using a patched font in your terminal gives you the capability to use icons that wouldn’t otherwise be available in a TUI environment. That’s a pretty ingenious hack!

Alternatively, imagine if you could simply ask the GUI to render the status line. Neovim plans to externalize the status line rendering, so that in a GUI environment, you could render whatever graphical icons you please. Given the popularity of the Vim-Airline plugin (with more than 10,000 stars on GitHub), it seems likely that this would be a good selling point for running Neovim in a GUI.

GUIs for Neovim

One of the goals of the Neovim project is to make it possible to create better GUIs by externalizing some of the UI. The Neovim core team doesn’t maintain a GUI, but you can find a list of GUIs on the Related Projects wiki page.[72]

At present, most of the GUIs for Neovim are experimental projects. These come in various different flavors. For example, Gonvim is implemented using GoLang with the QT graphical framework.[73] Oni is an Electron app, implemented using TypeScript.[74] VimR uses the Cocoa framework for macOS and is implemented in Swift and Objective C.[75] Each of these GUIs has some neat features that really differentiate it from the terminal Vim experience. If you’re curious, I recommend trying them out.

There’s a radical alternative way to create a Neovim GUI: embedding it inside of another text editor. Let’s explore this idea in the next section.

Embedding Neovim in Other Editors

You can find Vim-emulation plugins for many text editors. These usually work by implementing a subset of Vim’s features. When you begin using a Vim-emulation plugin, it’s usually a matter of minutes before you discover a command that’s missing, or whose behavior differs subtly from the equivalent command in Vim. As a result, these Vim-emulation plugins often fall into the “uncanny valley,” making them somewhat unsatisfying to use.

Instead of reimplementing Vim’s features from scratch, what if you could actually embed Vim inside of another text editor? Imagine if your Vim emulator actually loaded the settings from your vimrc and used any Vim plugins you had installed? Neovim makes this possible.

Sublime Text[76] and Virtual Studio Code[77] are both programmer’s text editors that are available for Linux, Windows, and macOS. Each of these editors can embed Neovim, if you install the right plugin.

ActualVim for Sublime Text 3

Sublime Text 3 ships with a Vim-emulation plugin called Vintage mode, which is disabled by default. If you want to use Vim-style commands in Sublime Text, you simply have to enable the Vintage mode plugin.

Alternatively, you could install ActualVim,[78] by Ryan Hileman. This plugin actually embeds an instance of Neovim inside Sublime Text (hence the name ActualVim!). You get to use all the features of Sublime Text in combination with true Vim commands.

VSCodeVim for VSCode

You can enable Vim emulation for VSCode by installing the VSCodeVim plugin.[79] Like most Vim emulators, this plugin simulates a subset of Vim’s Normal mode commands. Optionally, you can configure the plugin to embed an instance of Neovim. By doing so, you get to use Ex commands such as :substitute, :global, and :normal. The plugin doesn’t emulate these commands; it delegates them to the embedded Neovim instance.

In its current form, the VSCodeVim plugin uses a mixture of the two approaches: emulation for Normal mode commands and delegation for Ex commands. One of the main contributors to the plugin, Horace He, is now rewriting it so as to use an embedded Neovim instance for Normal mode commands as well. Stripping out the Vim emulation code makes for a much smaller codebase. It’s still a work in progress, but if you want to try it out you can find the VSCodeNeovim repository on GitHub.[80]

Challenges of Embedding Neovim

When you embed Neovim inside of a host text editor, there are bound to be some features that overlap. For example, tab pages and split windows are commonly used for organizing your workspace within a text editor. Neovim supports these features, and if you embed Neovim inside a host editor that supports similar features, then you’ll have two overlapping feature sets for organizing your workspace. That could be pretty confusing for users. To keep things simple, it would make sense to disable commands such as :split, :vsplit, and :tabedit in the embedded instance of Neovim, leaving the host text editor in charge of managing your workspace.

Another basic feature that will likely overlap between the host editor and the embedded Neovim instance is undo. Allowing both text editors to keep track of the undo history could lead to strange results, especially if the editors have different ideas about what counts as an “undoable” change. Once again, putting either the host editor or the embedded Neovim instance in charge of this feature would make for better usability.

When implementing a traditional Vim-emulator plugin, you typically have to make a decision over which parts of Vim’s functionality to re-implement from scratch. Whereas when implementing a plugin that embeds Neovim, instead you have to decide which parts of Vim’s functionality you want to surface and which parts you need to hide. That’s a different kind of challenge.

Making Neovim embeddable is one of the major goals of the Neovim project. As I write this, Sublime Text and VSCode are the only text editors that can embed Neovim, but I expect to see similar plugins for other text editors soon. Anyone who wants to try embedding Neovim inside another text editor can use the ActualVim and VSCodeVim plugins as reference material.

Throughout this book, I’ve presented various tips to show how you can turn Vim into a development environment. The fact that Neovim can be embedded inside other text editors presents an alternative approach. You can use the host text editor as your development environment, while using Vim’s modal input model for the mechanical act of editing text. To put it another way: instead of turning Vim into an IDE, you can bring Vim into your IDE.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.66.178