Giter Site home page Giter Site logo

drgo / nvim-example-lua-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jacobsimpson/nvim-example-lua-plugin

0.0 1.0 0.0 20 KB

A simple Neovim Lua plugin using the Lua embedded in Neovim, suitable as a template.

License: The Unlicense

Shell 11.68% Lua 45.11% Vim Script 43.21%

nvim-example-lua-plugin's Introduction

nvim-example-lua-plugin

Introduction

Newer versions of Neovim include an embedded lua interpreter, making it possible to write non-remote plugins using Lua instead of Vimscript.

This is a minimal example of an embedded Lua plugin. When you want to create a new Lua plugin, you should be able start from a working plugin by running:

bash \
  <(curl -o- https://raw.githubusercontent.com/jacobsimpson/nvim-example-lua-plugin/master/install.sh) \
  mynewplugin

and following the instructions on the screen.

Installing Manually

The intention of this repository is to make it quick and easy to start a new plugin. If you don’t want to run the included bash script, it is also possible to do the steps manually.

git clone --depth 1 \
    https://github.com/jacobsimpson/nvim-example-lua-plugin \
    ~/nvim-example-lua-plugin
rm -Rf ~/nvim-example-lua-plugin/.git

After that, to load Neovim with the development version of your plugin, execute a command to modify the runtimepath on startup:

nvim --cmd "set rtp+=./nvim-example-lua-plugin"

Testing the New Plugin

There are some messages that should be printed to the console as Neovim is starting up, to confirm that the different parts of the plugin are executing correctly:

  1. Confirm that the VimL portions of the plugin are loading correctly.

    nvim-example-lua-plugin.vim: VimL code executing.
  2. Confirm the Lua block in the VimL file is executing.

    nvim-example-lua-plugin.vim: Lua code executing.
  3. Confirm the code from the Lua module is executing.

    nvim-example-lua-plugin.luamodule.showstuff: hello

There is a function defined in the VimL portion of the plugin which echos some text. You can execute the function like this:

:exec LuaDoItVimL()

There is a function defined in the same VimL file, in a Lua block. You can execute the function like this:

:luado lua_do_it_lua()

Plugin Development

Debugging

To test changes quickly, I usually reload the current file into the embedded Lua interpreter after changes:

:luafile %

Handy Vim/Lua Commands

See the Lua version you have available:

:lua print(_VERSION)

Directly execute an arbitrary Lua function that has been defined in the Lua interpreter embedded in Neovim.

:lua doit()

To apply a Lua function to each line:

:[range]luado {body}	Execute Lua function "function (line, linenr) {body}
			end" for each line in the [range], with the function
			argument being set to the text of each line in turn,

To define an arbitrary function in the Lua interpreter embedded in Neovim:

  • Highlight the code block.

  • Yank

  • :luado ^r"<CR>

function execute_lua_block()
    print("this is the thing.")
end

To map an arbitrary Lua function to a Neovim keybinding:

nmap <C-l-e> :lua execute_lua_block()<CR>

To see information about the Neovim API available in Lua:

:help api.txt

nvim-example-lua-plugin's People

Contributors

jacobsimpson avatar panky-codes avatar tssm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.