This handy dandy function inserts the current date and time on the current line after the cursor:
function! InsertDate() execute "normal \"=strftime('%FT%T%z')\<CR>p" endfunction
I think Neovim's Lua API is meant to simplify this kind of junk, but the only way I've found to do this in Lua is quite verbose:
function insert_date() local pos = vim.api.nvim_win_get_cursor(0) local line = vim.api.nvim_get_current_line() local new_line = line:sub(0, pos) .. os.date('%FT%T%z') .. line:sub(pos + 1) vim.api.nvim_set_current_line(new_line) end
What I really want is something like this:
function insert_date() vim.buffer.insert(os.date('%FT%T%z')) end
Is there an easier way to insert text with Lua?
normal) with Vim APS script. If you would have to implement the functionality using the VimScript API it would have been quite similar to what you wrote in lua. To my understanding the benefit to have lua is not to simplify but to use a widespread language (lua) and benefit from its momentum instead of using a language that is only developed for Vim (VimScript). What you can expect from using lua is a better or more accessible documentation, more language functionalities, more libraries, better performance.