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.
A godsend for saving time - the
ab
(abbreviation) command. This command lets you shorten a long sequence of characters (be it a text or a complex command) into another sequence of any length. It works in both insert mode and command mode. If you frequently edit text using a lengthy command, this feature will significantly save you time. For example::ab ul s/\<./\u&/g
to capitalize every word in a line. When you enter command mode (type:
) and typeul
, vim will automatically expand it tos/\<./\u&/g
for you.Additionally, the
map
command can save even more time, but IMO theab
command offers more control for handling various cases. In my example, you can useul
to only capitalize the lines that have a specific pattern using the global commandg
.Another overlooked aspect is the
.exrc
file. Enabling it withset exrc
in your config allows for different setups based on different situations. For instance, when writing notes, I prefer to have line breaks on to make the text look nicer on the screen. In contrast, when writing code, I don’t require this option. I simply need to placeset linebreak
in the.exrc
file in the note-writing directory to adjust accordingly.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.
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 (
I don’t think I like vim or similar for the “productivity gain”. It just feels much more smooth of an experience when I don’t have to target, point at something visually and click all the time. Or move my hand to a 4 keys that are as far from my hands resting position as possible. I don’t believe I have saved much time. But I had a blast working with it and want to continue this serendipity experience for the rest of my time.
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”
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.
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. :)
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.
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.
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 contents
s
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: helix@programming.dev
- Move a line to a new position in the file/another file (takes a couple of seconds)
I don’t use VIM but I once tried and although it may be faster in the long run, You’re absolutely not productive when learning it and it made me give up.
That’s fair, but in a week you’re effective, and after a month everything else seems wrong - like typing with oven mitts on.
But I enjoyed learning vim. It was like learning the controls to a game that I get to play every day. Now ten years later, I’m still finding little tricks and optimisations. I’m still having fun learning vim.
If that doesn’t sound fun to you, then I get why it isn’t worth it, though.
I wish it worked better on non ANSI USA layouts. So many commands are just impossible to do on my keyboard. So I gave up quite quickly after I found that out.
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
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
.- 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 . . .
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