guns / vim-sexp

Precision Editing for S-expressions
MIT License
611 stars 33 forks source link

Element motion problems (does not work with selection=exclusive in gvim) #4

Open oskarkv opened 10 years ago

oskarkv commented 10 years ago

Maybe these things are just happening for me, because of some other plugin or settings, but...

In the following, |x| represents the cursor position, and <x> represents a visual selection.

Starting with (+ 10|0|0) and doing vae results in (+< 100>0). Starting with (+ sym|b|ol) and doing vae results in (+< symbo>l). Starting with something "a str|i|ng" and doing vae results in something< "a string>".

There are similar problems with ie motions. In summary, the element motion does not quite work for the last element in a list, or if the element is a string.

guns commented 10 years ago

Hmm, I can't reproduce those unfortunately. I am highly interested in correcting behavior like this, so I would definitely enjoy having a consistently reproducible case. Have these motions always worked like this for you?

There is an outstanding bug in vim-sexp related to registers, but this does not seem to be related.

Thanks for reporting! I hope you will be able to communicate this problem to me.

oskarkv commented 10 years ago

I have not used vim-sexp before, so there is no "always". :P

I tried removing all my plugins except for these: rainbow_parentheses vim-classpath vim-clojure-highlight vim-clojure-static vim-fireplace vim-sexp

Also, I tried it in a really simple Clojure file with just one function.

Here is my vimrc: https://gist.github.com/oskarkv/7759c917238d1c4a90d9

The result is the same as before. Tell me if there is anything else I can do.

oskarkv commented 10 years ago

I don't know why I didn't do this at first...

I deleted everything in my vimrc from line 9 and down (in the above gist). Still the same result.

guns commented 10 years ago

Ah, that simplifies things. I was just perusing your vimrc. You use Colemak! Very fascinating, how do you like this layout?

oskarkv commented 10 years ago

Hehe. Colemak is pretty nice. I switched from Qwerty because I had bad habits on there, and starting with a new layout completely seemed easier than unlearning those habits. I like Colemak a lot better than Dvorak though, because Colemak has z, x, c and v in the same positions as Qwerty, and even beyond that I think it's better.

When I did that, I also switched place between Alt Gr and Caps Lock, and put all non-letter symbols on Alt Gr+letters. So this is my home row when I hold Caps Lock: /()@#+-'~ See http://i.imgur.com/2bug7fA.png The hardest symbol to type for me is 6 now. :P

guns commented 10 years ago

So this is my home row when I hold Caps Lock: /()@#+-'~

Now that's a pretty big advantage! I'll have to try that someday. And using a new keyboard layout to unlearn bad habits is an interesting strategy.

I hope you don't mind, but I'd like to debug this from scratch. It looks like we have pretty different environments, so I put up a minimal repo for testing and added you as a collaborator:

https://github.com/guns/vim-sexp-issue-4-tmprepo/

Please clone this and run

vim -N -u vimrc -U NONE example.clj

from the repo root, then try the element motions again. They work as intended on my machine. Thanks!

oskarkv commented 10 years ago

This line is making all the difference: source $VIMRUNTIME/mswin.vim With it, none of the versions work. Without it both works. Here mswin.vim is, if you don't have it: https://gist.github.com/oskarkv/ee1ff47184979a828755

oskarkv commented 10 years ago

Actually, it's the behave mswin, but it was in mswin.vim too. With it, the cursor is narrow and in between the letters in visual mode, and it does not reach behind the last letter.

guns commented 10 years ago

I was hoping it wasn't mswin.vim. I don't have access to a Windows machine (or even a Windows VM), so I may have to rely on you for testing. Hopefully the reason will be obvious.

Thanks for narrowing it down!

oskarkv commented 10 years ago

Tried :behave mswin?

:be[have] {model}   Set behavior for mouse and selection.  Valid
            arguments are:
               mswin    MS-Windows behavior
               xterm    Xterm behavior

            Using ":behave" changes these options:
            option      mswin           xterm   ~
            'selectmode'    "mouse,key"     ""
            'mousemodel'    "popup"         "extend"
            'keymodel'  "startsel,stopsel"  ""
            'selection' "exclusive"     "inclusive"

That incluse/exclusive stuff sounds like it could be it.

oskarkv commented 10 years ago

Yes, that was it.

guns commented 10 years ago

I just tried it, but it doesn't seem to make any difference; I'll take a look at the vim source

guns commented 10 years ago

Okay, I was finally able to reproduce it. This happens in GUI vim only, and only when selection is set to exclusive.

Unfortunately, selection is a global option, so we can't set it to inclusive only for Clojure buffers.

Therefore it looks like I'll have to compensate for the selection option directly in vim-sexp. This is going to take a little bit of work, so for now (if you like), you can

set selection=inclusive

after the final call to behave mswin.