I’d like actual examples instead of “I work faster”, something like “I can move straight to the middle of the file with 7mv” or “I can keep 4 different text snippets in memory and paste each with a number+pt, like 2pt”, things that you actually use somewhat frequently instead of what you can do, but probably only did once.
Where editors usually have editing shortcuts, vim has an editing grammar.
So you can copy (or select, or replace, or delete, or any other editing verb) N arguments or blocks or lines or functions or any entity for which vim has an editing noun, or around or inside either of these, and you only need to remember a few such editing verbs and nouns and adjectives in order to immediately become much more effective.
It’s so effective that switching back to a regular editor feels annoyingly clunky. (I guess that’s why many offer vim plugins these days.)
Better: you can record entire editing sentences and replay them. Ever had to make the same change on dozens of lines? Now you can do it in seconds.
Now of course, replaying a sentence, or several sentences, is also a sentence of its own that you can replay in another file if you want.
It’s neat. :)
Better: you can record entire editing sentences and replay them. Ever had to make the same change on dozens of lines? Now you can do it in seconds.
I think my first experience with that kind of macro recording/replay was with Dwarf Fortress, of all things.
I had no idea DF had macros but it makes so much sense.
CTRL R starts recording the inputs, press again to stop. CTRL P plays it. Makes digging magma shafts through several floors, then setting up the pumps, so much easier
I didn’t know this and tried to record on my keyboard a macro, and DF blocked me when I tried to use my keyboards built in macro keys. I guess that makes sense.
Ever had to make the same change on dozens of lines? Now you can do it in seconds.
This would be a big advantage… except multiple cursors were invented so I can easily do that without having to memorize a whole new editing language.
Multiple cursors are fantastic for certain use cases, but will not help you when each line needs a different input – if you’re swapping arguments in function calls, if you’re replacing one bracket type with another around contents of arbitrary length, etc.
Mind you, if your objective here is to not learn a new thing, then you can just go ahead and do that, you don’t need an excuse.
Yeah, I usually do that with regexp replacement in other editors, but sometimes it’s too hard to express as a regular expression
That’s just one thing the editing language does, though. There’s no single feature you can point to as the smoking gun; it’s all the small advantages added together that make vi worthwhile.
This is the comment that best explains it for me. I started with vim for comfort (less movement to mouse, and less reliance on modifier keys). The editing grammar is something I didn’t really understand until I started gradually using it, but now it’s the thing I most appreciate. I don’t know if I’m necessarily faster in vim, but my work is more fluid. The editing doesn’t interrupt my thinking as much.
Honestly the best bit is just not feeling the need to take my hand off the keyboard and use the mouse. I don’t think I can quantify the time saved, but I can tell you I really notice when I’m using software that makes me have to switch.
Yeah when my hand goes to the mouse it feels like I’ve broken a combo or streak. Like I’ve switched from an active to a passive mode. The mouse is for clicking and scrolling, like reading email and webpages
The Acme editor (and Sam) begs to differ. Sadly it’s hard to find a mouse that can do mouse chording today.
So, like every text editor also without a beep-mode?
I don’t know if this comment comes from ignorance or snarkiness but it’s really not the same. Other editors add in hotkeys over time to perform a single function.
Vim key bindings are actually a terse text manipulation language where you can form arbitrary “sentences” like:
-
ciw
- change the current word, meaning remove it and then enter insert mode -
D
- delete until end of line -
dt:
- delete everything between the cursor and the next colon on this line -
10"ap
Paste the contents of thea
register 10 times
-
I am logged into various servers via ssh constantly and nano or vim (or at least vi) are installed pretty much by default everywhere.
That doesn’t explain a preference for vi(m) over nano, tho
How could I live without dd, vap, 99j, 99k, 555gg, zt, zz, zb, [, ]?
If these were the only vim commands it would still be better than Nano.
For me it’s plain ol’ tT and fF. I get frightfully bored when a text field makes me use Home/End/arrows 😪
It’s like, I know where I want the cursor, just let me GO there. And no manually moving my cursor into position is not it. It’s so not it
I don’t know this command, about to test it out.
I always use 0 and $, then W and B to leapfrog words manually 💀
Thanks!
Welcome! I also stumbled upon these after I’d been using vim for a while. You’ve probably seen them in guides but glossed over them like I did originally. But once you get used to using these keys, you’ll wonder how you lived without them!
Used in combos like
f(dib
(delete function parameters), or2t.
(go back two periods, or sentences) they’re so great for moving within a long row.
Nano is extremely basic, it’s not really the right comparison. Vi competes well with heavyweight GUI editors and IDEs, yet is available about as ubiquitously as nano.
By learning vi, I can have my no-compromises favorite editor equally available to me locally or remotely. The terse, low-chord (looking at you, nano) editing language in vi means I’m not even that hampered when I do remote editing from my phone.
Its not so much about the time saved its about being allowed to stay in a mental state of flow since all actions in Vim and similars are built from foundational navigation language chunks. It feels less like editing and more like communicating. All these random little “I can do this command” is just people trying to show examples of how the language of editing to do weird and interesting things. So the answer isn’t so much “I work faster” in Vim as it is “I work with less mental overhead in Vim”
Just being able to jump to the top of the file, bottom of the file, beginning or end of the line, or directly to a regex pattern match or particular character already gives me some of the same satisfaction as a video game with really tight movement controls. (I also like being able to jump to lines by number, manipulate lines by number or range, and I like being able to get to the top, bottom, or middle of the screen with one or two keypresses.)
In the same vein, deleting arbitrary lines at a time, performing external operations only on lines that match a particular pattern, and saving macro recordings of repetitive manual changes all feel like multiplicative powerups. Heck, incrementing and decrementing with ^a and ^x feels like one more little cheat code. Bouncing on parentheses with % makes structured files easy to get around in.
These are all things I’ve done with some regularity over the years.
Bouncing on parentheses with % makes structured files easy to get around in.
That’s something I wasn’t aware you could do in vim. % jumps to the next parentheses character, whether ( or )? Does it work with brackets and curly braces too?
So far as I’m aware, yes. As a C engineer, it’s also useful for jumping from #ifdef to #endif .
Not just the next parenthesis that appears, It jumps to the matching one that opens or closes the one under the cursor. Hitting it repeatedly bounces back and forth around the text that pair of parentheses enclose.
It works not only with brackets and curly braces, but also with opening and closing tags in XML etc.
I feel like other editors must have an equivalent feature, though. I’d say the fact that vi can put such a specific action under just
%
rather than some nasty chord or mouse operation is what really makes it shine here.It generally works with a wide variety of delimiters. There’s a widely used plugin to make it work with even more, including language-specific keyword pairs.
deleted by creator
I do most of my work on my laptop, which has a really shitty touchpad (a system76 pangolin 12). Using the touchpad to scroll, move around, etc. feels clunky and frustrating. Using my wonderful keyboard feels amazing, quick, and responsive. Honestly, that’s the main reason I use neovim; touchpads, especially bad ones, just feel clumsy, imprecise, and inefficient.
Now I’ve gotten used to typing
nv
and, in under 30 milliseconds, getting a full-featured, LSP-supporting text editor. Other editors trigger my impatience now 😂. The features are secondary to me, they’re not what makes nvim great.If there were two things that are a game changer for me though, they would probably be
<C-o>
(mixed with plugins like trailblazer) and the incredible ease of use that vim macros offer.Coding in neovim, I don’t know that I am that much quicker or more efficient. Maybe with certain actions I am, but its probably n9t measurable.
What I do get though, is a sort of flow state. It’s like playing a video game where I try to edit text with the fewest keystrokes possible. It’s genuinely fun and I can code longer since its fun.
Time saved is not the most important part. Here is my opinion:
- it is very satisfying to use. Once it becomes muscle memory, vim just gets out of your way, and you feel like you’re one with the computer. Your ideas flow freely from brain to document.
- neovim is highly customizable and scriptable. You can make it do many things, many of which were never even conceived by the developers.
One thing I haven’t seen mentioned is that not moving between mouse and keyboard so much reduces the risk of getting an RSI. So even if it didn’t make you faster it would still probably be worth it to find a keyboard based workflow.
I use Helix and would suggest you try it (at least to start off with) as it is easier to learn than vim and does not require plugins or a complex config. To answer your question I will go from the less to more advanced/complex:
- Move a line to a new position in the file/another file (takes a couple of seconds)
x
thend
to select a line (pressing N times will select N lines) and delete it (delete will also copy to the clipboard)- navigate the cursor to the new location
p
to paste in a new
- Navigating around a file:
- jumping to a function/class definition by pressing
g
thend
when on a function/class usage. - getting a list and navigating to class/function calls when the cursor is on a class/function definition by pressing
g
thenr
.
- jumping to a function/class definition by pressing
- Multi cursor editing - I use this to make edits to multiple places at once. I most recently used this to extract the names of 30 tables that are used in a SQL file. This probably took ~5 seconds and I barely thought about it. To do this I used:
%
to select the entire files contentss
to search- typed "FROM "
- pressed enter to create cursor at all locations matching the search
v
theng
thenl
to select the rest of the linespace
+y
to copy to the system clipboard.- paste into a document where I needed to list the tables
- Using a terminal workspace manager (zellij) with helix and a git tui app (gitui) so that I can easily make code changes, commit, push, ,run tests, move to a new repo and more without leaving the keyboard.
There is actually a helix community on programming.dev: [email protected]
- Move a line to a new position in the file/another file (takes a couple of seconds)
I use vim bindings in vscode, but I’m trying to switch to neovim.
It’s hard to talk about efficiencies without use cases but here’s some that I like:
- Compared to using mouse, text selection is just much easier in vim. Instead of accidentally highlighting an extra space and clicking somewhere on accident which gets rid of my selection, vim lets me go directly to the end of the word and be precise about where I’m selecting.
- I remember before I used vim, I would count the number of times I hit the backspace or delete when I had heavily nested parentheses. With vim I just type the exact number I want, and if I were to undo that operation I also know exactly what was changed, whereas when counting there’s always the possibility of miscounting or pressing delete without counting.
- I don’t have to scroll. I can jump 100 lines in less than a second. Instead of searching through long files to find where I left off, I just generally remember what line number I was at, then I can simply just jump back.
- Forces me to type better. Before vim I had really shitty typing form(I don’t know what it’s actually called) but switching to vim shone a light on exactly how I was typing wrong, and now I type faster.
- Using the % operator you can jump between brackets or parentheses. This comes in handy especially when you want to highlight the inside of a function call, or just jump to the end of a pair of brackets
- Ctrl-left/right jump to the beginning/end of words
- No exactly sure what you mean here.
- Page up/down let you scroll up/down quickly. Ctrl-P :123 lets you jump to a specific line, but I generally use editing history (alt-left) instead.
- I can type perfectly well…
- Ctrl-{ or } does this I think.
Do you have any more compelling examples?
Ooh fun, these all take 2-3 key presses
- Delete the contents inside a function delimiter by {
- Delete the next nine words
- Delete the contents inside long text quotes
And these more/less key presses
- Start a regex search with a single button
- Perform the same edit 100 times in a jagged files (good luck not f’ing up your multi cursor)
But it misses the point, of course every editor can do just about anything, but there is a lot more mouse involved and learning it is more difficult because the keybinds aren’t combinatorial
- Ctrl-shift-}
- How often do you want to delete exactly 9 words? It’s much easier if this is interactive.
- Not a common task IMO.
- Ctrl-F and click a button. This is rare enough that a button click is fine.
- Not sure what you mean by “jagger files” but I find multiple cursors are a lot easier to get right than e.g. regex replace because they give you instant feedback. Vim sequences are more like “oh you got it wrong, better start from scratch”.
1 is just going to highlight right?
2, how about 6 words, 10 words, 100 words
3, 4 I use all the time
5 if your edit locations don’t line up so that you can alt drag a single column, this is what I mean by jagged. I would use a combination of find and repeat action.
Start from scratch - skill issue :p
how about 6 words, 10 words, 100 words
Yes exactly my point. How often do you need to delete exactly 100 words? Do you count them? Obviously not - you probably guess and delete 50, and then 25 and then 20 etc.
10dw . . .
Superficially, typing <Ctrl>+<left> seems to be the same as typing <Esc> <b>, but these are two completely different paradigms of using the editor.
Vim does not use shortcuts or hotkeys to edit the text, it uses a language to communicate with the editor.
For me, shortcuts and hotkeys are rote memorization, and I’m bad at rote memorization – compare your point “5. Ctrl-{ or } does this I think”. Do I need Ctrl-left, Super-left, Alt-left, Shift-left or Ctrl-Shift-left to jump back a word?
The vim editing language is mostly consistent and logical. I did not need to memorize it, I could learn and understand it. But that’s just me.
Far too much examples:
Most commands are abbreviations – a for append, b for back, c for change, d for delete, e for end of word, f for forward, g for goto (and more), hjkl are special, i for insert, m for mark, n for next, o for open line, p for paste, q for reqord macro is a strange spelling, r for replace, s for substitute, t for to, u for undo, v for visual mode, w for word, x for extinguish, y for yank, z is just a prefix for arcane stuff. Capital letters are usually variants of their minuscle counterpart – like A for append at end of line.
Commands take a repeat count, and a lot of commands take objects/movements, and these reuse the commands, like “delete inside backticks” => di`, “yank inside brackets” => yi{, “change up to third slash” => c3t/
If you are fluent in vim, you won’t type shortcuts while editing, you will talk to your editor.
As for more compelling examples:
“I’d like to change the next 2 sentences” translates to )c2)
“Please format this paragraph.” translates to gqap
“Swap these two characters.” translates to xp
And I did not touch ex mode, vimscript and plugins yet.
Nah I don’t have any more examples cuz I haven’t been using vim for like 30 years. I think the other comments make good points tho
Instead of remembering what line number you were at, you can use marks (
:help mark-motions
) to immediately jump back to where you left off.For example, type
mx
to mark the current position withx
(or anything you want). Say now you are at the top of the file, just type'x
to go back to the line marked withx
.
I’ve been using vi since my mentor at an internship sat me down with a copy of “Unix in a Nutshell” and told me to learn it. This was before I discovered Vim, so I think I was using nvi which had very limited in-editor help. It was a struggle, especially compared to the resources available today.
Around the same time, circa 1999, Tom Christiansen (of Perl fame) wrote an essay called “Zenclavier: Extreme Keyboarding” which still speaks to me, and is worth the read.
In brief, I’ve never been able to “zen out” in a typical non-model text editor, at least not the way I can with [neo]vi[m]. It’s hard for me to overstate how great it is to not have to reach for the mouse - or even outside the home row of the keyboard. Christiansen calls this the “penalty zone” - any time you need to move your fingers away from home row, you’re breaking flow. And when programming, it’s something we have to do all the time!
There are other editors that support this kind of thing, like Emacs. Even VS Code and Visual Studio can be navigated entirely with the keyboard if you’re willing to memorize their keybindings. But they generally rely on “chorded” keystrokes, which put your fingers into sometimes tortured positions (the old unix editor holy war joke is that Emacs stands for “Escape Meta Alt Ctrl Shift”). And often you still have to reach for keys in the “penalty zone”, like PgUp/PgDn/Home/End.
I’m biased, having used vim keybindings in basically every editor I’ve programmed in for the last 25 years. It would be impossible for me to go back now. There are other modal editors, like Helix and Kakoune. They’re basically like vi, but they reverse the order of the keybinds - which has some really nice features, and I might even suggest you try those before getting sucked into vim-land like me. But I do think modal editing, in general, is where it’s at for pure text. Especially programming, but I use it all the time for other tasks like formatting textual data files interactively.
Anyway. Maybe it’s a cop-out, but I think it’s something you have to experience to really appreciate.
I’ve been using vim as my daily driver for development for the last 8 years.
There are a million things I could talk about regarding vim’s editing language, consistent interface, scriptability, performance (seriously, I’ve opened 1GB+ files and vim barely breaks a sweat), etc., but one thing I’ll highlight that most people don’t talk about is vim’s ability to interface with other tools. It’s what takes vim from a great editor into a full-fledged development environment. You can:
- Read the stdout of any shell program into a vim buffer (
:help read !
) - Use the contents of a buffer as stdin to any shell program (
:help write !
) - Filter a portion of the buffer through any shell program, replacing the contents with that program’s stdout (
:help !
) - Parse the output of a program or the contents of a file into a set of entries for quick navigation (
:help quickfix
,:help make
) - Insert the output of a shell program into the current buffer (
:help <C-R>=
, specifically when used with the:help system()
function) - Control arbitrary jobs with vimscript and communicate back and forth with code
And much more. I use all of these every day: the output of git commands give me filepaths I can jump to with
gf
; a range in vim selected with thev
command gives me line numbers to pass togit log -L
to see the history of a section of code; the current filepath of the vim buffer is pass to many different shell commands to do processing with that file; the symbol under the cursor is passed as an argument to theopen
command on macos to lookup external (company-specific) documentation in a Web browser. And many, many other things. Unix is my IDE, and vim is at the heart of it.And here I am proud that I can open a file, save it, make edits, jump to the beginning/end, and quit it. 😅
- Read the stdout of any shell program into a vim buffer (
Stockholm syndrome
Is there any good interactive VIM/Helix tutorial/practice tool? I imagine something like hotkey trainers for Starcraft, or keyboard typing trainers. It gives you a task, and measures time how fast it takes you to do it, giving you hints about best keybindings in the process. I did find https://www.openvim.com/ , which is great to learn what options there are, but I’m missing the trainer part of it giving you tasks and scoring you on them, that you can drill in to learn it quicker.
Also, it’s missing macros and some of the more advanced stuff, which would also be great if included.
Vimgolf is really cool, thanks for sharing
One of my favorite emacs features is the VHDL stutter mode (which replaces certain repeatedly-typed characters with operators), as well as an easy to get to rectangle select, and it just being decently fast compared to something like VSCode. I also never have to take my hands off of the keyboard, because it’s all right there. It just feels better to me.