How to convert this vimscript code into Lazyvim Lua code?
function! BreakHere() s/^\(\s*\)\(.\{-}\)\(\s*\)\(\%#\)\(\s*\)\(.*\)/\1\2\r\1\4\6 call histdel("/", -1) endfunction nnoremap K :<C-u>call BreakHere()<CR> How to convert this vimscript code into Lazyvim Lua code?
function! BreakHere() s/^\(\s*\)\(.\{-}\)\(\s*\)\(\%#\)\(\s*\)\(.*\)/\1\2\r\1\4\6 call histdel("/", -1) endfunction nnoremap K :<C-u>call BreakHere()<CR> I would do:
vim.keymap.set('n', 'K', function() vim.cmd([[s/^\(\s*\)\(.\{-}\)\(\s*\)\(\%#\)\(\s*\)\(.*\)/\1\2\r\1\4\6]]) vim.fn.histdel('/', -1) end, {}) Remark:
vim.keymap.set api[[...]] is the Lua notation for raw string (the equivalent of r".." string in Python).vim.fn collectionRemark: for LazyVim the mapping code standard location is ~/.config/nvim/lua/config/keymaps.lua on Linux and ~/AppData/Local/nvim/lua/config/keymaps.lua on Windows.
Remark: Here is a variation of the expression that avoid breaking within the words:
vim.keymap.set('n', 'K', function() vim.cmd([[s/\v^(\s*)(.{-})(>\s*)(\S*%#)(\s*)(.*)/\1\2\r\1\4\6]]) vim.fn.histdel('/', -1) end, {}) Remark: If autoindent is set you could also do approximate with:
vim.keymap.set('n', 'K', 'EBi<CR><Esc>EB', {}) function! BreakHere() s/^\(\s*\)\(.\{-}\)\(\s*\)\(\%#\)\(\s*\)\(.*\)/\1\2\r\1\4\6 call histdel("/", -1) endfunction nnoremap K :<C-u>call BreakHere()<CR>