5 ms·
Practical Vim command workflow (2023)
- mathfailure 3y ago> Don’t use arrow keys and mouse No.
- allarm 3y agoThanks for your valuable input.
- ykonstant 3y agoYup; this is an extremely silly thing to say. 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.
- allarm 3y agoYou know, when you learn something new you don't necessarily dump the previous experience. Also it took me just around an hour to get used to hjkl back then, why there's so much moaning about it?
- Repulsion9513 3y agoI would generally argue that mouse is slower. If your hand is already on the mouse it is faster but the act of moving your hand to the mouse introduces quite a bit of latency. I can type a few keystrokes (which is usually all that it takes to move within the screen) in the time that it takes to move my hand to the mouse and locate the cursor... (But if you want to use a mouse, use a mouse! Choice is amazing!)
- camgunz 3y agoNah, if I see something on screen I want to go to, I type /thing_I_want_to_go_to<enter>. I finish that before I would even touch the mouse with my palm (or touchpad with my fingers) because I never have to leave home row.
- bastardoperator 3y agoDevelop new muscle memory, having to move your hand off the home row to the arrow keys is an absolute waste, god help the people using a pinky finger. Secondly, I would argue disabling the mouse in vim is commonplace.
- bravetraveler 3y agoI never managed to move away from arrow keys. 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
- jononomo 3y agousing Vim without using h, k, j, and l for navigation is incomprehensible for me. 20% of the keystrokes that I perform in command mode must belong to that group of four keyboard navigation moves. 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.
- bravetraveler 3y agoToo late now... but I'd like to edit :) :%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
- danielvaughn 3y agoI'm slowly getting into it, though I definitely didn't start early (been coding since 2009). Although funnily enough, I do remember using Vim a couple of times back when I was 10 years old, on my 95 Packard Bell. 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.
- serial_dev 3y agoRemapping them is always an option (though it obviously has its disadvantages).
- sameoldtune 3y agoI use vim every day and use a completely different workflow that heavily relies on searching and (gasp!) mouse mode. 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.
- bmoxb 3y agoI also rely heavily on search. When editing code, I am frequently looking to modify a string of characters somewhere in the middle of a line. Navigating firstly to the correct line and then also the correct position within that line is probably going to require several keystrokes anyway so why not just use search to go there directly?
- mattpallissard 3y agoThe trick is to set both number, and relative number. You then get line numbers in the side. The line your cursor is on is the absolute line, but above and below them are offsets. Makes jumping up/down lines easy. So the cursor sitting on line 4 of a file looks like this 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.
- Repulsion9513 3y agoI don't like number because it makes it harder to copy-paste from vim. LOL (Although I've now left copy-pastability behind a bit with `list listchars=tab:··▸`... Maybe I should try them again)
- mattpallissard 3y agoThat's why I set the vim copy-paste buffer to the operating system clipboard. So you can use visual select and y/x.
- deodar 3y agoI recently switched to vscode after using vim for over 2 decades. Perhaps I am just getting older, however I now find that hitting 5j or 12k as in the article steals some cognitive bandwidth. I still use vim for looking at log files and quick edits e.g. to config files, and went mode-less for more free form editing like coding. 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.
- jononomo 3y agoWhy would you hit `5j` when you could just hold `j` down for an extra tenth of a second and then just literally put your finger/cursor on any line you want?
- SebastianKra 3y agoWaiting for the visual feedback to tell you where the cursor is, also takes some bandwidth. For example, vscode has this awesome syntax-aware expand-selection feature, but it requires you to repeat the command multiple times and check the results between each press. When applicable, ci{ is better because, despite requiring more mental bandwidth, you know exactly what the result will be.
- lambdaba 3y agoI agree but staying in neovim and using search / or ? 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.
- tiptup300 3y agodoes anyone know a I don't know module or extension for vim that jumps to a text based file browser. 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
- zx321 3y agoSomething like this maybe? https://github.com/luukvbaal/nnn.nvim https://github.com/luukvbaal/nnn.nvim
- kirlfiend_grill 3y ago:Ex
- jacksonrya 3y ago:help netrw vim-vinegar for some netrw extras
- akozlev 3y agoI used netrw in the past but I switched to oil.nvim [1]. I highly recommend it. It lets you edit the your files and directories like a vim buffer. It also supports lsp rename which convenient. [1] https://github.com/stevearc/oil.nvim https://github.com/stevearc/oil.nvim
- Icathian 3y agoNetrw is quite good. Oil.nvim is by far the best if you're willing to monkey with a plugin.
- iaresee 3y agohttps://github.com/nvim-neo-tree/neo-tree.nvim https://github.com/nvim-neo-tree/neo-tree.nvim Is quite popular.
- lizardking 3y agoI used to use neo-tree but at this point I've settled into using netrw which is the default file browser. Just open vim in a directory rather than a file and you will boot right into netrw. https://vonheikemen.github.io/devlog/tools/using-netrw-vim-builtin-file-explorer/ https://vonheikemen.github.io/devlog/tools/using-netrw-vim-b...
- jurschreuder 3y agoI honestly have no idea how I'm controlling VIM but I only know when I'm trying to help someone in VSCode that I'm thinking: How can you live like this? 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.
- dvfjsdhgfv 3y ago> I honestly have no idea how I'm controlling VIM but I only know when I'm trying to help someone in VSCode that I'm thinking: How can you live like this? 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.
- spiderice 3y agoYou are right about VSCode having a lot of quality of life features. But regarding multiple cursors, for me the “.” key in Vim made them obsolete. 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.
- stnmtn 3y agoThis is why for me the best setup is VSCode with a solid VIM extension. You can run NeoVIM directly in VSCode. Best of both worlds.
- camgunz 3y ago"." is wonderful, but let me tell you that I bit down and learned macros a few years back, and boy oh boy has that saved me... so much time. They're complicated, but I can say it's worth it.
- QuadrupleA 3y ago
- bastijn 3y agoAll posts I read on VIM always compare to a barebone editor without proper refactoring plugins enabled it seems. Would love to see a proper comparison against state of the art refactoring and against a skilled user of those systems. 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.
- denvaar 3y agoI didn't get the impression that this post was trying to compare vim to anything (which is refreshing). Seems like this is simply demonstrating how to use vim, given a few real-world editing examples.
- Repulsion9513 3y agoYou can of course get plenty of "refactor" plugins for vim out there but I've never found a need for one. Even in more complex codebases with multiple instances of a local variable like you mention, I tend to do more "find-and-replace in selection": V to Visually select a block, then just :s/foo/bar/g
- jauntywundrkind 3y agoGenerally with you 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.
- denvaar 3y agoThe gif's/short clips of each situation were a good way to present that information.
- Repulsion9513 3y agoA lot of these are nice, but honestly, why not use the arrow keys? You can prefix them with a number just the same as `hjkl`, and jump around by words with Ctrl, just like you're already used to. 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
- javier123454321 3y agoI believe it's just ergonomics. There's no reason to use the arrow keys if your fingers are already on hjkl. The pinky motion is highly impractical, and moving your whole hand is also. Therefore the only reason to use them is because you have the habit, and the idea is to replace that habit while editing with the hjkl keys.
- Repulsion9513 3y agoYou know, that's fair. I touch type but I also peck, so I don't really notice it. So long as I don't have to go to the number pad or, god forbid, the mouse - it's no difference to me.
- denvaar 3y agoThe benefit of hjkl is that it keeps your fingers on home row. I see your point that it could be considered dogmatic, though. Personally, I'm a fan of hjkl.
- ykonstant 3y agoNo reason but personal preference; here is me using the arrow keys: https://www.reddit.com/r/unixporn/comments/jtjol5/cinnamon_latex_workflow_in_vim/ 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.
- lambdaba 3y agoArrow keys suck on most laptop keyboards.
- doix 3y agoDoes anybody here use the number repeating thing and feel like it's faster? I could _never_ make it faster, doesn't matter if I have relative lines or any other combination of settings. I've spent some time deliberately practicing and just gave up. I set my repeat delay very low and repeat rate pretty high, and just end up holding j/k, {/} or some other movement operator. 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.
- QuadrupleA 3y agoAs a decades-long Vim user, same here, absolutely. Much faster for me to hit j 5 times than to count lines downward in my head. And to use visual mode for deletes etc. rather then precounting in my head beforehand.
- petepete 3y ago> than to count lines downward in my head :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.
- williamdclt 3y agoI'm with you. The page gives "5k 12j" as an example, there's no way in the world it's faster for me to figure out that "12" is the right number faster than through other means. 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)
- bumbledraven 3y ago> The page gives "5k 12j" as an example, there's no way in the world it's faster for me to figure out that "12" is the right number faster than through other means. 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. https://jeffkreeftmeijer.com/vim-number/ https://jeffkreeftmeijer.com/vim-number/
- rafamct 3y agoSelf promotion (in the form of a video I made anyway if that counts). 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 https://youtu.be/N__lwGR2kdA?si=7Nqc7BGGkaqJr5J8
- nbulka 3y agoWhat do you all think about this? I spent a lot of time on it last year and then put it on the backburner but I was thinking of updating some of the levels to reflect this Practical Vim Command Workflow. https://www.vimarcade.com/ https://www.vimarcade.com/
- inanutshellus 3y agoThis is great! Consider adding ":n" for "next lesson". As in - not having to grab the mouse every few seconds to go to the next lesson on a keyboard-only tutorial would be nice. 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.
- mhd 3y agoOh, embarassing, I used ci" quite often, but always maneuvered to the starting quote beforehand. Didn't know that it just took the next one the line. Of course, now I wonder how to quickly express "change within 2nd text delimited by ..."
- Gnurou 3y ago> Of course, now I wonder how to quickly express "change within 2nd text delimited by ..." c2i"
- JohnMakin 3y agoctrl v (visual mode) -> highlight lines you want to change -> shift i -> add whatever you want to the line -> escape -> Gets applied to all highlighted lines. 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.
- javier_e06 3y agoI frown on rule 3. Ctrl-D or other Ctrl commands can be mistakenly be sent to your session and oops. Bad things will happen. I train my muscle memory on %s global substitutes and other good tid-bits in the article. One that I don't use enough: $vim my_file.c +321 (open vim on line 321)
- JamesLeonis 3y agoProbably my best ergonomic change is remapping CAPS LOCK to CTRL. It makes every <c-XYZ> better, and you can use <c-[> as ESC. Do your pinky a favor!
- brisketbbq 3y agoI like to use vimium with firefox: https://github.com/philc/vimium https://github.com/philc/vimium