Kakoune: Range (count) with insert

Created on 3 Jan 2017  路  9Comments  路  Source: mawww/kakoune

Hi,

Thank you for great editor!

This is a feature request to have counts work with insert mode.

In vim counts work with insert mode in a following way:
3i= will produce === which is convenient for markdown headers.
{3ik:"v", i} will produce {k:"v", k:"v", k:"v"} which is an easy way to initiate a set.

I could not find similar functionality in kakoune so far.

Most helpful comment

That's such a nice hack @occivink ! I poked around a bit with it and made it a keybinding:

def -allow-override -params 1 urk %{
    exec -no-hooks \;i.<esc>hyd %arg{1} P %arg{1} Hs.<ret><a-space>c
}
map global user i %{:urk %val{count}<ret>}

All 9 comments

Hello,

I have thought of this feature a few times during the development of Kakoune, but it was not implemented because it did not seem useful enough. Its pretty easy to repeat the insertion with ., or copy paste. Another reason was to keep the count parameter for an eventual other use, like inserting only for a given selection.

Interestingly, pressing c with adjacent cursors gives you multiple overlapping selections (is that a bug?) so you can kinda use that to do what you propose:

10:exec ;y%val{count}p%val{count}Ls.<ret><a-space>c gives you 10 cursors.

My quoting-fu is not good enough to turn that into a usable binding though.

That's such a nice hack @occivink ! I poked around a bit with it and made it a keybinding:

def -allow-override -params 1 urk %{
    exec -no-hooks \;i.<esc>hyd %arg{1} P %arg{1} Hs.<ret><a-space>c
}
map global user i %{:urk %val{count}<ret>}

@occivink Overlapping cursors are expected to work in insert mode, the main use case is c. We tend to merge the overlapping ones in normal mode though.

I ironed out some bugs (now works at end of line and undo history don't show dummy characters) and put it in one single file:
https://github.com/danr/dotfiles/blob/master/config/kak/same-point-insert.kak

I think count i should work the same way count o works at the moment, but instead of making new cursors on each line, they suppose to appear adjacent on the same line. Something similar to:

3o<esc><a-J>i

Revised snippet, courtesy of @danr

define-command -params 1 urk %{
    execute-keys -with-hooks \;i.<esc>hd %arg{1} Ph %arg{1} HLs.<ret>c
}
map global user i %{:urk %val{count}<ret>}

Here's another version:

map global user i ': exec %val{count}o<lt>backspace><ret>'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

akkartik picture akkartik  路  3Comments

a12l picture a12l  路  3Comments

hwmack picture hwmack  路  4Comments

alexherbo2 picture alexherbo2  路  4Comments

MasterOfTheTiger picture MasterOfTheTiger  路  4Comments