⬆️ ⬇️

Neovim: a modern clone of the Vim text editor

Vim is a powerful text editor with a large audience. Although the program is over 20 years old, its functionality continues to be improved through vimscript scripts. The latest version of the free editor Vim 7.4 was released in August 2013.



The problem is that in two decades Vim has grown to a terrible size: about 300,000 lines of code on C89. “Very few people can understand this code or have the courage to change it. There is a problem with the addition of new code and patches in Vim: the only maintainer is not keeping up with the development of the plug-in ecosystem, ”writes Brazilian programmer Thiago de Arruda Padilha, who created the Neovim project - an updated and improved version of Vim for the 21st century .



As part of the Neovim project, it is planned to aggressively refactor the Vim source code. Goals:



  1. Simplify support and increase the speed of adding patches and new features;
  2. Distribute work among several developers;
  3. Implement a modern GUI as an option;
  4. Improve the extensibility of the editor due to the new plug-in architecture based on coprocesses. Plug-ins can be written on any PL without their explicit support from the editor.


The developer notes that he does not aim to rewrite Vim from scratch and create an IDE, although Neovim does have some IDE features. On the contrary, changes should not greatly change the model of Vim or vimscript as a whole. Most vimscript plugins will continue to work normally.

')

Speaking of specific changes, it is planned to switch to a modern cmake- based build automation system, remove the Vi emulation mode and some other not very important options that make it difficult to maintain the code, and also remove the platform-specific code. Instead, there will be a dynamic link library, libuv, which will perform asynchronous I / O across platforms.



A new system of plug-ins is proposed to build on top of the task management mechanism, similar to this one . Plug-ins can be written in any language, the presence of the plug-in editor will be checked at startup, and each plug-in will work asynchronously, waiting for events and sending commands to Neovim. For example, this is how a plug-in session with json-rpc might look like.



plugin -> neovim: {"id": 1, "method": "listenEvent", "params": {"eventName": "keyPressed"}} neovim -> plugin: {"id": 1, "result": true} neovim -> plugin: {"method": "event", "params": {"name": "keyPressed", "eventArgs": {"keys": ["C"]}}} neovim -> plugin: {"method": "event", "params": {"name": "keyPressed", "eventArgs": {"keys": ["Ctrl", "Space"]}}} plugin -> neovim: {"id": 2, "method": "showPopup", "params": {"size": {"width": 10, "height": 2} "position": {"column": 2, "line": 3}, "items": ["Completion1", "Completion2"]}} plugin -> neovim: {"id": 2, "result": true}} 


This scheme gives Neovim almost unlimited extensibility and at the same time improves the stability of the program, since the plugins are separated from the main source code.



The GUI elements and all corresponding widgets will be removed from the main code. The GUI will connect in approximately the same way as the plugins. The only difference is that the plugins are loaded into Neovim, and Neovim itself is launched from the GUI.



  GUI | ---> Neovim | --->  1 | --->  2 | --->  3 


GUI hypothetical session.



 gui -> vim: {"id": 1, "method": "initClient", "params": {"size": {"rows": 20, "columns": 25}}} vim -> gui: {"id": 1, "result": {"clientId": 1}} vim -> gui: {"method": "redraw", "params": {"clientId": 1, "lines": {"5": " Welcome to neovim! "}}} gui -> vim: {"id": 2, "method": "keyPress", "params": {"keys": ["H", "e", "l", "l", "o"]}} vim -> gui: {"method": "redraw", "params": {"clientId": 1, "lines": {"1": "Hello ", "5": " "}}} 


Thus, modern GUIs written in high-level programming languages ​​and better integrated into the operating system can be incorporated into the editor. Plugins will be able to interact directly with the GUI, like minimap in Sublime. The editor core can be run on the server, and many GUI instances can be run on client machines. The editor can be embedded in other programs, as well as it is actually built into the GUI.



The entire Neovim development is planned on Github . Donations are accepted.

Source: https://habr.com/ru/post/213517/



All Articles