Practical Vim command workflow (2023)
m4xshen.dev
m4xshen.dev
Anyway, start early/stay consistent. This stuff seems overwhelming until you surprise yourself with muscle memory
Can't speak for others, but I don't think about spelling/make-up of words while typing. They flow.
This is the ideal state with vim; muscle memory for documents. In the end it can reduce effort/improve speed
:%s/vim/any editor/
A similar idea applies to skateboarding, basketball, whatever. Sure - it's physically exhausting to get there, but the motions become routine
In fact, I have Vim mode turned on in all contexts where it is possible -- in my terminal, in any editor I use, etc. It is difficult for me to properly edit text without Vim mode, honestly.
But not using h, k, j, and l would cripple my productivity in command mode. It allows me to zip down 6-8 lines just by holding the j key down for an extra split second, or 6-8 lines up with k key -- and I can control exactly which line to stop on by lifting my finger.
It pains me to think of not having this at my fingertips.
For me, hjkl for directional keys is extremely difficult to remember. I think because in the spoken word we say "up and down", not "down and up", so my brain wants j to be up and k to be down. My muscle memory really fights me on that.
Beat that game and hjkl will feel just as natural as arrow keys, and so will a ton of vim commands.
I think the creator does himself a disservice by selling 6 month licenses rather than lifetime. But 6 months is more than enough to play through it. I think it only took me a couple days.
I'd be more likely to buy/support lifetime over six months, or really, any interval. This is a largely-unchanging editor. Why drag out this relationship? Once I learn the things, it's on me to put them to practice/make it real. Six months is lifetime, if you haven't mastered it by then I'm not sure you will.
I can't say whether or not this would be more effective than others, I haven't played it.
The proposition of buying a license at all is a bit of a hard sell. Again, there are a lot of free things to give me the info and gamified experience. Perhaps not as nice, but this needs to do a bit more to sell me than look pretty.
The hard part is aided by several other freely available games, yet experience of all kinds still teaches. I have a feeling it's more motivation or personal choice, than game(s), when it comes to why my arrow-key usage persists.
Then again, I also don't use services for languages. I'd rather read. A lot.
Presenting a subscription is just a little off-putting. How deep does the hole go, you know?
The active side of learning is one thing. The game you choose, the manuals you read, or whatever.
The other side - what happens outside of that, both actively and passively (with time), is important too. I want to stress that.
It's easier to build good habits than break bad ones, and the lines between aren't clear.
The learning aid doesn't matter if you aren't dedicated to the teachings by putting them into practice while editing.
In fact, habits you have unrelated to editing can hurt your editing!
I didn't want to turn this into a spat saying "this thing" or "that one". It defeats the purpose of my message: the learning aid doesn't matter so much, dedicating yourself to it does.
Disclaimer: I'm biased. I learned before gamification was so readily available. I can't objectively judge them completely
The game I played was called "painstakingly edit a lot and look at a cheat sheet until the bones remember". Self-enforcing learning model! Both good and bad, again - habits.
Someone willing to be so dedicated that they'll invest both money and time, while not falling back to old habits, will most likely succeed without the 'payment' part.
Anyone should be able to sit down and dedicate themselves to self-improvement or entertainment for free.
It's all very arbitrary. Not all six months are equal. Not all editing is equal. I edit more than any healthy person should, is it good or bad? Who knows.
First one for instance with resharper plugin enabled or in any IntelliJ IDE: Ctrl R R, type new word. Bonus; replaces all instances of the variable and recognizes scope in the file so if you have two locals with the same name over two methods it would change only the one you want. You want all, multi-carrot expansion Ctrl D D until you hit what you want and replace. Multi Carret is so powerful, find a repeating pattern, can be anything and even if it occurs further down where you don’t want to change just stop hitting expansion. Sure, you can do the same with VIM but comparing VIM to modern refactoring plugins is way more fair.
Things like extract method, extract variable and replace all instances at once are also one keybind away.
That said, many of these refactor systems are multi-file capable. Or even more fancy, they understand for example that an export is being renamed & update all consumers, leaving all other uses of that variable name as-is.
I'm a pretty mediocre but long time vim user. I don't intend to leave. But I remain interested in codemod tools that can help me reshape code at scale.
You get context aware search and replace with LSP in Vim too.
%s/thingamabob/doodad/g
You can put regexes in there, so for 99% of cases you're fine. In neovim (but not in vim) this will also show you a "multicaret" UI.
This is also just one mode of sed, so if you need to do this across multiple files you can just run sed.
Oh, I think I wasn't clear on what "Start" would do. At some point the ball stopped moving but I kept cruising along by clicking the "Proceed" button. Also... not sure what toggle does.
It may be slower and less efficient to hit the down key 5 times or alt+right a few times however it is also mindless and doesn't take any mental bandwidth. YMMV of course.
IMO relative numbers for navigation are not the Vi way. The Vi way, is, as you say, mindless.
People who say you're not faster with Vim (untrue anyway) or it doesn't matter are also missing the point. The point of Vim is ergonomics, and not thinking, not speed. It's diminishing cognitive load. Sometimes I like to use Vim with the cursor turned off.
Taking the first example I would instead do: `<UP>f.i<Ctrl+W>this<ESC><End>i;<ESC>`, which is probably a couple more keystrokes but also much less foreign to people today...
Edit: `<UP>f.i<Ctrl+W>this<End>;<ESC>` - no need to end and restart insert mode
https://www.reddit.com/r/unixporn/comments/jtjol5/cinnamon_l...
Of all things people get stubborn about regarding Vim, "use hjkl!" is probably the silliest. The whole notion of text object is meant to make character-wise navigation irrelevant.
Maybe I suck at reading quickly, but by the time my eyes move from where I'm reading code to the line numbers, register what the relative number is, and type it (say 15) I could have just held j or } to get there faster. Same with something like d5w. I can't count 5 words, I'll just ctrl+v to get into visual selection and press 'w' until I'm happy and call it a day.
Pretty much the only time I do counting operations is when I'm doing writing macros, at which point I've slowed down enough that counting this doesn't feel that bad.
These days things are (usually) fast enough you don't have to worry about exactness, but it's right there when you are experiencing a bad connection.
Re. your remarks about d5w: give the t/T and f/F operators a look, if you haven't already. I use these far more than numbered motions when it comes to line based motion. https://unix.stackexchange.com/questions/146824/what-is-the-...
What threw me off for a long time was trying to combine with j: it's `n+1`dj = `n`dd, and the former is almost never what I want. Since j is down I kept thinking I needed to use `jd`, and that isn't how it works.
Sort of stuck with that for upward line delete, it's never intuitive to me to want to delete three lines up and express it as 2dk. I wish that D was backward, so it would pair with t/T and f/F, but it's an entirely different sort of deletion which I rarely need to combine with a motion. Even for what it does on its own, I use d$ out of habit. There must be a way to remap it, but one of my premises in using vim mode is that the skill transfers well, and changing any of the conventions fights against that.
:set relativenumber
Once you get used to jumping right to the line it's far quicker. Searching and hopping can be quite quick _providing_ there's something unique to jump to, otherwise it can be tedious.
Typically your macro starts with a regexp search for the next item to change then you have all your editing commands (including arrow keys and inserts and replaces and whatever) - a quite complicated macro, then you stop recording your macro and tell vim to do it 1000 times. if 1000 isn't enough then do it 1000 more.
You can end up with junk at the end of your file or other issues but on the whole the ability to do a macro many times is still a fabulously useful feature.
sed usually likes to work on a line-by-line basis whereas macros aren't limited to that so vim with numbers can basically do things that no other tool does.
I have H mapped to `5h`, same for jkl, and that's good enough to do biggish jumps that I can eyeball (JJJJ is very quick to type while being iterative)
The relative number bit actually drives me nuts. Mostly I'm fixing some code error "on line 465" of my code. I open up my spacevim and I'm always at line 0, so I have to gg then 465G and it's irritating. Probably need a better IDE.
:set number
:set relativenumber
With both set, you see the actual line number you're on (e.g. line 465) and all other lines are relative.Personally I end up copy/pasting in/out of vim enough that I turn off line numbers but... FWIW, there's a way to not have the "always on 0" problem. :)
If you add `set relativenumber` to your .vimrc, then the nth line up and the nth line down from from your current line will each have an n on the left-hand side. This lets you see at a glance which motion (e.g., `5k` or `12j`) will take you to a given line.
In IdeaVim and VSCode, I've mapped the spacebar in Normal mode to EasyMotion. For jumps that aren't very close, you can land on any character you can see on the screen in 4-ish keystrokes.
It’s so much slower to move your eyes and type the number even with relative numbers than it is to just hit w, e or f horizontally or j k vertically.
And also when I'm making a quick not in Gedit I'm instantly frustrated how much moving around everything is.
But it's just all muscle memory. For example I noticed that I always press CAPSLOCK twice. I have CAPSLOCK mapped to esc, but sometimes it's not so I guess my brain adjusted by always tapping it twice.
I can still remember a time though when it was actually slower with VIM than without it.
I've used the neovim extension using neovim remote and it's not a good experience, the two just clash together too much to make it enjoyable.
VSCode has nothing on Vim with a good LSP config, granted, it can be overwhelming for beginners, but it's not that hard. It's an investment for sure, OTOH, I'm also a NixOS user :P.
VSCode has many features that make developers' lives easier. The one I'm probably using most is multiple cursor. Many others are useful in specific situations like rectangular selection etc.
No need to lay down multiple cursors then make an edit when I can just make the edit first and repeat said edit wherever I need it.
Of course, now I wonder how to quickly express "change within 2nd text delimited by ..."
c2i"
No.
First of all, people have arrow keys muscle memory from all other programs. Saying "dump it" is as obnoxious as it is stupid; it only makes enemies and gives a false impression of Vim's power.
Secondly, the mouse provides the fastest method of random access on the screen; even things like EasyMotion only barely reach mouse speed. Such nonsense gives the idea that Vim "should not" be used with a mouse, which again misrepresents Vim.
(But if you want to use a mouse, use a mouse! Choice is amazing!)
I did a video that explains some of the ways I use Vim as a non beginner. It covers some of what's in the article, but more around what I'm thinking about when I'm doing them: https://youtu.be/N__lwGR2kdA?si=7Nqc7BGGkaqJr5J8
I like “hjkl” movement for nearby characters but the idea of typing numbers to move around a document (e.g. “13k”, “4w”,…) has always baffled me. If something is more than a few lines away I either search for it and go directly or use the mouse to scroll to it.
Searching also has a similar problem where you might land on an earlier match, so it's not perfect either.
Mouse to scroll (scroll not jump?) just feels much slower to me than any of the other solutions.
3 a line
2 another line
1 a third line
4 foo
1 bar
2 bazz
3 fizz buzz
As far as jumping words, I personally feel that it's easy enough to eyeball.edit: I see that they have the note 'There are line number and relative line number on the left.' in the post.
(Although I've now left copy-pastability behind a bit with `list listchars=tab:··▸`... Maybe I should try them again)
That's helpful for sure :) unfortunately I'm often running vim on a remote system though
One that I don't use enough:
$vim my_file.c +321 (open vim on line 321)
Surprised at how many vim users I run into don't seem to use visual mode that often, stuff like this is fantastic for commenting out multiple lines at once or aligning "=" signs in stuff like terraform.
one that I can navigate with keys up/down, enter to open that file or drill into that folder, backspace to go up a folder
maybe page up/down to flip through pages of files on the screen.
I used to work with iseries and I miss that workflow for editing files through cli
https://vonheikemen.github.io/devlog/tools/using-netrw-vim-b...
When screen sharing with a colleague who might be unfamiliar with vim, it is easy for them to help us navigate if they see a tree compared to the magic of ctrl-p/fzf fuzzy search based on their hints.
Is quite popular.
It just treats your file structure as a buffer
vim-vinegar for some netrw extras