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

On insert mode, the cursor will be before the character #27

Closed
ioRekz opened this issue Feb 14, 2013 · 6 comments
Closed

On insert mode, the cursor will be before the character #27

ioRekz opened this issue Feb 14, 2013 · 6 comments

Comments

@ioRekz
Copy link

ioRekz commented Feb 14, 2013

I only use a subset of vim navigation functionality so I'm really often in "insert" mode.

Then when I want to easy motion to a character, the cursor will be just before the character I want to, and in my case, I almost always want to go after this character.

Any idea how I can do it ?

@tednaleid
Copy link
Owner

hmm, so I'm guessing you're normally typing something like the last letter in a word, and you want to keep typing after that?

I could implement something like an offset parameter for the keystrokes so that people who use it like you do could modify their keybinding definition with an offset = 1 so that the cursor actually appears one character past where it "naturally" would appear.

The other alternative, if you're normally just wanting to type at the end of a line is for me to implement issue #21, which I've now found some use for myself. So if it's normally just an EOL thing where you want to start typing, doing that would give you what you want.

Are there others that are similar to ioRekz who would find it useful for the cursor to appear one more character to the right of where it does now?

@edwardoriordan
Copy link

Are there others that are similar to ioRekz who would find it useful for the cursor to appear one more character to the right of where it does now?

I also only use a handful of vim navigation and am almost always in insert mode. Having the option to set the cursor to appear after the word would be very useful.

@tednaleid tednaleid mentioned this issue Mar 15, 2013
@benjohnson
Copy link

Came here looking for a solution to exactly this issue. I'm slowly retraining my brain to seek the character next to the one I want, but if the offset was available I'd use it. I almost always end up with the cursor before the character I'm aiming at instead of after.

@OwenAR
Copy link

OwenAR commented Feb 1, 2014

Welp, I tried adding a line two lines to the end of this function definition in easy_motion.py:

# MONKEY1
    def jump_to_winning_selection(self):
        if self.winning_selection is not None:
            self.active_view.run_command("jump_to_winning_selection", {"begin": self.winning_selection.begin(), "end":self.winning_selection.end()})
        if SELECT_TEXT == False:                                                            # line I added
            self.active_view.run_command("move", {"by": "characters", "forward": True})     # line I added

Which fixes all the cases where you end up with the caret one character before the spot you want it to be...

...except of course it breaks the one case where it already had the desired behavior: jumping to a "Beginning Of Line".

I'm just flailing at this wildly with my minimal programming experience in general and only the barest clue of how to work the Sublime API from a couple minutes of skimming the documentation...

But I imagine there should be a way to restrict the context in which that "move" command fires off so that it only runs when the caret isn't already (?=^)?

I managed to slop together this keybinding:

{
    "keys": ["alt+,"]
,   "command": "move", "args": {"by": "characters", "forward": true}
,   "context": [{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "^$", "match_all": true }]
},

But I can't figure out: how can you translate the functionality of the "context" restriction from the keybinding JSON to the Python API?

(Incidentally, I tried this first but bluh promblems:

# MONKEY2
    def target_regexp(self, character):
        re_flags = self.determine_re_flags(character)
        if (REGEX_ESCAPE_CHARS.find(character) >= 0):
            return re_flags + '\\' + character
        elif character == "enter":
            return re_flags + "(?=^).|.(?=$)"               # <-- ORIGINAL
            # return re_flags + "(?=^)|(?=$)"               # tried this, but of course it makes a mess
                                                            # cuz the newlines are replaced with the 
                                                            # single-width placeholder characters.
                                                            # Can't think of a clever, simple work-around...
        else:
            return re_flags + character                     # <-- ORIGINAL
            # return re_flags + "(?<=" + character + ")."   # ends up also putting the placeholder character
                                                            # a spot to the right of where we want it...

)

@tednaleid
Copy link
Owner

I believe the latest master branch fixes this so that when you're in insert mode it'll put the cursor on the right of the chosen character instead of the left. Vim command mode should work like it does now.

@pruppert
Copy link

pruppert commented Jan 7, 2015

How do I get into insert mode? I am also wanting the cursor to go after the character I chose. FYI, I am on ST3.

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

No branches or pull requests

6 participants