Kakoune: How to change default keybindings

Created on 13 Jul 2019  Â·  23Comments  Â·  Source: mawww/kakoune

I want to replace

h: select the character on the left of selection end
j: select the character below the selection end
k: select the character above the selection end
l: select the character on the right of selection end

With arrows.

d: yank and delete current selection
With

How can I do that?

All 23 comments

Arrows should already work, including with the Shift and Alt modifiers.

For your other example, you want something like:

map global normal <c-x> d

...but be aware that Kakoune's "yank" does not store the yanked text on the system clipboard, but only in its own internal clipboard (that is designed to handle multiple selections). For system clipboard integration see the wiki.

Sorry, I am new to Kakoune. What did you mean by "Shift and Alt modifiers". Can you please elaborate a little bit.

I mean pressing → moves the cursor right by one character, and pressing Shift+→ extends the selection rightwards by one character. It turns out I mis-remembered about Alt—Alt+l jumps to the end of the line (like End), but Alt+→ doesn't do anything (I guess since End does the same thing and is easier to press).

Thanks. Now I understand.

Please help me out a bit. I am trying to use ctrl+a to select all.

I tried:

map global normal <c-a> %

and also

map global normal <c-a> <s-5>

not working. what can I do?

It's the first way you did it (there's no "shift" modifier in Kakoune), but you have to escape the % because it's used for expansions (:doc expansions).

You can use either:

map global normal <c-a> '%'

or

map global normal <c-a> \%

to prevent Kakoune from trying to expand %.

Thank you very much.

One more question please. The following works:

map global normal y '<a-|> xsel --input --clipboard <ret>'

But the following does not:

map global normal <c-c> '<a-|> xsel --input --clipboard <ret>'

Is there any reason for that?

I found this. It looks like <c-c> can't be mapped :/.

Thank you very much.

I am trying to unbind few keys in normal mode. However, the following is apparently not working.

unmap global normal <a-d>
unmap global normal j
unmap global normal k
unmap global normal l
unmap global normal H
unmap global normal J
unmap global normal K
unmap global normal L
unmap global normal <a-h>
unmap global normal <a-l>

Is there any reason for that?

If you use map to layer some other behaviour on top of the defaults, you can use unmap to remove that behaviour and return to the defaults. You can't unmap the defaults, they're the defaults.

You could concievably map those keys to the empty string, though, or some do-nothing sequence like :<esc>.

Thank you very much.

So can I do things like:
map global normal l ~

I mean 'l' for lower case.

Kakoune's ~ command makes things upper-case, so it would seem odd to map l to that... but sure, you could do that.

I have keybindings like the following.

map global normal ( <a-i>(
map global normal [ <a-i>[
map global normal { <a-i>{

So, if I press ( in normal mode, it select the enclosing parenthesis....

How can I make it so that [ in normal mode will enclose ( or { or [ or < or " or ' or `

One more thing please. The following is not working

map global normal <c-l> '`'

Is it just me or <c-l> is not actually bindable.

I'm not sure what you mean by "enclose ( or { or [ or < or " or ' or `". If you had all those symbols in a row and pressed [, what would you expect to happen?

As for <c-l>, I can certainly bind it here, but if you bind it to backtick then it won't do anything most of the time - it squashes the selection to lowercase, so on already-lowercase text, or numbers or symbols, nothing happens.

@Screwtapello thank you very much.

What I meant is: when we press <a-i> there are options like:

b, (, )

    select the enclosing parenthesis
B, {, }

    select the enclosing {} block
r, [, ]

    select the enclosing [] block
a, <, >

    select the enclosing <> block
Q, "

    select the enclosing double quoted string
q, '

    select the enclosing single quoted string
g, `

    select the enclosing grave quoted string

So, ('s enclosing part is definitely )
{'s enclosing part is definitely }
['s enclosing part is definitely ]
<'s enclosing part is definitely >
"'s enclosing part is definitely "
''s enclosing part is definitely '

So, I do not what to manually select the enclosing character. I always want to press [ so that it selects till the enclosing part.

In algorithm, what I am looking for is:

if current selected char is ( select till )
if current selected char is { select till }
if current selected char is [ select till ]
....

That way it will not occupy all those chars in my normal mode (and I also will not have to frequently go to the Object mode):

map global normal ( <a-i>(
map global normal [ <a-i>[
map global normal { <a-i>{
....

I am open to write some code as well, if you tell me what to do. However, I think if we can use multiple commands then the problem can be solved without writing any code.

Please let me explain. There are most probably commands associated with keys.

Suppose,

the command associated with the key <a-i>( is select-the-enclosing-parenthesis
the command associated with the key <a-i>( is select-the-enclosing-block-a
the command associated with the key <a-i>( is select-the-enclosing-block-b
.....

Then we can do something like:

define-command select-till-enclosing-part select-the-enclosing-parenthesis;select-the-enclosing-block-a;select-the-enclosing-block-b
map global user [ ': select-till-enclosing-part<ret>'

I hope this will work. Because, one char at a time can not be multiple things. So, it will either be ( or { or [.... So, though we have chained multiple commands only the appropriate one is supposed to work.

There are most probably commands associated with keys.

No, there aren't. The name of the "select within parenthesis" command is <a-i>( (or possibly <a-i>) or <a-i>b). Even in the C++ code there's no specific name for that action, it's just part of the general select_object() function.

That said, I think there's an easy way to do what you want:

map global normal [ ': execute-keys <a-i> %val{selection}'

That way, whenever you hit [, Kakoune will type <a-i> followed by whatever you have selected - if your cursor's on [, it'll select inside [. If your cursor's on ", it'll select inside ".

I am super greatful. Thank you very much.

@Screwtapello have you noticed something. if we use map global normal [ ': execute-keys <a-i> %val{selection}' the prompt shows like map global normal [ ': execute-keys %val{selection}'. It removes <a-i>.

this works: map global normal [ ': execute-keys <lt>a-i<gt> %val{selection}'. However, it would be great if I did not have to press <ret>.

Ah, right, sorry. I ran execute-keys <a-i> %val{selection} interactively, but I didn't actually try it in a mapping and forgot the extra changes needed. Replacing < with <lt> is one of them, the other is adding <ret> at the end:

map global normal [ ': execute-keys <lt>a-i<gt> %val{selection} <ret>'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hwmack picture hwmack  Â·  4Comments

abitofalchemy picture abitofalchemy  Â·  3Comments

valerdi picture valerdi  Â·  4Comments

radare picture radare  Â·  3Comments

dpc picture dpc  Â·  4Comments