dotfiles/config/nvim/after/ftplugin/lua.lua
Fernando Schauenburg 38476f668c vim: add feedback for lua executor
This is useful when executing lines that produce no output, so I have
some confidence that something actually happened when pressing the key
bindings.

I am printing the message before executing the command because otherwise
this feedback would shadow the output of the command being executed
(which I am presumably interested in and would serve itself as
feedback).
2022-09-28 23:01:12 +02:00

22 lines
740 B
Lua

vim.bo.tabstop = 2
local buffer = { buffer = true }
local exec_current_lua_line = function()
local lineno = vim.fn.line('.')
print('Executing line ' .. lineno)
vim.fn.luaeval(vim.fn.getline(lineno))
end
local exec_current_lua_selection = function()
local selection = { vim.fn.line('v'), vim.fn.line('.') }
local first, last = vim.fn.min(selection), vim.fn.max(selection)
local code = vim.fn.join(vim.fn.getline(first, last), '\n')
print('Executing lines ' .. first .. ' to ' .. last)
loadstring(code)()
end
vim.keymap.set('n', '<leader>x', exec_current_lua_line, buffer)
vim.keymap.set('x', '<leader>x', exec_current_lua_selection, buffer)
vim.keymap.set('n', '<leader><leader>x', '<cmd>write | luafile %<cr>', buffer)