Skip to content(if available)orjump to list(if available)

Editing Code in Emacs

Editing Code in Emacs

39 comments

·November 23, 2025

dustfinger

My favorite way to move around in Emacs, and to move text around, is via avy-mode: https://github.com/abo-abo/avy. If you have not experienced avy-mode, give it a try, I think you will wonder how you ever got along without it.

Buttons840

I was excited for avy until I realized its purpose is only to move the cursor to a place visible on the screen. It does nothing a mouse can't do with one click.

(This is my understanding at least; I'm open to correction.)

I'm a lover of Vim bindings, and so I appreciate keyboard controls, but where Vim enables working with files and text in a general and powerful way, avy enables avoiding one click with the mouse. I don't use Vim to avoid the mouse, I use it so I can hack some Vim macros together when I'm editing text on a text-level. Vim (or Emacs) is an eternal tool that can do big things, avy just positions my cursor.

lvass

Definitely not it's purpose. Avy can be used to select a word, line, or region. One action is move to it. But it can also, in it's own words, copy, yank, zap to, transpose, teleport, kill, mark, ispell, org-refile, and custom actions.

https://karthinks.com/software/avy-can-do-anything/

Buttons840

I've bounced off that blog post in the past, because it makes it appear the first step to doing something in avy is to position all my files and "windows" (a "window" is an editing pane inside Emacs) in some clever way, and after I got all that setup, and the windows are all looking at just the right parts of the files, then I can move a paragraph from one window to another with just a few special keystrokes.

I feel like moving from a large monitor to a small monitor would limit the usefulness of avy; it's weird that the physical size of a monitor would limit a tool like this.

If I can only see 3 lines of text at a time (maybe an accessibility thing), the usefulness of Vim-bindings is not significantly reduced. Is the same true for avy?

Again, I'm willing to learn that I was wrong, but this is the specific issue that ended my enthusiasm for learning avy.

jlouis

It's really a selector or a filter. It's power comes from combining it with other tools.

dustfinger

Don't underestimate the advantage of being able to move the cursor anywhere in a few clicks without having to take your hands off the keyboard. It is much faster than a mouse. Also, you can save your elbows the pain of constantly reaching over for the mouse.

avy does more than just jump the cursor to a specific place. It also allows you search for, copy and move text round without needing to move your cursor to that text. It is extremely easy to use and very efficient.

skydhash

I have it installed and have the main commands bound to convenient keys. But I’m so used to moving via words, paragraphs and isearch that the only time I remember it is when targeting symbols.

globular-toast

I don't think this was the first package to use the tree idea, but `avy-goto-char-timer` is amazing and is new since the first time I tried it. After activating goto with a key press you type as many characters as you like to get where you want. Often you can get straight there if it's something unique, but if not then it goes to the tree. It's amazing how quick you get at typing "def" or something to get to a Python function definition, for example.

What I love about functionality like this is it's completely generic. It's just text. I don't need any lsp support to get me "go to def" or something. I can open a file in a language I've never seen before and use the exact same interface I'm used to to navigate around.

nine_k

In short: turn Emacs navigation into Vim-like navigation, make the editing modal, and thus make navigation hyper-efficient. (If you like the idea, I would suggest taking a look at evil-mode if you come from Vim, or god-mode and devil-mode if you already are used to Emacs.)

A few useful pieces of advice beside that, too. The workflow the author describes is not how I prefer to do things, but the author mentions a number of important capabilities to be aware of: operating at sexp level, subword motion, etc. Narrowing and folding, which I like to use, are not mentioned.

No mention of LSPs or compilers, but these are their own large topic.

rickstanley

Thanks for sharing. I've been off editor hopping for quite some time, nowadays I just use some pre-defined configuration like Doom Emacs, occasionally I try to build some environment, with AI help, from "scratch" for fun and curiosity.

I really like Emacs' flexibility + evil-mode and reactivity, recently I searched for something similar and found Lem: https://github.com/lem-project/lem, looks promising, I'll try it out and compare with Emacs when I have the chance and time.

OhMeadhbh

Meh. I'm not a fan of modal interfaces. But if it works for you, then knock yourself out. I appreciate the write-up here. I'll give it a try to see if I can see what the author is talking about. The overwhelming majority of code I write now is in snippets inside text documents (think Knuthian Literate Programming) so I don't know how that would work w/ the author's modal setup. But they went to the trouble of documenting it, and it seems sort of like what `vi` people are always yammering about. Seems a decent idea to try to understand it.

iLemming

> I'm not a fan of modal interfaces

I'm assuming you're using Emacs (otherwise why would you be commenting in this thread, right?). It's weird to hear that from an Emacs user - it's inherently a modal editor - keycords are modal, isearch is modal, repeat-mode is modal, transients are all modals with states. Evil-mode only adds some consistent "language" and structure to deal with modality, there's nothing much to it.

Idea of vim-navigation is actually pretty neat thing - absolutely beautiful, practical model. Its biggest problem is that it encapsulates some tacit knowledge - nobody can really explain the benefits of it to anyone until they try it for some time and it "clicks". I suppose just how learning to ride a bike may work differently for different people - it also takes different amount of time and effort. But once you figure it out - there's really no going back - no reason. It's very rare to meet people who've mastered it and then willingly stopped using it.

There's no conceptual difference in switching between navigation and insert modes in Vim and e.g. C-c C-c/C-d in Emacs - the only difference that you're in-between state more often, but once muscle memory trained, it becomes second nature - you don't even think about what mode you're actually in - it becomes very fluid and consistent flow state that allows you to very efficiently navigate and deal with text - with any kind of text - plain and structured.

Also, I find that mastering efficiency in Emacs using only vanilla keybindings is a bit harder than becoming a keyboard-maestro with the help of evil-mode or similar modal modes like meow. I've been working over a decade in various teams where people use Emacs, and evil-mode users typically figure out things much faster, while those sticking to native keybindings, don't even discover some great features of Emacs for years.

mystifyingpoi

I really like this, it's a bit hardcore, but for someone that really cares about efficiency (whether it is worth it or not - debatable), this is great.

Though I have one minor nit against one point, that I've seen basically in every similar article:

> This means no arrow keys and no mouse

I use Neovim daily, and there is no denying that 98% of the time, using mouse is less efficient than doing a fancy search or jump. But for the remaining 2%, it's provably true that mouse is better - like, selecting an arbitrary block of code (without {} or any keyword to hang on). So I always recommend leaving the mouse enabled. Just use it when it makes sense.

redpenguin101

> But for the remaining 2%, it's provably true that mouse is better

This is definitely true. The thing is that using the mouse is a habit, and until you break it, people find themselves instinctively using it in situations where it would be better to use the keyboard. So the 'hard' mouse disable is more of a 'going cold-turkey' type thing to try and break the habit. I agree that once it's broken it makes sense to relax this.

magackame

How using a mouse and incurring a context switch is better than just mashing j/k a couple of times in worst case scenario?

trelane

If you're moving in emacs using per-line/character commands, you're definitely not using emacs as efficiently as you could be.

So the distance in efficiency (and therefore efficacy) between mouse and keyboard is rather a gulf, once you've paid the cost of learning the extra emacs commands.

vinceguidry

When you're not editing lisp.

skydhash

v, then t/T or f/F if staying on the same line, j and k if it’s within a couple line, / or ? for anything else. With the repetition commands ./,/n/N if I do not land at the correct place.

eichin

Hmm, would be interesting to see a "race" between this and isearch; from the examples, it looks like this has an advantage only if you have lots of similar strings, so "the one you're looking at" vs. "typing more letters of the word" is an advantage? (externally timed, see The Humane Interface for details on how self-reporting doesn't actually work to measure this kind of thing)

tacker2000

You can also use a great vim “integration” in emacs by using doom emacs.

emil-lp

I've used Emacs for 20 years and I never learnt to navigate in a file except backwards and forwards search.

Is there still hope for me?

I think my biggest issue is that I am a slow coder and I never feel in a hurry.

redpenguin101

If your workflow feels comfortable there's really no need to change it in my opinion. The reason I do this is to avoid the frustrating feeling that I'm spending all my time moving around in the text file rather than actually making the program. It's less about speed and more about feeling good while programming.

brabel

You really only need a few shortcuts to feel comfortable. The ones in the basic tutorial are pretty much all I use, but I also enable god-mode to avoid having to keep Ctrl pressed as that hurts.

lvass

Just type C-h t (help-with-tutorial) and work your way through it.

final_aeon

In my opinion there's no reason to stick to the "old school" / classic emacs controls. They're archaic at this point.

I am an experienced emacs user and I still use CUA mode, arrow keys, and I wrote a package which completely overhauls built-in "word jumping" commands (called bbww on melpa.)

You don't need to worry about upholding traditional emacs orthodoxy

nothrabannosir

Disagree with this just because it makes everything else easier. The more you stick to common key bindings, the more intuitive various packages will be. Eg navigating lines vs blocks in a magit diff block is C-n and N respectively. Copying a full hash is M-w. All these bindings are intuitive “overlays” on conventional bindings.

Emacs shines when packages combine to form a whole greater than the sum of its parts. Changing basic key bindings is the quickest way to vitiate that symbiosis.

Unfortunately.

And while they may be old school, traditional, and orthodox, they are by no means idiosyncratic. They’re widely supported: readline , bash, everywhere on macos, even modern browsers. Eg you can actually paste in bash: try killing something with C-w or C-k, and paste it back using C-y. Or transpose arguments using C-M-t. Navigate suggestions in Firefox using C-n and C-p. Bash even supports undo using C-/.

All to say: learning emacs movement keys pays off.

v9v

Firefox opens a new window when I press C-n. Is this a setting that you have to enable?

brabel

The op is probably on Mac where emacs movements use Ctrl but FF and other apps use Cmd key, so they always work as there’s no conflict.

jmclnx

Seems to be an intro to a kind of but lite weight vi mode. I tend to like the regular mode in Emacs.

Maybe a bit OT, but I think I saw here a week or more ago a post about magit, I am toying with using it, but seems to be a rather big package. Plus I wonder why dash is needed:

https://emacsdocs.org/docs/magit/Installing-from-the-Git-Rep...

In anycase to avoid downloading additional packages I may use Melpa

https://emacsdocs.org/docs/magit/Installing-from-Melpa

user333311

[flagged]

user333311

[flagged]

user333311

[flagged]

user333311

[flagged]

user333311

[flagged]

user333311

[flagged]