-
Notifications
You must be signed in to change notification settings - Fork 13
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
Mapping/command to move to beginning/end of blocks, parent blocks? #1
Comments
I wanted to add def hello(obj):
if True:
print('Hello, %s' % obj) On all 3 lines there, you are inside one of those blocks. It becomes unclear to me about how the plugin should decide. Not to mention the 3rd line is the "end" for the There are keys that move outward to the parent |
I think the issue becomes clearer if we decide whether the plugin is focussed on blocks defined by indents or code blocks defined by indents. The latter is a semantic overlay on the former. I think the fact that your plugin is focussed on the semantically-richer "code block" concept is exactly what makes it really nice, distinguishing it from others out there. I am the author of indentwise, which focusses on blocks defined by indents, with no attempt at semantic interpretation. Your plugin instantly appealed to me more than my own for Python programming precisely because it goes one step further and sees the world in terms of semantically important code blocks rather than just indented blocks. So, given that, in the example you list above:
Note that "move to end of block" is difficult to consistently and robustly define, at least in a way that makes movement predictable and intuitive in braceless syntaxes. In most cases, though, the "beginning of next block at higher level" usually gets you close enough for all practical purposes. |
I saw your plugin after I had left for dinner and know you have a real appreciation for the goofiness involved here, so your input is definitely appreciated. I actually had no particular focus on indent blocks vs code blocks (but obviously emphasized on the latter). I broke down and made this after I had typed Back on topic: I think what you mentioned above makes more sense to me now. I'll focus more on code blocks and shrug off the impossible scenarios that the user should already understand. Not sure when I'll get around to looking at it next since my day is pretty filled tomorrow. Do you have suggestions on what the default motion keys should be? I did want to implement |
When I first shared "indentwise" on reddit, key-mappings was a pretty involved discussion. Long story short: everyone had a perspective/opinion, most of which made sense, but there was no consensus or even a majority opinion. Basically there were as many schemes as their were programmers. [Though the schemes could be classified into two broad groups, those who preferred a mnemonic-emphasis consistent with other movement keys and those who preferred something easy to type. I fell into the first class, using for, e.g. "]-" to move to the next higher-level indent rather than, e.g. "m,"]. So given all that, I would recommend: (1) All commands are bound to PLUG mappings. (1) and (2) are considered standard best practices for modern Vim plugin development. With respect to (1), best practices also recommend that you name your plugins with enclosing parenthesis to avoid needing to timeout in the case of names that are a subsets of another. E.g. (from indentwise):
So you might have, e.g.
Bbecause I would like to retain the "m" modifiers for movements that have some sort of "method/function" semantics, my personal preference for the above movements might be something more neutral "[j" and "]k" rather than "[m" and "]m". But you know what would be deliciously ironic? If "Braceless" actually used braces as the primary prefix keys!! E.g., "{m" and "}m" or "{j" or "}k". Ha! Either way, though, using the PLUG architecture gives you the flexibility to indulge in whatever works for you while allowing everyone else's idiosyncracies to be supported easily and without hassle as well. EDIT: remove angle-brackets from PLUG so that they text actually shows up! |
I'm a little slow to reply to this one because it warrants some thought. I think I like
I definitely was thinking about this when I started, but didn't want to add a delay to paragraph movement since it's still kind of useful in Python 😆 |
Due to the But there is a case to be made for If you do go with the
Maybe find a suitable replacement for "z" for Braceless? Maybe ">": "[>", "]>", ">j", ">k"? |
I forgot to reply to this earlier, sorry.
I was actually thinking this, but I guess I typed it out the wrong way 😓
I thought about |
There's also But the "key" (ha ha) point you make is this:
Yep! Default to what you feel comfortable with + option to suppress or not enable default mappings + everything bound to |
@jeetsukumaran Sorry for not updating sooner. This took a while to get right. And by "right", I mean "as close to making sense as possible". I went with What I did was made it so that movement happened by block segments. Here's an image that shows what are considered block segments: It somewhat matches the fold movement keys. I'm going to sit on this for a day or two before merging it into master so I can try using these keys in real work. You should try out the block-motions branch and see what you think. |
(1) First, I think that every motion should add the current position to the jumplist so that (2) I think that For e.g., consider the following code fragment::
Then, if the cursor is on line 10, I can see wanting go up to line 5 or 4, but not so much the end of the previous block. BUT, I confess that this might be just me and if you find it useful by all means you should keep it. (3) Similarly, I am thrown off by the cursor going to the end of the line: that typically is not a place I find most convenient to begin working on a like (my eyes have to scan "backward" to the place I want to then go, and it seems more natural to go to the beginning of the line and scan forward). But again, this might be just me. (4) For reference, here are the
But what is missing these movements produced by indentwise is the awareness of code blocks rather than indent-based segments.
Some of the above can be achieved through multiple smart invocations of the dumb indentwise commands, e.g. |
Is there a vim function for setting updating the jumps or is it a matter of `normal! m`` before the movement? Yeah, after some real use, the cursor positions after the move are a little too weird for me. I was modeling after the fold movements so I could have some concept to latch on to while working on this because it was getting a little confusing. And, now that you've mentioned jumps, I just noticed that
I checked and rechecked and there doesn't seem to be anything already using these keys. Can you confirm that? I've only been using Vim seriously for a little over a year now, and very poorly for about a decade. So, I'm far from an expert and might be missing something. The reason that these don't land on the line that starts the block is because of the way the lines are being searched. In a case like this: if True: # Go here
if True:
if True:
pass # Start here
pass
pass # Go here It was not awesome jumping one line at a time with two keys when I'd rather keep these movements agnostic and not Python specific since I want to extend this plugin into CoffeeScript one day. So, no go on having these being contextual to a block head (re: your comment about def and class). I am going to be adding Python specifics though, but most likely reimplementations of what's in python-mode. In any case, I'm going to be merging what I have now into master to fix a regression in indentation (updated movement code is needed to fix it), but it's going to be disabled by default. |
The key to having the current position recorded in the jumplist is to use movements that record the current position in the jumplist. Tautalogical, I know, but what I mean is this ... If you decide you want to move 3 lines up to line 35, you could either do
or
Conversely, you use |
Thanks for the pointers about the jumps. I've been using it everywhere it makes sense. Observations of my own: You can move the cursor all you want, but to record the jump correctly, you have to restore the original position before The segment movements have been more difficult than I expected. I implemented |
Oops, I forgot I was optimistic and had the commit message close this. |
Thanks! Will give it a spin. |
So, I lied about taking a break from this. I added |
Is there such? If not, would it be possible to request it?
Nice movements would be:
E.g.,
Given:
(1) If the cursor is between line 4 (inclusive) and 5 (exclusive), then would move to the line just before [5].
(2) If the cursor is between line 4 (inclusive) and 5 (exclusive), then would move to [4]
(3) If the cursor is between line 4 (inclusive) and 5 (exclusive), then would move to [3]
(4) If the cursor is between line 4 (inclusive) and 5 (exclusive), then would move to [7]
The text was updated successfully, but these errors were encountered: