wiki/editor.neovim.lua.html
2022-07-29 15:41:17 +00:00

33 lines
20 KiB
HTML

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Neovim Lua integration</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
MathJax = {
tex: {
inlineMath: [ [&#x27;$&#x27;,&#x27;$&#x27;], [&#x27;\(&#x27;,&#x27;\)&#x27;] ],
displayMath: [ [&#x27;$$&#x27;,&#x27;$$&#x27;], [&#x27;[&#x27;,&#x27;]&#x27;] ]
},
options = {
processHtmlClass = &quot;math&quot;
}
}
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Neovim Lua integration</h1><section class="post-metadata"><span>Date: <!-- -->2021-07-15 07:45:50 +08:00</span><span>Date modified: <!-- -->2022-04-20 21:19:43 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/editor.neovim.lua#setting-configuration-with-lua" class="toc-link toc-link-h1">Setting configuration with Lua</a></li><li class="toc-item toc-item-h1"><a href="/wiki/editor.neovim.lua#real-life-examples-making-use-of-neovim-lua-api" class="toc-link toc-link-h1">Real-life examples making use of Neovim Lua API</a></li></ol></nav><ul><li><p>with Lua integration, you can create <a href="/wiki/editor.neovim.lua-modules">Neovim Lua modules</a></p></li><li><p>you can start with <code class="inline-verbatim">lua-intro</code> section from <a href="/wiki/editor.neovim.help-system">Neovim help system</a>;
it gives all of the information on the things you need to get started with configuring Neovim with Lua as well as pointers for more things to do with Lua;
</p></li><li><p>Neovim also extends the Lua standard library found in <code class="inline-verbatim">vim</code> object;
see the <code class="inline-verbatim">lua-stdlib</code> in <a href="/wiki/editor.neovim.help-system">Neovim help system</a></p></li></ul><h1 id="setting-configuration-with-lua">Setting configuration with Lua</h1><p>There are some equivalent setting values in Lua versus Vimscript.
For more information, see the <code class="inline-verbatim">lua-vimscript</code> help section.
</p><table><thead><tr><th>Description</th><th>Vimscript statement</th><th>Lua equivalent</th></tr></thead><tbody><tr><td>Setting options</td><td><code class="inline-code">set number relativenumber</code></td><td><code class="inline-code">vim.opt.number, vim.opt.relativenumber = true, true</code></td></tr><tr><td>Setting local options</td><td><code class="inline-code">setlocal spell</code></td><td><code class="inline-code">vim.opt_local.spell = true</code></td></tr><tr><td>Running Vimscript commands</td><td><code class="inline-code">colorscheme nord</code></td><td><code class="inline-code">vim.cmd &quot;colorscheme nord&quot;</code></td></tr><tr><td>Setting buffer-specific options</td><td><code class="inline-code">b:ale-enabled=1</code></td><td><code class="inline-code">vim.b[&quot;ale-enabled&quot;] = 1</code></td></tr></tbody></table><p>Some more general things you generally want to know:
</p><ul><li><p>You can still execute Vimscript with <code class="inline-verbatim">vim.cmd</code>.
For more information, see <code class="inline-verbatim">:h lua-vimscript</code> from the help system.
</p></li><li><p>You can access environment variables through <code class="inline-verbatim">vim.env</code> — e.g., <code class="inline-code">vim.env.HOME</code>, <code class="inline-code">vim.env.MYVIMRC</code>.
</p></li><li><p>Highlight options are mostly in <code class="inline-verbatim">vim.highlight</code> — e.g., <code class="inline-code">highlight clear SpellCap</code> versus <code class="inline-code">vim.highlight</code>.
</p></li><li><p>You can manipulate variables of various scopes from <code class="inline-verbatim">vim.{g,b,..,t}</code>.
To see more details, see <code class="inline-verbatim">lua-vim-variables</code> help section.
</p></li><li><p><code class="inline-verbatim">vim.opt</code> will return an Option object, it has a common API.
to learn more about it, see <code class="inline-verbatim">vim.opt</code> and its subsections.
</p></li></ul><h1 id="real-life-examples-making-use-of-neovim-lua-api">Real-life examples making use of Neovim Lua API</h1><p>This is a list of <a href="/wiki/editor.neovim.lua-modules">Neovim Lua modules</a> that can serve as a basis for learning to interact Neovim with Lua.
</p><ul><li><p><a href="https://github.com/savq/paq-nvim">paq-nvim</a> is a simple Neovim package manager
</p></li><li><p><a href="https://github.com/wbthomason/packer.nvim">packer.nvim</a> is a more comprehensive package manager
</p></li><li><p><a href="https://github.com/L3MON4D3/LuaSnip">LuaSnip</a> is a snippet engine
</p></li><li><p><a href="https://github.com/nvim-telescope/telescope.nvim">telescope.nvim</a> is a fuzzy finder integrated inside Neovim
</p></li></ul><p>Several people have already replaced their already existing Vim configurations with Neovim.
</p><ul><li><p>TJ DeVries&#x27; <a href="https://github.com/tjdevries/config_manager/">Neovim config</a> is fully written in Lua complete with his own plugins.
</p></li><li><p>ThePrimeagen&#x27;s <a href="https://github.com/ThePrimeagen/.dotfiles/">public dotfiles</a> contains Neovim config written in Lua.
</p></li></ul></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2021-07-15 07:45:50 +08:00\"","date_modified":"\"2022-04-20 21:19:43 +08:00\"","language":"en","source":""},"title":"Neovim Lua integration","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"setting-configuration-with-lua"},"children":[{"type":"text","value":"Setting configuration with Lua"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/editor.neovim.lua#setting-configuration-with-lua"},"children":[{"type":"text","value":"Setting configuration with Lua"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"real-life-examples-making-use-of-neovim-lua-api"},"children":[{"type":"text","value":"Real-life examples making use of Neovim Lua API"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/editor.neovim.lua#real-life-examples-making-use-of-neovim-lua-api"},"children":[{"type":"text","value":"Real-life examples making use of Neovim Lua API"}]}]}]}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"with Lua integration, you can create "},{"type":"element","tagName":"a","properties":{"href":"/editor.neovim.lua-modules"},"children":[{"type":"text","value":"Neovim Lua modules"}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"you can start with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"lua-intro"}]},{"type":"text","value":" section from "},{"type":"element","tagName":"a","properties":{"href":"/editor.neovim.help-system"},"children":[{"type":"text","value":"Neovim help system"}]},{"type":"text","value":";\n it gives all of the information on the things you need to get started with configuring Neovim with Lua as well as pointers for more things to do with Lua;\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Neovim also extends the Lua standard library found in "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"vim"}]},{"type":"text","value":" object;\n see the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"lua-stdlib"}]},{"type":"text","value":" in "},{"type":"element","tagName":"a","properties":{"href":"/editor.neovim.help-system"},"children":[{"type":"text","value":"Neovim help system"}]}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"setting-configuration-with-lua"},"children":[{"type":"text","value":"Setting configuration with Lua"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"There are some equivalent setting values in Lua versus Vimscript.\nFor more information, see the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"lua-vimscript"}]},{"type":"text","value":" help section.\n"}]},{"type":"element","tagName":"table","properties":{},"children":[{"type":"element","tagName":"thead","properties":{},"children":[{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"Description"}]},{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"Vimscript statement"}]},{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"Lua equivalent"}]}]}]},{"type":"element","tagName":"tbody","properties":{},"children":[{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Setting options"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"set number relativenumber"}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"vim.opt.number, vim.opt.relativenumber = true, true"}]}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Setting local options"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"setlocal spell"}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"vim.opt_local.spell = true"}]}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Running Vimscript commands"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"colorscheme nord"}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"vim.cmd \"colorscheme nord\""}]}]}]},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"Setting buffer-specific options"}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"b:ale-enabled=1"}]}]},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"vim.b[\"ale-enabled\"] = 1"}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Some more general things you generally want to know:\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can still execute Vimscript with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"vim.cmd"}]},{"type":"text","value":".\n For more information, see "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":":h lua-vimscript"}]},{"type":"text","value":" from the help system.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can access environment variables through "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"vim.env"}]},{"type":"text","value":" — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"vim.env.HOME"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"vim.env.MYVIMRC"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Highlight options are mostly in "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"vim.highlight"}]},{"type":"text","value":" — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"highlight clear SpellCap"}]},{"type":"text","value":" versus "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"vim.highlight"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can manipulate variables of various scopes from "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"vim.{g,b,..,t}"}]},{"type":"text","value":".\n To see more details, see "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"lua-vim-variables"}]},{"type":"text","value":" help section.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"vim.opt"}]},{"type":"text","value":" will return an Option object, it has a common API.\n to learn more about it, see "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"vim.opt"}]},{"type":"text","value":" and its subsections.\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"real-life-examples-making-use-of-neovim-lua-api"},"children":[{"type":"text","value":"Real-life examples making use of Neovim Lua API"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This is a list of "},{"type":"element","tagName":"a","properties":{"href":"/editor.neovim.lua-modules"},"children":[{"type":"text","value":"Neovim Lua modules"}]},{"type":"text","value":" that can serve as a basis for learning to interact Neovim with Lua.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://github.com/savq/paq-nvim"},"children":[{"type":"text","value":"paq-nvim"}]},{"type":"text","value":" is a simple Neovim package manager\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://github.com/wbthomason/packer.nvim"},"children":[{"type":"text","value":"packer.nvim"}]},{"type":"text","value":" is a more comprehensive package manager\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://github.com/L3MON4D3/LuaSnip"},"children":[{"type":"text","value":"LuaSnip"}]},{"type":"text","value":" is a snippet engine\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://github.com/nvim-telescope/telescope.nvim"},"children":[{"type":"text","value":"telescope.nvim"}]},{"type":"text","value":" is a fuzzy finder integrated inside Neovim\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Several people have already replaced their already existing Vim configurations with Neovim.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"TJ DeVries' "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/tjdevries/config_manager/"},"children":[{"type":"text","value":"Neovim config"}]},{"type":"text","value":" is fully written in Lua complete with his own plugins.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"ThePrimeagen's "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/ThePrimeagen/.dotfiles/"},"children":[{"type":"text","value":"public dotfiles"}]},{"type":"text","value":" contains Neovim config written in Lua.\n"}]}]}]}]},"backlinks":[]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["editor.neovim.lua"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html>