Formatting questions

  1. Is there a shiftround equivalent?
  2. How do I remove the space between a comment and the line? e.g.

After I use :comment-line I get:

# line

But what I want is:

  1. How do I disable the auto-commenting for new lines? If I’m on a commented line and I press o, then it creates a new line where I’m typing a comment. I would like to disable this behavior so I’m not typing a comment.

  2. This isn’t really a formatting question, but how do I insert 5 identical strings? e.g. in Vim I could simply do 5istring<esc> and it would insert stringstringstringstringstring.

For number 4, I don’t know if there’s a way to do it with a count like in vim, but the command exec istring<esc>.... will have the same effect, where string is the string to be duplicated. If you want more or less strings, add or remove periods to or from the end so that there is exactly one less period than the desired number of strings. (e.g. for two strings have one period at the end, for ten strings have nine periods, etc.)

1 Like

This is completely picking a nit and tangential to your ask but … on #2 … why… why?

:cry: :sob: Your # needs its personal bubble!

def trim-excess-padding %{ try %{
    exec -draft "<a-x>s ^[ ]{%opt{indentwidth}}+\K +<ret>d"
map global normal <gt> '>: trim-excess-padding<ret>'
map global normal <lt> '<: trim-excess-padding<ret>'

should do what you want although you could implement it in other ways using the same “trick” of %opt{indentwidth} as a the quantifier.

For #3 that behavior also irritates me. I’m too lazy to do it for every file type, but my solution to the problem was to overwrite the default indentation hook with one that cheked to see if the previous line contained nothing but the comment line symbol and if it did go back and delete that line. So basically you could double tap enter to end the comment block, I found this to be the best of both worlds.

In theory you might be able to do something like

hook global WinSetOption (filetypes|you|want|this|applied|to) %{
    hook window InsertChar \n %{
        # logic here is kinda jank because it's after normal indentation hook has triggered.
        try %{
            # delete previous line if it's only white space + comment
            exec -draft "k<a-x>s ^\h*%opt{comment_line}\h*$<ret>d"
            # delete the bottom line but keep the indentation
            exec -draft 'giGld'

to cover everything.

For #4 I was going to say you could do istring5. but for some reason that doesn’t work…

For #4, that doesn’t work in Kakoune I think because of the multiple-cursor thing. However, you can do this:


I realise this was probably a joke, but I personally put a space between a comment marker and the the text for actual documentation comments, and put no space for temporarily commenting-out code. Having two different patterns for commented code and for commented documentation also helps me automate the uncommenting later (with a regex like ^#[^ ]).

@Screwtapello interesting, do you have a different comment out command for code commenting that puts the comment char on the left of the code at all indent levels?

Cool idea, and it would look visually different too – I withdraw some of my horror.

Thanks @prion, I’ll give that a try!

@Screwtapello, I’m glad I’m not the only one that does this with comments! And 5o<backspace> actually works really well, I didn’t realize that 5 works with o because it doesn’t work with i. Thanks!

@robertmeta, it is indeed for distinguishing between documentation vs. commented out code. I’ve met one person go to extra lengths to distinguish documentation comments:

# // this is documentation

For 4. , i personally use:

# multiple insert
define-command -params 1 urk %{
    execute-keys -with-hooks \;i.<esc>hd %arg{1} P %arg{1} Hs.<ret><a-space>c
map global user i %{:urk %val{count}<ret>} -docstring "countable insert"

However this does not work well with multiple cursor.

1 Like