How to convert th recipes part to lua format?
singlexyz opened this issue · 8 comments
You mean you want to define those recipes by lua interface in Neovim?
You mean you want to define those recipes by lua interface in Neovim?
Yes, I think I should read the nvim-lua documentation.
Unfortunately, I'm not familiar with neither lua nor neovim, but it is just to set a global variable. There should be a way to do. Probably, :help lua-vim-variables
might help.
If anyone comes across this, after lots of trial and error I have converted the vim surround keybindings to Lua (I am using packer but this code can be used for other plugin managers too):
use {
'machakann/vim-sandwich',
config = function()
-- Use vim surround-like keybindings
vim.cmd('runtime macros/sandwich/keymap/surround.vim')
-- '{' will insert space, '}' will not
vim.g['sandwich#recipes'] = vim.list_extend(vim.g['sandwich#recipes'], {
{ buns = { '{ ', ' }' }, nesting = 1, match_syntax = 1, kind = { 'add', 'replace' }, action = { 'add' }, input = { '{' } },
{ buns = { '[ ', ' ]' }, nesting = 1, match_syntax = 1, kind = { 'add', 'replace' }, action = { 'add' }, input = { '[' } },
{ buns = { '( ', ' )' }, nesting = 1, match_syntax = 1, kind = { 'add', 'replace' }, action = { 'add' }, input = { '(' } },
{ buns = { '{\\s*', '\\s*}' }, nesting = 1, regex = 1, match_syntax = 1, kind = { 'delete', 'replace', 'textobj' }, action = { 'delete' }, input = { '{' } },
{ buns = { '\\[\\s*', '\\s*\\]' }, nesting = 1, regex = 1, match_syntax = 1, kind = { 'delete', 'replace', 'textobj' }, action = { 'delete' }, input = { '[' } },
{ buns = { '(\\s*', '\\s*)' }, nesting = 1, regex = 1, match_syntax = 1, kind = { 'delete', 'replace', 'textobj' }, action = { 'delete' }, input = { '(' } }
})
end
}
If anyone comes across this, after lots of trial and error I have converted the vim surround keybindings to Lua (I am using packer but this code can be used for other plugin managers too):
use { 'machakann/vim-sandwich', config = function() -- Use vim surround-like keybindings vim.cmd('runtime macros/sandwich/keymap/surround.vim') -- '{' will insert space, '}' will not vim.g['sandwich#recipes'] = vim.list_extend(vim.g['sandwich#recipes'], { { buns = { '{ ', ' }' }, nesting = 1, match_syntax = 1, kind = { 'add', 'replace' }, action = { 'add' }, input = { '{' } }, { buns = { '[ ', ' ]' }, nesting = 1, match_syntax = 1, kind = { 'add', 'replace' }, action = { 'add' }, input = { '[' } }, { buns = { '( ', ' )' }, nesting = 1, match_syntax = 1, kind = { 'add', 'replace' }, action = { 'add' }, input = { '(' } }, { buns = { '{\\s*', '\\s*}' }, nesting = 1, regex = 1, match_syntax = 1, kind = { 'delete', 'replace', 'textobj' }, action = { 'delete' }, input = { '{' } }, { buns = { '\\[\\s*', '\\s*\\]' }, nesting = 1, regex = 1, match_syntax = 1, kind = { 'delete', 'replace', 'textobj' }, action = { 'delete' }, input = { '[' } }, { buns = { '(\\s*', '\\s*)' }, nesting = 1, regex = 1, match_syntax = 1, kind = { 'delete', 'replace', 'textobj' }, action = { 'delete' }, input = { '(' } } }) end }
Thanks for the plugin @machakann ! Thanks for the lua version @smjonas !
Could this be included over here as well?
Yes, the Wiki page is not locked. Please feel free to edit.
Yes, the Wiki page is not locked. Please feel free to edit.
It's done! I wasn't aware I could do that.
Thanks!