Skip to content

Commit 779dbe1

Browse files
committed
feat(nvim): amp keymaps
1 parent 8b6a41b commit 779dbe1

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

nvim/lua/config/keymaps.lua

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,57 @@ map("n", "<leader><tab><tab>", "<cmd>tabnew<cr>", { desc = "New Tab" })
221221
map("n", "<leader><tab>]", "<cmd>tabnext<cr>", { desc = "Next Tab" })
222222
map("n", "<leader><tab>d", "<cmd>tabclose<cr>", { desc = "Close Tab" })
223223
map("n", "<leader><tab>[", "<cmd>tabprevious<cr>", { desc = "Previous Tab" })
224+
225+
-- amp
226+
map("n", "<leader>as", function()
227+
vim.ui.input({ prompt = "Amp: " }, function(input)
228+
if input and input ~= "" then
229+
require("amp.message").send_message(input)
230+
end
231+
end)
232+
end, { desc = "Send Message" })
233+
map("n", "<leader>ab", function()
234+
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
235+
require("amp.message").send_message(table.concat(lines, "\n"))
236+
end, { desc = "Send Buffer" })
237+
map("v", "<leader>as", function()
238+
local start_line = vim.fn.line("v")
239+
local end_line = vim.fn.line(".")
240+
if start_line > end_line then
241+
start_line, end_line = end_line, start_line
242+
end
243+
local lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
244+
require("amp.message").send_message(table.concat(lines, "\n"))
245+
end, { desc = "Send Selection" })
246+
map("v", "<leader>ap", function()
247+
local start_line = vim.fn.line("v")
248+
local end_line = vim.fn.line(".")
249+
if start_line > end_line then
250+
start_line, end_line = end_line, start_line
251+
end
252+
local lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
253+
require("amp.message").send_to_prompt(table.concat(lines, "\n"))
254+
end, { desc = "Add Selection to Prompt" })
255+
map({ "n", "v" }, "<leader>ar", function()
256+
local bufname = vim.api.nvim_buf_get_name(0)
257+
if bufname == "" then
258+
vim.notify("Current buffer has no filename", vim.log.levels.WARN)
259+
return
260+
end
261+
local relative_path = vim.fn.fnamemodify(bufname, ":.")
262+
local ref = "@" .. relative_path
263+
local mode = vim.fn.mode()
264+
if mode == "v" or mode == "V" then
265+
local start_line = vim.fn.line("v")
266+
local end_line = vim.fn.line(".")
267+
if start_line > end_line then
268+
start_line, end_line = end_line, start_line
269+
end
270+
if start_line ~= end_line then
271+
ref = ref .. "#L" .. start_line .. "-" .. end_line
272+
else
273+
ref = ref .. "#L" .. start_line
274+
end
275+
end
276+
require("amp.message").send_to_prompt(ref)
277+
end, { desc = "Add File Ref to Prompt" })

nvim/lua/plugins.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,7 @@ return {
17851785
{
17861786
mode = { "n", "v" },
17871787
{ "<leader><tab>", group = "tabs" },
1788+
{ "<leader>a", group = "amp" },
17881789
{ "<leader>c", group = "code" },
17891790
{ "<leader>f", group = "file/find" },
17901791
{ "<leader>g", group = "git" },

0 commit comments

Comments
 (0)