VSCodeVim / Vim

:star: Vim for Visual Studio Code
http://aka.ms/vscodevim
MIT License
14.02k stars 1.32k forks source link

Don't move back 1 character when exiting Insert mode #7548

Open verhovsky opened 2 years ago

verhovsky commented 2 years ago

To replicate, write a sentence like

hello world

then move the cursor to the end of a line and repeatedly type i, Esc, i, Esc (i.e. enter and exit insert mode). The cursor will eventually end up at the beginning of the line instead of staying where it started.

Describe the solution you'd like I would like a config option like

"vim.moveCursorBack": false,

that would keep the cursor where it is when exiting insert mode (default to true).

Describe alternatives you've considered I think I could use NeoVim integration because there's definitely ways of configuring it to behave this way, I think I do it with autocmd InsertLeave * :normal `^. See https://vim.fandom.com/wiki/Prevent_escape_from_moving_the_cursor_one_character_to_the_left#Programmatic_Alternative

J-Fields commented 2 years ago

This is a niche enough use case that I'm unlikely to support it explicitly (the config is already much more bloated than I'd like). More complete support of vimscript is planned, but it'll be a while until autocmd and such work well enough for that to work.

inoremap <Esc> <Esc>l gets you close - it just moves your cursor to the right on the first column. There may be some clever way of getting around this; I'm not sure.

verhovsky commented 2 years ago

Evil (vim bindings for Emacs) has a dedicated evil-move-cursor-back config option for this and it's also a somewhat common question on stackoverflow

so it's not that niche. I'm honestly surprised that I'm the first one to ask about this.

verhovsky commented 2 years ago

Another place where this matters and where it should also have an effect is when pasting text. If you copy some text like abcd and move your cursor to be in the space between the words

hello world
     ^

then press p then press C you will delete the last letter you pasted

hello abc
         ^

So pretty much every time I paste something I have to press l, whereas in Emacs using Evil with the above mentioned option, I don't.

gabrieljreed commented 1 year ago

This is long past, but I'd also really appreciate this functionality!

darianmorat commented 11 months ago

I just realized about this issue and is driving me crazy

catesandrew commented 5 months ago

chatgpt$ rewrite the evil-move-cursor-back function from emacs lisp into javascript. 🤣