Ask HN: How to become good at Emacs/Vim?

42 points by mudrockbestgirl ↗ HN
I've tried switching from IDEs like VSCode to Emacs (with evil mode) a few times now, but I always gave up after a while because my productivity decreases. Even after 1-2 weeks it's still not close to what it was with VScode. That's frustrating. But when I watch proficient people using these editors I'm always amazed at what they can do, and they appear more productive than I am with VSCode. So with enough effort it should be a worthwhile investment.

I think my problem is the lack of a structured guide/tutorial focused on real-world project usage. I can do all basic operations, but I'm probably doing them in an inefficient way, which ends up being slower than a GUI. But I don't know what I don't know, so I don't know what commands and keybindings I should use instead or what my options are.

How did you become good at using these editors? Just using them doesn't really work because by myself I'd never discover most of the features and keybindings.

83 comments

[ 3.8 ms ] story [ 147 ms ] thread
I think what I did was just force myself to use it and if there was something in particular I wanted to do I would look it up, or if there was something that I was doing repeatedly I would try to find how to do it in the lowest number of keystrokes.

After I got the basic movements down (doing vimtutor if I needed refresher), then I would watch videos on youtube of peoples favourite keybinds, or lesser known keybinds. A lot of times this would open up a lot of things I didn't realize was possible.

Eventually I started to understand the vim "language", and things became natural to the point where I don't even really think about the keybinds I'm using, it just happens.

It was definitely a struggle at first though. If I could go back and be a TA again for intro to programming labs I would have found a way to give people extra credit for learning vim. The best time to start putting in the work is now, you'll thank yourself later.

If you program in C, google "Ctags" and the associated keybinds and vim command line argument (-t). Most useful utility for me personally.

This is similar to my experience. I forced myself to use vim on non-coding text files first. Just the basics of vimtutor. Only later, after learning to organize my vimrc configs, and adding useful plugins, did I use vim for coding.
When I wrists started hurting after a few years of professional programming, I became motivated to learn him.

I used vimtutor on Mac to get started.

Then I also tried my hands at a few vimgolfs and then tried to understand the winning answers.

There’s a lot of YouTube tutorials now too.

I made the switch to vim a few years ago. You'll want to start with learning the keybindings. Every major IDE and editor out there has a "vim mode" and an "emacs mode" so pick one you like and enable it. Whenever you need to move more quickly just switch back to your usual keybindings and get it done. Once you have the keybindings memorized, try to use them everywhere. There are browser plugins like vimium that let you navigate with vim keybindings for example.

It gets a bit weirder from there. If you pick vim for example theres a whole lot of customization rabbit holes you can go down. My advice is to find some sensible defaults and layer in stuff as you need it from there. vim-sensible[0] is a good start.

Good luck!

[0] - https://github.com/tpope/vim-sensible

I dabbled with neovim on and off for a while - kind of following the same logic as you, wanting to be like many people I saw on Youtube. It never really worked since I was really comfortable with my existing workflow - vscode + iterm and "swiping" between screens on macOS. I was super-fast with the Macbook trackpad with its sensitivity turned up to the max.

It finally clicked when I started a job where I had to use a windows laptop with a linux VM as my primary computer. I found that using vscode either within the VM or over "Remote-SSH" from windows was severely cramping my productivity. So I switched to NeoVim+Tmux cold turkey (SSHing into VM using "Windows Terminal"). I set up some shortcuts that made sense for me somewhat from vscode (e.g. Alt+<number> for switching "tabs", alt+hjkl or alt+arrow keys to switch between tmux panes etc.). Within a couple of weeks I was back to my old level of productivity.

My usual setup has neovim on the left and a terminal in the right pane. Adding more panes vertically or horizontally is super easy as well. This may not be the most optimal setup, and there are still a few pain points from time to time - particularly with the LSP/"intellisense" stuff. But it works for me.

Oh and when I am coding on my MacBook Pro at home, I still prefer to use vscode + iTerm.

Some resources that helped:

"Practical Vim" by Drew Neil. I didn't read it cover to cover but I have scanned through it enough to pick up the important stuff.

https://www.youtube.com/watch?v=iF4RvQq6yU0

https://www.youtube.com/watch?v=GUptUQGrJLE

https://www.youtube.com/watch?v=wlR5gYd6um0

Pair programming is a great way to learn. Just watch what others do and pick up tricks.

Also, check out fugitive by tim pope. It’s a git plugin for vim that’s changed my life. It’ll open your files with the old version in one split and the new version in another. You can then pull in changes chunk by chunk. It’s amazing.

Honestly I never devoted myself to trying emacs, but I learned vim the same way you're being inspired. Seeing other people, asking "Hey how'd you do that?" and then going from there

Taking those and making a point to work them into muscle memory has been key.

Eventually I found that I was familiar with the core modifiers (and figuring out new things) without any real effort. I knew that shift + something would do a specific thing

It takes knowing about the thing... and using it so much that you don't even have to think about it

The cases where I'm a little bit beyond what one can reasonably handle with sed is when I get to flex the vim muscles. Things like visual mode, finding/replacing, etc.

I found this game very helpful for solidifying my vim skills, and I would highly recommend it! https://vim-adventures.com/

It helped me to be a better vimmer, and it was fun too!

This is great!

I'm terrible at it.

But, this is great!

I use Helix (very much like vim) and a lot of applications that use keyboard focused vim-like UX, and the only advice I have is to keep using it. It's like playing an instrument, eventually your mind just makes your will a reality through your fingertips, you don't even have to think about it, but until then, you do.

Get the basic operations down, keep a cheatsheet handy, anything you'd want to do that you think might have a key combo look it up the minute you need it. Take an interest in it for it's own sake every now and then.

I recommend having an explicit plan for how you intend to use Emacs or Vim.

I've been using Emacs for five years. When I got started, I also started journaling daily with Org-mode. That gave me a reason to open Emacs every day.

I think it was just sheer repetition. I had to switch back to VSCode a few times a week to be productive on a time crunch but other than that I just had the mouse enabled and scrolling and tried to not use the mouse as much as possible. I would often tweak my config to find more intuitive key bindings that I could remember.

My view is that it’s just like learning a language (albeit easier) and you just need to give yourself space and time. Structure is good, but can also be overwhelming in the sense that you try to min max like vim pros from youtube. I just found that I would take it in digestible pieces and build on that. First it was jumping lines, then changing inside or around, and so on and so on.

I use emacs with evil and been using it for over a decade now. However, I use VSCode for web development and Rider for game development as the integrations are superior with vim extensions for those IDEs. What you are looking for is a set of principles that make theses editors better. You can take baby steps towards it and 1 - 2 weeks is very limited time if you want to change your editing style (It's like learning a new language).

1. Modal editing (VIM / Evil): Install vim extension pack[1][2][3] for VSCode. This should give a good starter pack.

2. Practice:

   - Disable the arrow keys using keymapping in VSCode or with a keyboard customization (s/w or h/w).
   - Disconnect the mouse
   - Practice long writing / code editing sessions where your productivity doesn't matter. You are learning.
   - Start with simple navigation (hjkl, go to line)
   - Use numeric prefixes
   - Begin using text manipulation commands (yi" or di> for  example)
   - Use normal mode keys for window navigation (spc + w + h for example)

   Once you get comfortable with this you should already see a decent leap in comfort/experience and almost zero mouse usage.
3. Next install emacs with a configuration repository[4]. Most of your practice in VSCode vim should apply almost directly.

4. With emacs, you have a vast operating surface. You can choose to use it just as your editor or you can use it as an operating system: email, calendering, note taking, calculations, twitter, rss, text based browser, file manager, http request playground etc. Org mode is essential emacs experience. You can add the rest of them very slowly

[1]: vscodevim.vim: https://marketplace.visualstudio.com/items?itemName=vscodevi...

[2]: vspacecode.vspacecode: https://marketplace.visualstudio.com/items?itemName=VSpaceCo...

[3]: vspacecode.whichkey: https://marketplace.visualstudio.com/items?itemName=VSpaceCo...

[4]: doom emacs: https://github.com/doomemacs/doomemacs

This is good advice. The "Zaiste Programming" [1] is a nice intro to Doom Emacs.

I'd say using Vim Keybindings in VSCode, being able to use Vim when on some remote machine and using Doom Emacs with its included packages is a good approach for improving without investing too much time.

[1] https://youtube.com/playlist?list=PLhXZp00uXBk4np17N39WvB80z...

What converted me to vim was understanding that the commands are composable. For instance: the d key is used to delete, and de deletes to the end of word. But it doesn't end there. Typing t followed by a character goes to the next instance of the character in the current line, so if you type dt followed by that character it will delete everything just before it. If you play around with different commands, and practise navigating through a file this way, it's only one step to editing a file in the same way you navigate through it.
If you merely want to internalize the vi movement keys, play a round of hunt (part of the bsdgames package on Linux systems) with some friends or colleagues on your local network.

Vscode also has vim keybindings available.

A couple of suggestions (in no particular order, and from an ex-Emacs/Xcode/Jetbrains/VSCode and current nvim user):

1. Don't. There's no need to 'switch'. There are marvellously 'productive' developers using every editor under the sun, and neither the quality nor quantity of their work is strongly related to their choice of editor. There are world-class developers who do everything in a vanilla Sublime Text. Others who have a fully tricked-out emacs who dream in org mode. Some use a mouse in one hand and do keyboard shortcuts in the other. None of it matters much. Ignore antiempirical self-attestations to the contrary - they're entertaining but informationally worthless. If self-attestations were relevant, then everything (from quack medicines to cult healing methods to levitation) would be true, because everything has more utterly self-convinced dataless self-attestations than you could absorb in all a bodhisattva's recalled lifetimes. [all scare quotes intended].

2. Do. Emacs and vim/nvim are great and will serve you well if one matches your preferences. Pick one using your preferred criteria, and commit to it for a period. Your 1-2 weeks just isn't enough - I'd say 2 months at least. Put that commitment in your calendar. If it slows you down too much for practicality to start with, limit its use (to an an hour a day, or to a side project), but stick with it for the full period regardless. In the first week or two, go through enough basic tutorials to be able to do essential editing with their basic keybindings without plugins. With reasonable fluency established, just keep a note in which to jot down what's missing compared to your IDE, and pick them off, one-by-one, over time. Sort the list once a week to keep it fresh, and just pick the next item to configure/learn. Get fluent with each new item before moving on to the next.

Reinforcing #1: It's amazing how productive you can be if you're creating things instead of endlessly trying, configuring, and comparing editors.
Whether you call it over-engineering or procrastination, customizing an editor is a delicious waste of time.
I'm certainly not knocking it. I have enjoyed it in the past, particularly with emacs. But it's an activity which some enjoy for its own sake and some don't. It's just not a necessary condition for becoming a 'productive' developer. Those who do enjoy it to the point of writing some of the great open source plugins available, do the rest of us a terrific service.
Just as you, I certainly don't relate productivity and editor config.

My co fig now is really simple: I rely on other's work: I find powerline-10k + LunarVim to make for a more than good enough terminal environment.

I mean, you're going to be programming for the rest of your life, right? I put a bunch of time into customizing vim... god, I think it was 15 years ago? Whenever this comes up, people make it sound like you are somehow going to be doing that every single day for the rest of your life or something... and then, awkwardly, I tend to see them screwing around constantly with some new IDE-of-the-week that crashes constantly and slows them down at every turn gloating about how they "saved time" by not spending a small amount of time forever ago to figure out what the hell they actually wanted :/.
> I tend to see them screwing around constantly with some new IDE-of-the-week that crashes constantly and slows them down at every turn gloating about how they "saved time" by not spending a small amount of time forever ago to figure out what the hell they actually wanted

This is just as much a caricature as the one you're objecting to. People do good work using all of the available tools. Some use more than one! There are people who like both emacs and IntelliJ! We really don't have to tribalize over every little choice people make.

I'm totally cool if you want to use IntelliJ. I'm somewhat less cool if you are telling me how awesome IntelliJ is this year after trying to get me to use Eclipse on your last project but are now looking at VSCode as an alternative because you are sick of switching between this stack and Xcode and PyCharm after you stopped just trying to use Sublime for everything... and I certainly lose all sympathy when these same people actively defend this insanity by saying they don't think it makes sense to "waste time" "over-engineering" their text editor setup.

Like, if you want to tell me "I use nothing but notepad, and I'm a god at it" I'm going to be "holy hell yeah, I want to feast my eyes upon this marvel"... but, first off, I'm betting at that point you are going to have gotten really good at using notepad, along with all of the little warts of how it interacts with Explorer... and second off, the people who are coming out always to bash on the people who bother to learn and optimize their tools to prepare for a lifetime of software development generally aren't people who simply chose a different tool.

And then there's the majority of devs, like me, who did not spend months forcing themselves to actually make vim/emacs into an IDE and, at the same time, who suffer from no negative effects with one of those "IDE-of-the-week" (JFYI, that's not a thing). Intellij, Pycharm, and VSCode are all stable and fast. I don't think I've had neither of those crash on me in the past three years.

You're laying out a false dichotomy.

I'm not laying out a false dichotomy, I'm laying down two stacked arguments, and you are welcome to disagree or agree with each of them separately (and it isn't even clear to me that you disagree with the first one--about how that supposedly-large cost is amortized over a lifetime of development--as you seem to have been so distracted by the second).

(And yes, IDE-of-the-week is definitely a thing. The shear number of different one-off text editors and IDEs for various language stacks I've seen people try to get me to use over the past 25 years is staggering.)

I agree with you, and that's one of the reasons I wanted to try switching away from VSCode. It has been pretty good, but sometimes it's quite slow and does who-knows-what in the background, and then I check my CPU and memory usage and yep, it's eating 32Gi of ram. For what? Editing text? Compiling unncessary stuff when I don't want to compile? Then I restart it, like the good old Windows 95 days, and it's all good again. Probably something with the LSPs, but who knows. The point is, it's a lot of magic in those plugins, and I don't like magic because at some point the extra cost of debugging the magic is not worth it. I'd rather have a system that properly surfaces the complexity even if that means it takes longer to learn.
There's churn in the Vim world too. Plugins and plugin managers change. For example, with Neovim, Packer and Mason are apparently what's good to use now, and Mason literally came out 3 months ago. I guess if you don't use many plugins (and aren't trying to make Vim a full fledged IDE) then it's fine, but if you are, there's a lot of churn to go through.
What I've found over the last 2 jobs/3 laptops is that I'm quite comfortable starting working and being productive with vi, and then over time I start setting 'nocompatible' when I need some feature from Vim, and then some weeks in add a vimrc/init.vim.
There's approximately zero churn in Emacs. Moved up four major versions a few years ago and I think I had to regigger one line in my config, out of a config of over 2000 lines.
Why did you switch to nvim from emacs?
Well I don't use the 'switch' term - cliches cloud thought, and I've only at some points in my programming life used a single editor for everything, and for me it's been more a pragmatic journey than anxious 'switch'. Also I don't always work as a programmer - so sometimes, returning to the field after a few years away, I start afresh with new tools.

I did once use emacs extensively. I stopped because at the time I moved almost exclusively into iOS work, which mostly meant XCode. I disliked that enough that I tried and enjoyed the only real alternative - Jetbrains' AppCode. So then when I moved on again to non-iOS work I had fallen for the Jetbrains approach, so mostly used IntelliJ. I did have one small spell again with emacs, when writing some clojure (for which it's a good fit), but found it overwrought for my more recent taste.

But all this time I had used vim for small on-off and in-terminal edits, and mostly used vim keybinds in other editors. Anyway, via a couple more shifts (including using VSCode for a while), the advent of LSP and treesitter really makes neovim close enough to matching IntelliJ's features for my purposes. I just like neovim and its ecosystem, and it works well enough for me. But so would emacs or IntelliJ or VSCode or vim or emacs. I probably make several choices a week far more significant than what text editor to use.

I can only confirm this. Only change if you feel real need and progress with another tool. Learning a new IDE takes time. I've been using Emacs for over 20 years and I'm still discovering new features. The goal is not to become an Emacs superhero but to gain confidence and efficiency. Some features may seem useless to you until you have a suitable use for them. For example, for a long time I ignored Emacs' natural keyboard shortcuts for moving the cursor, preferring to use the arrow keys until I felt the need to use them and felt that I was doing my job more efficiently.

I tried VS Code as well but did not enjoy the experience. Back to Emacs with which I have too many habits and a long love affair. I also use Atom a bit for some tasks but it's more rare.

You also don't need to configure your IDE from the start. It's a bit of a thankless task but not that difficult or incomprehensible. It took me a few years before I started messing with my Emacs configuration. The advantage is that it is portable and I can find my environment on any computer just by copying a folder.

Just stick with it. Both editors have tutorials built in. If you’re not getting anywhere with it in a month or two and enjoying the transition then stop. VSCode is just fine.
>How did you become good at using these editors? Just using them doesn't really work because by myself I'd never discover most of the features and keybindings.

I used Vim (GVim to be specific) as part of my job in a semiconductor industry. Everybody in our team used it and we'd help each other. My recollection is not 100% sure, but I think nobody knew how awesome user manuals were (start with vimtutor and then go through `:h usr_toc.txt` https://vimhelp.org/usr_toc.txt.html a few times).

I've also collected a list of Vim resources here: https://learnbyexample.github.io/curated_resources/vim.html

For Emacs, check out https://www.emacswiki.org/emacs/SiteMap

A document with notes on the software tool https://westurner.github.io/tools/#vim :

- [x] SpaceVim, SpaceMacs

- [ ] awesome-vim > Learning Vim https://github.com/akrawchyk/awesome-vim#learning-vim

- [x] https://learnxinyminutes.com/docs/vim/

- [ ]

  :help help
  :h help
  :h usr_toc.txt
  :help noautoindent
- [ ] https://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/Mod... :

  :help Command-line-mode
  :help Ex-mode
- [ ] my dotvim with regexable comments: https://github.com/westurner/dotvim/blob/master/vimrc
Read the book Practical Vim. It’s not worth using Vim without it. Don’t trust Vim users who haven’t read it, unless they’re Tim Pope.

At least 75% of Vim users I’ve encountered don’t know Vim well enough to justify their using it. Most users stop at vimtutor and are left without the knowledge of the terrible nightmare of Vim knowledge you need to get close to useful editing.

Also keep in mind Vim is a text editor, not a code editor. IDEs are incredibly more powerful than Vim for code editing.

VSCode/IDEs and Vim need not be mutually exclusive. I tend to rely on vim emulation within my vscode, chrome and in other applications. Usually, all I need are the basic vim modalities with the nicer amenities provided by modern editors.
The well known “Vim mode paradox”: if you like the Vim mode provided by another editor, it means you don’t know Vim well enough to justify using Vim nor Vim mode. Vim modes don’t approach even 10% of the Vim features you need to reach the bare minimum of efficient editing.
> Vim modes don’t approach even 10% of the Vim features you need to reach the bare minimum of efficient editing.

What's the 90% that's not available in VSCode with the Vim extension?

Trying it out again now, this isn't Vim, it's an entirely different product. It doesn't have command editing mode q: nor q/. It doesn't use Vim's regexes and doesn't support \v (which is probably good, Vim's regexes are very bad, but it's still not Vim). There is limited support for windowing, I mean not really support at all, because this is a better windowing system that Vim (:h CTRL-W_J). Although I am surprised `ctrl-w +` works. Of course no support for Vim plugins like surround.vim. Vim out of the box is not a usable editor. H and L seem to be busted and scroll the screen.
Still trying it, no `:norm`, no `:g`, multiple cursors in VSCode are so much more powerful than this, and already do 90% of what you want to do in Vim in the first place.
What is the 90% that is missing in Evil?
That's fine, my focus is on mastering software engineering (rather than text editing) :p
One feature at a time. I didn't use M-y to cycle through my kill ring in emacs until 2022 after a decade of use!
> Even after 1-2 weeks it's still not close to what it was with VScode. That's frustrating.

Emacs is a lifelong journey. Expecting to be great at it in a few weeks is very unrealistic.

To answer your question I spent a week reading a book on Emacs and forced myself to figure out any task rather than reaching for another editor. This was for the editing part.

For the IDE, my default is to use another IDE and as time permits I try to replicate features in Emacs - but I never have an obsession to completely replace an IDE.

Watching the system crafters YouTube channel will teach you about a lot of cool features and packages. Highly recommend it.

Monitoring the Emacs subreddit is a good source of inspiration as well.

Ultimately people use Emacs because they enjoy it - not because it is a superior IDE. If you're frustrated with Emacs, consider that it's not for you.

I started by using vimium so that I'd navigate the browser with vim key-bindings, since I spend so much time in there. https://vimium.github.io/

Then after that, I just started using vim and keeping with it. To me, the biggest hurdle was switching between modes. Hitting esc was too far for me. So I found some post that helped me configure vim that bound "ii" to command mode. So to switch between insert mode and command mode was just "i" and "ii".

Nowadays, I use the escape key. It's second nature by now. But I'm still trying to make navigation with 't' and 'f' more natural. I think it's just persisting, honestly.

Why?

No, seriously, why do you think you have to switch if you are productive with VSCode?

I used to be all in with Vim and then Emacs many years ago. I can manage pretty well with both to this day. But I moved onto VSCode a few years ago and… it’s very nice. It just works out of the box. I have tried to move back to Emacs for example, but the lack of trivial and good remoting features and the lack of great LSP integration are hard to overcome.

Nowadays I still use vim for quick or repetitive edits (learn how to record and replay macros; they are a game changer), but otherwise spend all of my time in VSCode with its Vim mode enabled.

And to be fair, I only use the Vim mode in VSCode because I moved from macOS to Windows and I could not stand the Windows native shortcuts.

I remember I found setting up remote connections for VSCode harder than emacs.

isnt emacs just M-x ssh … and ure done?

Just use it. When you get stuck Google how do something. Also join r/vim or something to have a community to get inspiration from.