πΎ Archived View for bbs.geminispace.org βΊ s βΊ vim βΊ 21350 captured on 2024-12-17 at 15:10:33. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
I love vim, but perhaps I am using it wrong!
Whenever I do just about anything, I am pretty much always off by one character.
In the simplest case, if I enter the instert mode and exit it, I am no longer on the same character! If I do it repeatedly, the cursor will crawl backwards.
Whenever I yank and paste, I invariably wind up one character past where I wanted to paste.
I thought I would get used to it eventually, but it's now been years and I am constantly 'cleaning up' almost every non-trivial edit by deleting or inserting a character or two I just butchered. It is driving me nuts.
Am I doing it wrong? Is there something I am missing?
Oct 30 Β· 7 weeks ago Β· π fab, datavoid
Yes, the cursor moves backwards if you constantly change from insert to normal mode. You're not using it wrong, but maybe I'm so used to it that I didn't notice. Pasting goes always before the cursor is on in normal mode. I just "imagine" an insert cursor (juat a line) between the character the cursor is on and the char before. I have no help for you for your feeling of "using it wrong", it's just the way it is. But you can always do an undo after a paste if it's wrong positioned, move to the right space and paste again.
π¦ wasolili [...] Β· Oct 30 at 23:24:
I invariably wind up one character past where I wanted to paste.
P will paste before the cursor, whereas p will paste after, so you may just need to use P instead (or remap p to P)
there's also gp and gP which can be useful, and insert mode's CTRL-R, as far as pasting stuff goes
moving back after insert mode
if you enter insert mod using a instead of i, you won't have the same issue.
using wrong
who's to say, but I am a bit curious about whether or not object-select motions are integrated in your worfklow since I've found that makes the exact cursor position fairly irrelevant for a lot of edits (e.g. ci" caw etc
π stack [OP/mod] Β· Oct 30 at 23:44:
wasolili: I am always forgetting the motions and wind up moving the cursor like a fool. I really need to bone up on simple selection... I also wind up accidentally shifting my hands, especially when I am tired, and getting myself into serious messes that are not undo-able!
π² halscode Β· Oct 31 at 01:29:
the biggest off-by-one that bugs me is that if I select multiple words (i.e. vw, v12w, etc) it selects the start of the next word, not the end of the word.
...and somehow I just discovered I'm looking for e, not w
π² halscode Β· Oct 31 at 01:32:
@wasolili
object-select motions
like the "a" in via (visual inside argument)? I find that those tend to not select what I expect them to. Maybe that's mini.ai's fault.
π¦ wasolili [...] Β· Oct 31 at 03:31:
yeah, all the motions listed in `:help object-select` and `:help objects` (the a for argument one isn't stock vim tho, that looks like it's from mini.ai)
I don't use mini.ai tho so I'm not sure what changes it makes. the default vim ones act as expected for me
π¦ CarloMonte Β· Oct 31 at 06:46:
I moved from VI to HELIX (never liked VIM: too heavy). From there, I never looked back.
π satch Β· Oct 31 at 09:25:
Just installed Helix. Love it, but a lot to get used to. First thing I did was map ZZ and ZQ to :x and :q!
π mbays Β· Oct 31 at 10:23:
@stack
getting myself into serious messes that are not undo-able!
Do you use the undo tree, accessed with :undolist? With that, it should be basically always possible to revert accidents.
I'd send a bug report/feature request to a new Vi/Vim incarnation such as Neovim, and start using that when/if this is fixed.
π stack [OP/mod] Β· Oct 31 at 22:59:
It's not a bug, as everything is like that. It is mainly a consequence of the fact that in insert the cursor is between characters and in normal mode it's on a character, but for some reason the position always slips to the left and is not restored... That's why I feel like I am missing something that (Molinar or whoever started doing it) had in mind... Although it could be just stupid.
π¦ wasolili [...] Β· Nov 01 at 01:59:
I got curious as to what the reasoning behind it was since, until now, I've just taken it as "it is what it is" and found this (in :help faq-10-2):
In insert mode, when I press the <Esc> key to go to command mode, the cursor moves one character to the left (except when the cursor is on the first character of the line). Is it possible to change this behavior to keep the cursor at the same column?
No. It is not possible to change this behavior. The cursor is always positioned on a valid character (unless you have virtual-edit mode enabled). So, if you are appending text to the end of a line, when you return to command mode the cursor must drop back onto the last character you typed. For consistency sake, the cursor drops back everywhere, even if you are in the middle of a line. You can use the CTRL-O or CTRL-\ CTRL-O command in insert mode to execute a single ex command and return back to insert mode without moving the cursor column.
so I guess Bill Joy just preferred that editing the very start of the line be inconsistent instead of editing the last character of the line being inconsistent. not that interesting, but at least I learned about insert mode ctrl-o
π stack [OP/mod] Β· Nov 01 at 02:03:
Yea, sort of makes sense, maybe. It sure drives me nuts!
I am constantly catching an extra character by yanking lines in V mode. To copy 2 lines I intuitively go down 2, and catch the first character of the next line! Combine that with pasting in the wrong place, and my next few minutes are occupied by furious remedial editing...
π¦ wasolili [...] Β· Nov 01 at 02:35:
for copying 2 lines, I usually just do `yj` which will yank the entire current line and the line after. numbers can be used for more lines, e.g. `y2j` for the current line and the next 2, and k works as expected (e.g yk for current line and the line above it)
then there's `yy` for just the current line. there's also the move and copy commands which are occasionally useful.
I very rarely use visual mode since usually the default motions behave more usefully outside of it. (as in `yj` from normal mode yanks the two lines, but `vyj` only yanks part of each line unless you do `0vj$y`))
I'd say the off-by-one thing is a UX bug. For me the main powerful idea behind Vi/Vim is not where the cursor ends up, but modes (normal/insert/visual). And the reason why modes matter is that typing becomes easy, because the user rarely has to press more than one key at a time on the keyboard. None of that Ctrl-Alt-Shift finger acrobatics.
π satch Β· Nov 01 at 13:32:
It would be pretty easy to make it the choice of the user whether to have the inconsistency be at the end of the line or the beginning of the line.
That way people who are bothered by the behavior could add something simple to their init script and problem solved.
That being said, itβs pretty easy to get used to - especially if you make frequent use of βAβ.
π stack [OP/mod] Β· Nov 01 at 16:28:
OK, I will make it a goal to find the bindings that actually do what I want and get used to them.
@arma - yes! Before Vim I spent almost a decade or so with Emacs and Common Lisp, and my hands are a wreck.
π¦ fiore Β· Nov 09 at 19:00:
happens to me as well!