diff --git a/.config/kak/autoload/clipboard.kak b/.config/kak/autoload/clipboard.kak index 8aa7eadc..b8347c2e 100644 --- a/.config/kak/autoload/clipboard.kak +++ b/.config/kak/autoload/clipboard.kak @@ -3,6 +3,17 @@ declare-option -docstring %{ Command for copying to system clipboard. } str clipboard_copy_cmd 'wl-copy' +declare-option str clipboard_strip_cmd %{ + perl -ne ' + BEGIN { $prefix = undef } + if (!defined $prefix) { + ($prefix) = /^([ \t]*)/; + } + s/^\Q$prefix\E//; + print; + ' | wl-copy +} + declare-option int clip_selcount 0 define-command -hidden clip-trim %{ @@ -12,6 +23,13 @@ define-command -hidden clip-trim %{ } } +define-command clip-copy-strip %{ + evaluate-commands -save-regs '|' %{ + set-register | %opt{clipboard_strip_cmd} + execute-keys '' + } +} + define-command -docstring %{ clip-copy [-split]: copy selections to system clipboard Set the clipboard_copy_cmd option to change the command @@ -52,6 +70,7 @@ define-command -docstring %{ map -docstring "yank the selections into the clipboard" global user y ": clipboard-copy" map -docstring "yank the split selections into the clipboard" global user Y ": clipboard-copy -split" +map -docstring "yank main selection, strip leading whitespace" global user ': clip-copy-strip' map -docstring "paste the clipboard" global user p " wl-paste -n" map -docstring "paste the clipboard before" global user P "! wl-paste -n"