Skip to content

Commit

Permalink
feat(plugins): add printer plugin with gp keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
ecosse3 committed Jan 1, 2023
1 parent e1c08b4 commit dbbd3ec
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lua/plugins/printer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require('printer').setup({
keymap = "gp", -- Plugin doesn't have any keymaps by default
behavior = "insert_below", -- how operator should behave
-- "insert_below" will insert the text below the cursor
-- "yank" will not insert but instead put text into the default '"' register
formatters = {
-- you can define your formatters for specific filetypes
-- by assigning function that takes two strings
-- one text modified by 'add_to_inside' function
-- second the variable (thing) you want to print out
-- see examples in lua/formatters.lua
lua = function(inside, variable)
return string.format('print("%s: " .. %s)', inside, variable)
end,
typescriptreact = function(inside, variable)
return string.format("console.log('%s: ', %s)", inside, variable)
end,
},
-- function which modifies the text inside string in the print statement, by default it adds the path and line number
-- add_to_inside = function(text)
-- return string.format("[%s:%s] %s", vim.fn.expand("%"), vim.fn.line("."), text)
-- end,
-- set to to indenity function to turn off the default behaviour
-- add_to_inside = function(text)
-- return text
-- end,
})

-- You can use use '<Plug>printer_print' to call the pluging inside more advanced keymaps
-- for example a keymap that always adds a prnt statement based on 'iw'
vim.keymap.set("n", "gP", "<Plug>(printer_print)iw")

0 comments on commit dbbd3ec

Please sign in to comment.