As described in README, many APIs are available in NyaoVim; APIs, Node.js APIs, Electron APIs, Neovim msgpack-rpc APIs), so many npm packages. In addition to them, NyaoVim offers some extra APIs.
- API in Vim script
- Subscriable events
Vim script interface is defined in this directory. The directory is added to runtimepath
at Neovim starting. All are defined in nyaovim#
namespace.
Load UI plugin from the runtimepath
directory. It searches nyaovim-plugin
directory and HTML files in the directory. Then load HTML files with <link rel="import">
.
Directly load HTML from html_path
HTML file with <link rel="import">
.
Load script_path
JavaScript file with Node.js's require()
function.
Call JavaScript func_name
global function with args
. args
values in Vim script will be converted to JavaScript values.
Open DevTools for NyaoVim. mode
determines how to open DevTools window and should be one of 'right'
, 'bottom'
, 'undocked'
or 'detach'
. If omitted, 'detach'
will be set.
Execute JavaScript code from Vim script with code
string. With this function, you can run various APIs directly from Vim script. Below is a code to toggle window fullscreen.
call nyaovim#execute_javascript('(function(){
\ const win = require("electron").remote.getCurrentWindow();
\ win.setFullScreen(!win.isFullScreen());
\ })()')
TODO: This function currently doesn't return the result of evaluating JavaScript.
Call BrowserWindow
API in Electron for the main window. This function is currently using notification. So Vim script side can't receive the return value.
" Calls `window.setFullScreen(true);` in the main window
call nyaovim#browser_window('setFullScreen', [v:true])
With Neovim msgpack API, you can receive rpc nortifications.
const neovim_element = document.getElementById('neovim');
const client = neovim_element.editor.getClient();
client.on('notification', (func_name, args) => {
switch (func_name) {
case 'nyaovim:edit-start':
// Do something
break;
default:
break;
}
});
NyaoVim defines some notifications to use internally and UI plugins can also use them.
This notification is sent when Neovim starts to edit some buffer. It passes the file path to 1st argument.