this post was submitted on 17 Jul 2024
82 points (97.7% liked)

Ask Experienced Devs

1232 readers
1 users here now

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

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.

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 33 points 4 months ago (6 children)

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. :)

[–] [email protected] 7 points 4 months ago (1 children)

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.

[–] [email protected] 7 points 4 months ago (1 children)

I had no idea DF had macros but it makes so much sense.

[–] [email protected] 3 points 4 months ago (1 children)

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

load more comments (1 replies)
[–] [email protected] 3 points 4 months ago

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.

load more comments (4 replies)
[–] [email protected] 21 points 4 months ago (3 children)

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.

[–] [email protected] 4 points 4 months ago (1 children)

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

load more comments (1 replies)
load more comments (2 replies)
[–] [email protected] 17 points 4 months ago (1 children)

I am logged into various servers via ssh constantly and nano or vim (or at least vi) are installed pretty much by default everywhere.

[–] [email protected] 6 points 4 months ago (2 children)

That doesn't explain a preference for vi(m) over nano, tho

[–] [email protected] 4 points 4 months ago* (last edited 4 months ago) (1 children)

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.

[–] [email protected] 2 points 4 months ago (1 children)

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

[–] [email protected] 2 points 4 months ago* (last edited 4 months ago) (1 children)

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!

load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 15 points 4 months ago

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"

[–] [email protected] 11 points 4 months ago* (last edited 4 months ago) (2 children)

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.

[–] [email protected] 6 points 4 months ago (3 children)

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?

[–] [email protected] 6 points 4 months ago

So far as I'm aware, yes. As a C engineer, it's also useful for jumping from #ifdef to #endif .

[–] [email protected] 4 points 4 months ago

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.

[–] [email protected] 2 points 4 months ago

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.

load more comments (1 replies)
[–] [email protected] 10 points 4 months ago* (last edited 4 months ago)

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.

[–] [email protected] 10 points 4 months ago

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.

[–] [email protected] 10 points 4 months ago

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.
[–] [email protected] 9 points 4 months ago (9 children)

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
load more comments (9 replies)
[–] [email protected] 9 points 4 months ago* (last edited 4 months ago)

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:

  1. Move a line to a new position in the file/another file (takes a couple of seconds)
    1. x then d to select a line (pressing N times will select N lines) and delete it (delete will also copy to the clipboard)
    2. navigate the cursor to the new location
    3. p to paste in a new
  2. Navigating around a file:
    1. jumping to a function/class definition by pressing g then d when on a function/class usage.
    2. getting a list and navigating to class/function calls when the cursor is on a class/function definition by pressing g then r.
  3. 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:
    1. % to select the entire files contents
    2. s to search
    3. typed "FROM "
    4. pressed enter to create cursor at all locations matching the search
    5. v then g then l to select the rest of the line
    6. space+y to copy to the system clipboard.
    7. paste into a document where I needed to list the tables
  4. 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]

[–] [email protected] 8 points 4 months ago* (last edited 4 months ago) (1 children)

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 the v command gives me line numbers to pass to git 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 the open 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.

[–] [email protected] 5 points 4 months ago

And here I am proud that I can open a file, save it, make edits, jump to the beginning/end, and quit it. 😅

[–] [email protected] 8 points 4 months ago* (last edited 4 months ago)

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.

[–] [email protected] 7 points 4 months ago

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.

[–] [email protected] 7 points 4 months ago (3 children)

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.

load more comments (3 replies)
[–] [email protected] 6 points 4 months ago

I work on many different systems, some ancient and some embedded, some both. Vim and friends are ubiquitous. It’s a tool I’ve learned to use effectively by necessity, because other editors weren’t always available.

As an example, many routers don’t offer a graphical environment. There is no option to use something like Visual Studio or notepad++ without shuffling files around.

[–] [email protected] 6 points 4 months ago

Not to say that I think learning to edit Vim-style is worthwhile, but I think using Macros can be quite fun to do.

Recording a sequence of operations and then repeating it multiple times can potentially save a lot of editing time.

[–] [email protected] 4 points 4 months ago

Stockholm syndrome

[–] [email protected] 4 points 4 months ago (1 children)

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.

[–] [email protected] 7 points 4 months ago (1 children)

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.

[–] [email protected] 3 points 4 months ago

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.

[–] [email protected] 4 points 4 months ago (1 children)

I wouldn't consider myself a power user if vim or the bindings I don't normally use the markers or anything. However, I will spend a lot of time and effort to get just a small set of basic commands into my ide.

I like my hands on my keyboard and vim bindings allows super easy common things like ~ for capitalization of a single character. 'gUw' for uppercasing a word. 'dd' is much better to delete a line; than highlighting and deleting with a mouse. The most bad ass things I think it does incredibly well, is grabbing text or changing text between () or {} symbols. A simple 3 key command grabs the text between the symbol, deletes it, puts you in edit mode. Screw it up esc-u.

Another cool thing I use is vim clipboard and the system OS clip board in tandem.

[–] [email protected] 3 points 4 months ago (1 children)

you can delete a line in most ides by having a cursor in the line and pressing ctrl+x (with the side effect of putting it in the clipboard)

load more comments (1 replies)
[–] [email protected] 4 points 4 months ago* (last edited 4 months ago)

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 type ul, vim will automatically expand it to s/\<./\u&/g for you.

Additionally, the map command can save even more time, but IMO the ab command offers more control for handling various cases. In my example, you can use ul to only capitalize the lines that have a specific pattern using the global command g.

Another overlooked aspect is the .exrc file. Enabling it with set 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 place set linebreak in the .exrc file in the note-writing directory to adjust accordingly.

[–] [email protected] 4 points 4 months ago* (last edited 4 months ago)

and similars

mg (minimal emacs clone, lighter than nvi) and ed user here, minimal editors integrate well into unix environments. I view IDEs as providing what is missing for people who haven't learned their OS tooling (or their tooling sucks/doesn't exist). I have no need for a heavier editor because I can already do everything I need to and more with shell suspension & job control, find, and regular expression tools (grep, sed, awk, ed), and building similar capabilities into a huge IDE prevents me from having common tooling when working within other parts of my system, and uses up my limited muscle-memory for learning tools that are largely inferior and poorly documented compared to the standardized portable tooling that works almost everywhere.

[–] [email protected] 3 points 4 months ago

I actually only noticed this the other day (I took a hiatus from doing a lot of Linux work for >5y), but it resumes editing a long doc at the point where I was when I last exited, saving me from scrolling again.

[–] [email protected] 3 points 4 months ago* (last edited 4 months ago)

I spend most of my time thinking, not writing code. I really don't care all that much about time saving, but I do concede that not taking my fingers off the home row feels really great. Other editors, even this very text input I'm writing my comment in right now, feel clunky in comparison.

The most important part to me, however, is how customizable it is. I'm not just using (neo)vim, I'm making and using my own personal development environment. Almost every aspect, be it visual, keybinding, system integration or behavior, is changed as I go to suit my needs above all else. I think the only way to go even further with this would be switching to Emacs :^) lisp machines are no joke.

It's not necessarily mechanically faster—though it absolutely can be: sometimes I get my editor state to where I wanted so naturally and so quickly that I actually pause for a moment after to ponder, wait, how the hell did I do that?—but darn do I like spending time in it, and it just keeps getting better. In a way, that actually makes me more productive: I'm a happier dev.

In the end, it's all about you. If you are at your best in vscode or sublime or whatever, keep at it. My only suggestion is: if you're willing to put in the time and effort, consider trying to make whatever you use truly yours.

[–] [email protected] 3 points 4 months ago

Sysadmin rather than dev here, but magit was what converted me to emacs. And then, at some point, it clicked that the whole shell uses the same (where applicable) shortcuts as emacs. Or, more likely, the other way around. Anyway, point being - what I learnt in emacs, I could reuse on all the hosts I ssh into.

On top of that - basic navigation in tmux also uses the same shortcuts. Win-win-win :)

[–] [email protected] 3 points 4 months ago
  • The motions exist everywhere. Almost every editor has at least a vim motions plugin.
  • You can navigate in your file without having to move your hand (to the mouse or the arrow keys)
  • Vim is aware of the text you are editing. You can delete/change text between/up to quotes, parenthesis, etc
  • You can program Neovim to do whatever you want. This means you can optimize it exactly for your workflow
[–] [email protected] 3 points 4 months ago

I'm probably the minority here, but I don't use neovim for (time) efficiency. I use it for customization, hence minimalism, interoperability with other tools and less complex key bindings.

I do realize the irony of the last point. Sure, you need to learn basic navigation first, but past that the wizardry is much easier to learn than in other editors/IDEs. I do however not believe that wizardry is impossible in other editors/IDEs, at least most of the usual stuff.

[–] [email protected] 2 points 4 months ago

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.

[–] [email protected] 2 points 4 months ago

The keybindings, the plugins, the general versatility of neo/vi/m. Can't really say i use anything specific that maybe Notepad++ wouldn't do, except that vim works via SSH.

load more comments
view more: next ›