Skip to content

Need API to for lines visible in viewport #2771

Closed

Description

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.

Activity

  1. johnfn commented on Jun 18, 2016

    @johnfn
    Contributor

    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.

  2. added
    VIM
    feature-request
    on Jul 5, 2016
  3. sandy081 commented on Jul 12, 2016

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

  4. sandy081 commented on Jul 19, 2016

    @sandy081
    Member

    Grant Mathews (@johnfn) FYI Listed the cursor move commands in description which are supported now.

  5. johnfn commented on Jul 19, 2016

    @johnfn
    Contributor

    Sandeep Somavarapu (@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.)

  6. sandy081 commented on Jul 19, 2016

    @sandy081
    Member

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

  7. johnfn commented on Jul 19, 2016

    @johnfn
    Contributor

    Sandeep Somavarapu (@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).

  8. sandy081 commented on Jul 19, 2016

    @sandy081
    Member

    Grant Mathews (@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.

  9. sandy081 commented on Jul 19, 2016

    @sandy081
    Member

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

  10. johnfn commented on Jul 19, 2016

    @johnfn
    Contributor

    Sandeep Somavarapu (@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. 😉

  11. johnfn commented on Jul 19, 2016

    @johnfn
    Contributor

    (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.

  12. sandy081 commented on Jul 19, 2016

    @sandy081
    Member

    Grant Mathews (@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

  13. sandy081 commented on Jul 19, 2016

    @sandy081
    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.

  14. johnfn commented on Jul 19, 2016

    @johnfn
    Contributor

    Sandeep Somavarapu (@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.

  15. sandy081 commented on Jul 19, 2016

    @sandy081
    Member

    Grant Mathews (@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.

  16. rebornix commented on Jul 19, 2016

    @rebornix
    Contributor

    Sandeep Somavarapu (@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 Grant Mathews (@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.

  17. sandy081 commented on Jul 22, 2016

    @sandy081
    Member

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

  18. sandy081 commented on Jul 25, 2016

    @sandy081
    Member

    Peng Lyu (@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

  19. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

VIMapifeature-request

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions