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 · 17 comments
Closed

How to select lines up? #1285

srghma opened this issue Mar 18, 2017 · 17 comments

Comments

@srghma
Copy link

@srghma 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

This comment has been minimized.

Copy link
Contributor

@lenormf 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 Mar 19, 2017
@srghma

This comment has been minimized.

Copy link
Author

@srghma 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

This comment has been minimized.

Copy link
Contributor

@alexherbo2 alexherbo2 commented Mar 20, 2017

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

This comment has been minimized.

Copy link
Author

@srghma srghma commented Mar 20, 2017

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

@srghma srghma closed this Mar 20, 2017
@srghma

This comment has been minimized.

Copy link
Author

@srghma 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

This comment has been minimized.

Copy link
Contributor

@alexherbo2 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

This comment has been minimized.

Copy link
Author

@srghma srghma commented Mar 20, 2017

@alexherbo2 , ahahahhh, you genius)) ❤️

@srghma

This comment has been minimized.

Copy link
Author

@srghma srghma commented Mar 20, 2017

@alexherbo2 , I think your answers must be in wiki

@alexherbo2

This comment has been minimized.

Copy link
Contributor

@alexherbo2 alexherbo2 commented Mar 20, 2017

Yep can you add them? :p

@srghma

This comment has been minimized.

Copy link
Author

@srghma srghma commented Mar 20, 2017

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

@srghma

This comment has been minimized.

Copy link
Author

@srghma 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

This comment has been minimized.

Copy link
Contributor

@alexherbo2 alexherbo2 commented Mar 30, 2017

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

This comment has been minimized.

Copy link
Author

@srghma 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

This comment has been minimized.

Copy link
Contributor

@alexherbo2 alexherbo2 commented Mar 31, 2017

I updated the command

@srghma

This comment has been minimized.

Copy link
Author

@srghma srghma commented Mar 31, 2017

Wow, awesome, I have got it, its beautiful

@srghma

This comment has been minimized.

Copy link
Author

@srghma 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

This comment has been minimized.

Copy link
Contributor

@alexherbo2 alexherbo2 commented Mar 31, 2017

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>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.