Imran's Blog
Stuff I feel like blogging about.


Converting my init.vim to lua

Posted on

I use neovim as my main driver for all my coding and text editing needs. They released version 0.5 (up to 0.6 now) which supports having your vim configuration in lua (5.1 via LuaJIT) instead of in vimscript.

I've never used lua before but it's a nice small language. LuaJIT is also crazy fast. You can find most of what you need to know with either :h lua and some syntax reference. One of the nicest changes is the ability to use maps for storing configuration for plugins. For example the following ale configuration:

let g:ale_fixers = {
\   '*': ['remove_trailing_lines', 'trim_whitespace'],
\   'python': ['autopep8', 'black', 'isort'],
\   'javascript': ['eslint'],
\   'vue': ['eslint'],
\   'dhall': ['dhall-format'],
\   'go': ['gofmt'],
\   'rust': ['rustfmt']
\}

Becomes this:

vim.g.ale_fixers = {
    ["*"] = { "remove_trailing_lines", "trim_whitespace" },
    python = { "autopep8", "black", "isort" },
    javascript = { "eslint" },
    vue = { "eslint" },
    dhall = { "dhall-format" },
    go = { "gofmt" },
    rust = { "rustfmt" }
}

Some rough spots still exist (e.g. auto commands) but there is a nice vim.cmd escape hatch that can still take regular vimscript. Super excited to see what else is in store for this project!