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

Need API to for lines visible in viewport #2771

Closed
20 tasks done
ghost opened this issue Feb 7, 2016 · 17 comments
Closed
20 tasks done

Need API to for lines visible in viewport #2771

ghost opened this issue Feb 7, 2016 · 17 comments
Assignees
Labels
api feature-request Request for new features or functionality VIM VIM issue
Milestone

Comments

@ghost
Copy link

ghost commented Feb 7, 2016

Cursor Commands

  • Move to view line start g0
  • Select till line start vg0
  • Move to view line first non white space character g^
  • Select till line first non white space character vg^
  • Move to view line end g$
  • Select till view line end vg$
  • Move to view line last non white space character g_
  • Select till view line last non white space character vg_
  • Move to view line middle gm
  • Select till view line middle vgm
  • Move up N view lines gk
  • Select till N view lines up vgk
  • Move down N view lines gj
  • Select till N view lines down vgj
  • Move to first non white space character of Nth line from the top of the view H
  • Select till first non white space character of Nth line from the top of the view vH
  • Move to first non white space character of center line of the view M
  • Select till first non white space character of center line of the view vM
  • Move to first non white space character of Nth line from the bottom of the view L
  • Select till first non white space character of Nth line from the bottom of the view vL

vi has H, M, and L keybindings that move the cursor based what lines are currently on screen. It's not possible for a Vim-like extension to implement these right now, because the the vscode extension APIs don't expose this information.

@johnfn
Copy link
Contributor

johnfn commented Jun 18, 2016

Yeah. We need this for zt and zb as well. As far as I can tell there is not even a way to hack it.

@alexdima alexdima added VIM VIM issue feature-request Request for new features or functionality labels Jul 5, 2016
@alexdima alexdima added this to the Backlog milestone Jul 5, 2016
@johnfn johnfn mentioned this issue Jul 9, 2016
89 tasks
@egamma egamma mentioned this issue Jul 9, 2016
4 tasks
@sandy081 sandy081 self-assigned this Jul 11, 2016
@sandy081
Copy link
Member

#9143 - will provides a command to move the cursor. We will see if that command is suffice the needs of this issue and take the next step

@sandy081
Copy link
Member

@johnfn FYI Listed the cursor move commands in description which are supported now.

@johnfn
Copy link
Contributor

johnfn commented Jul 19, 2016

@sandy081 This is step in the right direction, thank you!

Unfortunately, though, we can't do everything just by moving the cursor - we need to know the position where e.g. the middle of the screen is to have full support of the Vim commands. (We could hack it by moving the cursor, recording location, then moving back, but that seems like quite the hack.)

@sandy081
Copy link
Member

@johnfn Can you please point me to the use cases or Vim commands where you need the middle of the screen positions.

@johnfn
Copy link
Contributor

johnfn commented Jul 19, 2016

@sandy081 Sure, any operator combination with M will do the trick. e.g. dM will delete characters until the middle of the screen. vM will select until the middle of the screen. (The same is true of the top and bottom lines with H and L, respectively).

@sandy081
Copy link
Member

@johnfn Thanks.

The new command 'cursorMove' is mainly to support all cursor specific motions. Once I am done with this, we can definitely come up with a solution for various other motions / operations. For more information about this command refer to #9143. It would be great, if you can let me know if there is anything missing support for cursor specific motions.

@sandy081
Copy link
Member

I am also going through your Vim Extension Roadmap for what is missing and needing API support.

@johnfn
Copy link
Contributor

johnfn commented Jul 19, 2016

@sandy081 Just to make your life harder - there really isn't much of a "cursor-specific" movement in Vim. All cursor commands can be paired with operators in the same way M could be to transform them into deletions or selections, so the position is pretty much a global necessity. If just moving the cursor is easier, that's fine for now - it's certainly better than nothing.

You can feel free to go through the list, but I already culled it down to #8997; I don't think there are any more than that. You can feel free to try to prove my wrong. 😉

@johnfn
Copy link
Contributor

johnfn commented Jul 19, 2016

(Also, keep in mind that we don't just need first and last line - we actually need every screen line, since a command like 10H will bring you to the tenth line from the top. Course, given the position of the top line, retrieving the 10th line below that position won't be too hard.

@sandy081
Copy link
Member

@johnfn I see that in Left-right and Up-down motions section of your road map, following commands are not implemented

  • g0
  • g^
  • g$
  • gm
  • gj
  • gk

I think with this cursorMove command these can be implemented now with or without selection

@sandy081
Copy link
Member

Basic idea is to come up with a command to support use cases dependent on Screen / View positions just like the one which I mentioned above.

@johnfn
Copy link
Contributor

johnfn commented Jul 19, 2016

@sandy081

Again, all motion commands can be combined with operators. So while g0 works (yay!), vg0 (select to the position of g0) and dg0 (delete to the position of g0) are missing.

The same is true of the other motions you listed.

@sandy081
Copy link
Member

sandy081 commented Jul 19, 2016

@johnfn

I think, you can implement vg0 and dg0 using this new cursorMove command

  • g0 => cursroMove({to: 'lineStart'})
  • vg0 => cursroMove({to: 'lineStart', inSelectionMode: true})
  • dg0 => cursroMove({to: 'lineStart', inSelectionMode: true}); /*Select the text. Now write logic on doc text editor to delete the selected text */

All other motions follow the same

I will try to provide examples.

@rebornix
Copy link
Member

@sandy081 sorry for comming to this issue too late. I saw you already implemented new APIs for moving Screen positions and they look good to me.

The reason that @johnfn asks for position information instead of moving cursors for us is that we are handling cursors ourselves in VSCodeVim. While in other Vim extensions, they actually keep hands off the cursor, they delegate the cursor handling to VS Code.

Moving cursor is more generic and let me try the inSelectionMode you mentioned. Will give you update about newly added API real quick.

@sandy081 sandy081 modified the milestones: July 2016, Backlog Jul 20, 2016
@sandy081
Copy link
Member

Closing this as the new command meets all necessary cursor move requirements

@sandy081
Copy link
Member

sandy081 commented Jul 25, 2016

@rebornix Please note the small change done to the API for consistency and clean

  • Renamed argument parameter amount to value.

Please adopt to these changes

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api feature-request Request for new features or functionality VIM VIM issue
Projects
None yet
Development

No branches or pull requests

5 participants