Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to select lines up? #1285

Closed
srghma opened this issue Mar 18, 2017 · 19 comments
Closed

How to select lines up? #1285

srghma opened this issue Mar 18, 2017 · 19 comments

Comments

@srghma
Copy link

srghma commented Mar 18, 2017

In order to select 3 lines down one shold do 3X, how to do the same in up direction?
2K<a-x>? Too much keys

@lenormf
Copy link
Contributor

lenormf commented Mar 19, 2017

That's the proper way. x doesn't have a simliar upward key because we generally don't need as often, so it didn't warrant make room on the keyboard for it. You can however bind whatever key you want to emulate this behaviour though.

@srghma srghma closed this as completed Mar 19, 2017
@srghma
Copy link
Author

srghma commented Mar 20, 2017

@lenormf, you have said that you generally dont select upward, rly? I select upward all the time, with the same frequency as downward. And who is using current behavior of x? I know it consistent with web keys, but rly, there must be better way.
Tonight I came up with how I want to select lines in kakoune: make x behave like current X - select line if none selection or select downward if present, and X - select line if none or upward.
Consider this:

  1. no selection
  2. x - select line downward, 1 line selected
  3. 2x - append 2 lines downward, 3 lines selected
  4. 2X - append 2 lines upward, 5 lines selected, cursor now atop.

@lenormf @mawww ?

@srghma srghma reopened this Mar 20, 2017
@alexherbo2
Copy link
Contributor

def -hidden -params 1 extend-line-down %{
  exec "<a-:>%arg{1}X"
}
def -hidden -params 1 extend-line-up %{
  exec "<a-:><a-;>%arg{1}K<a-x>"
}
map global normal x ":extend-line-down %val{count}<ret>"
map global normal X ":extend-line-up %val{count}<ret>"

@srghma
Copy link
Author

srghma commented Mar 20, 2017

@alexherbo2 nice, you have made my day, kudos)

@srghma srghma closed this as completed Mar 20, 2017
@srghma
Copy link
Author

srghma commented Mar 20, 2017

@alexherbo2 I have another one insane idea: made web keys discern CamelCase and underscore notation by default, so usually when you move - you distinguish CamelCase, but when you want to select the word - you select it like textobject
Actually I have this feature in my vim and I have never regreted the day when I made this

@alexherbo2
Copy link
Contributor

alexherbo2 commented Mar 20, 2017

def -hidden select-next-word %{
  exec /[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>
}
def -hidden extend-next-word %{
  exec ?[A-Z][a-z]+|[A-Z]+|[a-z]+<ret>
}
map global normal w :select-next-word<ret>
map global normal W :extend-next-word<ret>

@srghma
Copy link
Author

srghma commented Mar 20, 2017

@alexherbo2 , ahahahhh, you genius)) ❤️

@srghma
Copy link
Author

srghma commented Mar 20, 2017

@alexherbo2 , I think your answers must be in wiki

@alexherbo2
Copy link
Contributor

Yep can you add them? :p

@srghma
Copy link
Author

srghma commented Mar 20, 2017

I put it in How to
Doesnt know that I can)

@srghma
Copy link
Author

srghma commented Mar 30, 2017

@alexherbo2 , finally I have tried your scripts))
In extending line script I wanted X to select line like x if none selection or select up if selection exists. Here is result (oh, god, I love that)

def -params 1 extend-line-down %{
  exec "<a-:>%arg{1}X"
}
def -params 1 extend-line-up %{
  exec "<a-:><a-;>%arg{1}K<a-;>X<a-;><a-X>"
}

map global normal x ':extend-line-down %val{count}<ret>'
map global normal X ':extend-line-up %val{count}<ret>'

but there is error: if lines are containing only newlines - it will select up and down simultaneously, can you help me with that?

  1. And CamelCase motions.....well, it can wait

@alexherbo2
Copy link
Contributor

alexherbo2 commented Mar 30, 2017

try %{
  exec <a-K>\n<ret>
  exec <a-x><a-:><a-\;>
} catch %{
  exec <a-:><a-\;>K<a-x>
}

@srghma
Copy link
Author

srghma commented Mar 31, 2017

def -params 1 extend-line-up %{
  try %{
    exec <a-K>\n<ret>
    exec <a-x><a-:><a-\;>
  } catch %{
    exec "<a-:><a-;>%arg{1}K<a-;>X<a-;><a-X>"
  }
}

Is that what you mean? I mean like in this video, if I am on new line it will select in both directions. This snippet is working the same(

@alexherbo2
Copy link
Contributor

I updated the command

@srghma
Copy link
Author

srghma commented Mar 31, 2017

Wow, awesome, I have got it, its beautiful

@srghma
Copy link
Author

srghma commented Mar 31, 2017

def -params 1 extend-line-down %{
  exec "<a-:>%arg{1}X"
}
def -params 1 extend-line-up %{
  try %{
    exec <a-K>\n<ret>
    exec <a-x><a-:><a-\;>
  } catch %{
    exec "<a-:><a-;>%arg{1}K<a-x>"
  }
}

map global normal x ':extend-line-down %val{count}<ret>'
map global normal X ':extend-line-up %val{count}<ret>'

You have forgotten count)))

@alexherbo2
Copy link
Contributor

def -params 1 extend-line-down %{
  exec "<a-:>%arg{1}X"
}
def -params 1 extend-line-up %{
  exec "<a-:><a-;>%arg{1}K<a-;>"
  try %{
    exec -draft ';<a-K>\n<ret>'
    exec X
  }
  exec '<a-;><a-X>'
}
map global normal x ':extend-line-down %val{count}<ret>'
map global normal X ':extend-line-up %val{count}<ret>'

@ixzh
Copy link

ixzh commented Aug 26, 2020

this should be the default mapping!

@evanrelf
Copy link
Contributor

Hi there 👋

I just finished an initial version of a plugin I'm calling expand-line.kak, which rebinds x and X to drag the cursor up and down, line-by-line.

https://github.com/evanrelf/expand-line.kak

  • You can mash x a bunch of times to select lines downwards, and then hit X to retract your selection by a line if you go too far.
  • Continuing to hit X will cause the selection to go from shrinking from below to growing from above.
  • You can use numeric prefixes, e.g. 5x works.
  • Multiple selections are supported.

There may be certain edge cases I haven't discovered yet, but in my initial testing and development it's worked great. Feel free to report issues if you run into any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants