12 ms·
Editing Code in Emacs
- user333311 10mo ago[flagged]
- user333311 10mo ago[flagged]
- user333311 10mo ago[flagged]
- user333311 10mo ago[flagged]
- user333311 10mo ago[flagged]
- user333311 10mo ago[flagged]
- user333311 10mo ago[flagged]
- user333311 10mo ago[flagged]
- user333311 10mo ago[flagged]
- nine_k 10mo agoIn 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.
- emil-lp 10mo agoI'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.
- lvass 10mo agoJust type C-h t (help-with-tutorial) and work your way through it.
- redpenguin101 10mo agoIf 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 10mo agoYou 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.
- final_aeon 10mo agoIn 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 10mo agoDisagree 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 10mo agoFirefox opens a new window when I press C-n. Is this a setting that you have to enable?
- jmclnx 10mo agoSeems 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-Repository 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 https://emacsdocs.org/docs/magit/Installing-from-Melpa
- OhMeadhbh 10mo agoMeh. 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 10mo ago> 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.
- 10mo ago
- mystifyingpoi 10mo agoI 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.
- magackame 10mo agoHow using a mouse and incurring a context switch is better than just mashing j/k a couple of times in worst case scenario?
- vinceguidry 10mo agoWhen you're not editing lisp.
- skydhash 10mo agov, 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.
- trelane 10mo agoIf 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.
- redpenguin101 10mo ago> 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.
- dustfinger 10mo agoMy favorite way to move around in Emacs, and to move text around, is via avy-mode: https://github.com/abo-abo/avy 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.
- globular-toast 10mo agoI 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.
- skydhash 10mo agoI 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.
- mark_h 10mo agoAbout my only usage is to augment my isearch. I frequently use isearch to navigate to a place on screen, but sometimes there are so many matches it would take a lot of repeated "C-s" to get there. I have "C-'" bound to avy-isearch (from within isearch), which instantly turns that into one or two keystrokes to filter down. (or I could pick up the mouse, I know, but that's not why we're here)
- eviks 10mo agoYes, that's a "paradigm shift" in behavior, so you need to force yourself to use it for some time to evaluate it properly
- eichin 10mo agoHmm, 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)
- rickstanley 10mo agoThanks 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 https://github.com/lem-project/lem, looks promising, I'll try it out and compare with Emacs when I have the chance and time.
- tacker2000 10mo agoYou can also use a great vim “integration” in emacs by using doom emacs.
- floathub 10mo agoI used Emacs for several years before I discovered "project" (it's built in). If you're navigating dired trees or similar to find files or grep for strings in groups of files, this is like magic: C-x p f (find any file in the current "project", e.g. git repo) C-x p v (grep the whole project super fast) It's embarrassing how long it took me to realize it was there all along. :-)
- JanisErdmanis 10mo agoI am consistently using `m` for marking relevant files/directories in the dired mode and then `A` to find a regex among all included files. It does not seem that I miss anything by not relying on such a project approach.
- eviks 10mo ago> A note on defaults. A problem with customised setups is that they mean you can’t pick up your friend’s Emacs setup and use it > can be mitigated by sticking with the ‘language’ of the system No? You're still going to be mistaken a lot of the time to the point of making your experience unpleasant. And how often do you really pick up your friend's Emacs setup for this to outweigh the other 99% of your time? > Emacs has pretty clear (if arguably not very good) conventions Indeed, so it's a waste of productivity and ergonomics to rely on it
- Conscat 10mo agoIf I couldn't give Emacs incredibly specialized behavior, I wouldn't even use it.
- mark_l_watson 10mo agoI am going to sound like a mouse-using Luddite but I configure .emacs with a one line addition to allow a mouse click to reposition the cursor and fast scrolling works also. I have been using Emacs for 40 years, and decades ago, before ground based fiber, it was a 2 satellite bounce ping time between my office in San Diego and the 38 data collection sites around the world for a DARPA project and the mouse click in Emacs saved a ton of time. In the present time, I use Emacs on remote servers and local editing, either using my iPad Pro, and Apple Mouse, and a Studio monitor, or a MacBook - on both environments I find occasional mouse clicks or fast scrolls using mouse or Apple trackpad still saves time even in zero latency environments.
- quotemstr 10mo agoTramp isn't an option? I know people say it's slow (it is) and synchronous (yes, it is) but I'd rather pay a high latency cost only upon saving than a moderate one ALL THE TIME.
- mark_l_watson 10mo agoIt is an option. You are talking with an old man (me!) and I just usually like simple Emacs setups, also using mosh and ssh and tmux.
- AlfredBarnes 10mo agoHow do you go about editing via ipad, I'm just getting into this whole world, and am finding it difficult to figure out a system.
- mark_l_watson 10mo agoI use an app like Terminus or Prompt to access a remote server. I have a keyboard and a mouse for my iPad Pro.
- iLemming 10mo ago> fast scrolling works also Grokking efficient navigation within Emacs buffers completely removed the necessity for scrolling for me - most of the time it's all about finding specific content - using consult-line, imenu, various jump methods, ex-commands, etc. - there are so many different tools in Emacs to rapidly move around, it makes scrolling feel like useless fiddling, not efficiency. Mouse is nice for operations that don't require exact precisioning - like resizing windows in your WM, or another cool albeit pretty rare and gimmicky use for it is setting mouse clicks for multiple-cursor selection - feels like shooting lasers in a video-game, i.e., (global-set-key (kbd "C-s-<mouse-1>") 'mc/add-cursor-on-click) Selecting regions of text with mouse? Why, if vim-navigation lets me quickly grab: anything between things - parens, brackets, quotes, etc.; anything including those things; anything up to the char; including the char; until some text; backwards up to the text, etc. With expreg (expand-region) I can quickly expand and contract my selection - it's so smart - it first selects the word, then line, then sentence, then paragraph - similarly it expands/contracts structurally for code, it understands org-mode, yaml, markdown and Lisp structure. After developing the muscle memory for these things, selecting and moving text with the mouse feels so crude and annoyingly inaccurate. Makes me feel sorry for the vscode kiddos to be honest.
- femiagbabiaka 10mo agoThis is a much better alternative to using evil-mode, kudos. It's absolutely right that losing access to the "lingua franca" of emacs keybinds makes the whole thing kind of pointless, unless you rebind everything, of course.