Comment line(s) and paste uncommented

It’s a simple trick I got used to in spacemacs, so implemented the same in kakoune:

map -docstring "comment and paste" \
 global user '#' %{: exec -save-regs '"' <lt>a-s>gixy:<lt>space>comment-line<lt>ret><lt>space><lt>a-p><lt>a-_><ret>}
2 Likes

It’s not working for me. Should it make a copy of the current line before commenting?

Do you have comment-line command? It should be built-in I suppose.
Yes it yanks a line, comments it and then pastes original line below.

Not sure why it’s not working for you, btw I use master version of kakoune.

Nevermind, I didn’t notice I was mapping it in the user mode.

I also got this one from spacemacs, it’s quite nice.
Here’s my version which also maintains the selections.

define-command copy-and-comment %{
    evaluate-commands -save-regs ^ %{
        execute-keys -draft Z:comment-line<ret><a-x>yP:comment-line<ret>z
    }
}
1 Like

With the breaking-cleanups branch it’s even simpler:

define-command copy-and-comment %{
	evaluate-commands -save-regs ^ %{
		execute-keys -draft %{ZxyP: comment-line<ret>z}
	}
}
1 Like