-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): add printer plugin with gp keymap
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |