Skip to content

Commit 04ddc0a

Browse files
advpetcclaude
authored andcommitted
Fix clipboard copy keybindings for remote SSH sessions
- Add OSC 52 clipboard support to <leader>cp, <leader>cP, and <leader>cl - Ensures clipboard works over SSH without X11 forwarding - Uses pcall to safely fallback if nvim-osc52 plugin not loaded Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4766af0 commit 04ddc0a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

init.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,22 @@ vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper win
222222
vim.keymap.set('n', '<leader>cp', function()
223223
local path = vim.fn.expand '%'
224224
vim.fn.setreg('+', path)
225+
-- Also copy via OSC 52 for remote SSH sessions
226+
local ok, osc52 = pcall(require, 'osc52')
227+
if ok then
228+
osc52.copy(path)
229+
end
225230
print('Copied: ' .. path)
226231
end, { desc = '[C]opy file [P]ath (relative)' })
227232

228233
vim.keymap.set('n', '<leader>cP', function()
229234
local path = vim.fn.expand '%:p'
230235
vim.fn.setreg('+', path)
236+
-- Also copy via OSC 52 for remote SSH sessions
237+
local ok, osc52 = pcall(require, 'osc52')
238+
if ok then
239+
osc52.copy(path)
240+
end
231241
print('Copied: ' .. path)
232242
end, { desc = '[C]opy file [P]ath (absolute)' })
233243

@@ -240,6 +250,11 @@ vim.keymap.set('n', '<leader>cl', function()
240250
return
241251
end
242252
vim.fn.setreg('+', url)
253+
-- Also copy via OSC 52 for remote SSH sessions
254+
local ok, osc52 = pcall(require, 'osc52')
255+
if ok then
256+
osc52.copy(url)
257+
end
243258
vim.notify('Copied: ' .. url, vim.log.levels.INFO)
244259
end, { desc = '[C]opy GitHub [L]ink' })
245260

0 commit comments

Comments
 (0)