Emacs commands I got by with for years
macadie.info
macadie.info
On top of Doom Emacs, I have enabled CUA Mode and my own configuration is less than 10 lines, and it is copy-paste from Internet to enable word-wrap, delete to trash etc.
The only shortcuts I use are:
C-x C-f - open file
C-c C-s - save file
C-c, C-x, C-v - copy, cut, paste
C-z - undo
C-s - search
C-x 1, C-x 2, C-x 3, C-x k - split and killing of buffers
For the remaining I use F10 to bring up the menu and do via it or use M-x and try to find the matching function by "guess n type".
I tried learning a few commands but forgot them after a while.
With these commands and help of Doom Emacs, Emacs has been pleasant to me. I have LSP setup for C, Python, Rust, JS which provides me IDE like features. I have no complaints with Emacs. There has been no learning curve for me because I never tried learning it. The above mentioned commands too I learned by periodic usage.
Thanks to every Emacs user for sharing their knowledge on Internet, had it not been you people, Emacs would have been unreachable to beginners like me. :)
C-x r b runs the command bookmark-jump
C-x r m runs the command bookmark-set
> I tried learning a few commands but forgot them after a while.
C-h k runs the command describe-key. You do this and after that any command, and it will give you the explanation.
I've been using emacs only a year. I played a lot with it the first months and it was heavy, but if you take it like a game the benefits are immense.
Also defining your own keys tied to elisp functions or even running python scripts or bash scripts called from eslip and tied to keys is awesome.
For example things that i did: - Open, close bluetooth to conect/disconect headphones. - Open desktop gui folder of current buffer. - Insert custom org templates and such.
I encourage you to take some time every week to play with emacs. Be cautious not to fall down the rabbit hole, but you can gain a lot by learning just the basics.
pd: when learning a new command take it REALLY slow, and push the keys deliberately, this will make you learn faster, like playing the piano.
Hearing them for the first time :)
> C-h k runs the command describe-key. You do this and after that any command, and it will give you the explanation.
I think I'm forgetting them because I don't use them often but will keep this in mind thank you!
> Also defining your own keys tied to elisp functions or even running python scripts or bash scripts called from eslip and tied to keys is awesome.
It is definitely in my todo list to learn. I have changed many of my workflow to Emacs like using Org for todo, reminders, to even publishing a book with it [1], Ledger to manage money etc. So investment in elisp is worthy every penny!
Thanks for your comment :)
But what about the opposite direction ? Is there anything like an "apropos" command ?
[1]https://www.gnu.org/software/emacs/manual/html_node/emacs/Ap...
There is also C-h d (apropos-documentation)
Embark[2] is also cool. It will show all the possible commands relevant to where the cursor is at that moment. I bind it to C-c a.
[1] https://github.com/minad/marginalia [2] https://github.com/oantolin/embark
C-h f runs the command describe-function (found in global-map)
If the command is bound it has "It is bound to..."
I agree with the sentiment here mostly: very few commands go an awfully long way, with org mode about the only Melpa add on I know I use.
I do wish I could remember some chording to avoid a few long winded M-x command strings being typed. And the cut/yank thing is .. annoyingly inverse to most people's language as is window and frame.
That said, I am more fluent in vi. Modes are a pattern just as valid as modeless. We're all meta all the time. Sometimes being immersed in the whole (-emacs) is what I want and sometimes I want a :1,$s/earch/and replace/g experience and being mode-full is fine.
While you enable it (usually by pressing Esc), Ctrl is "assumed" to be always pressed, so saving a file becomes "x s" (though when I am on Mac, I always map Cmd+S to save - and many other Cmd key based shortcuts that I used in every other app - thanks to emacs built-in shortcuts almost never using the Cmd key as it was designed for Unix).
It made using emacs much more enjoyable for me.
[1]: https://github.com/meow-edit/meow
[2]: https://esrh.me/posts/2021-12-18-switching-to-meow.html
Nvi has no syntax highlighting and is far less scriptable. Again, it's minimalist religion.
A lot of this is muscle memory.
I've found that this helps me to memorize ones I reference, even if it's only memorized for a couple hours.
For tmux users, this will avoid any lag. Place it at ~/.tmux.conf:
set -sg escape-time 10Strangely enough I decided to learn vim keybindings once I heard that it can be learned as a language. After a while I learned about LSP and got curious if I could adjust my setup to run remotely over ssh. I ended up trying Lunarvim and then Doom.
I finally feel like I can use all the power of Emacs as an editor with the vim keybindings, and Doom LSP support is amazing. So yeah, learning vim is what got me back into Emacs.
Also what do you mean by, "learned as a language" wrt to vim keybindings?
I first started by getting a free VPS from Oracle and setting up my computer to use autossh to always maintain a connection to the VPS so that I could access it through reverse tunnel over any kind of NAT. I use a key pair for authentication to make it secure. I also use mosh to make it easier to reconnect when moving around.
Then anything that can be done locally over a terminal can also be done remotely over ssh. I try to avoid anything graphical. You can use tmux or screen to do terminal multiplexing, or if stay inside Emacs, you can do the terminal multiplexing without separate tools by using multiple windows with terminal buffers.
So basically you can slowly convert your workflow to run on a terminal when working locally, and if you make your machine accessible remotely, then you will naturally start to use it also when working remotely.
> Also what do you mean by, "learned as a language" wrt to vim keybindings?
I think the original idea of "learned as a language" came from reading this stackoverflow entry [1], but when learning I looked also to other references. [1] https://stackoverflow.com/a/1220118
Vim isn't a hodgepodge of ad-hoc keyboard shortcuts like, say, typical Windows programs ("where shall we put search and replace? Ctrl+H is free, done"). It can be seen more as a small domain-specific language for text manipulation. "d2w" is delete twice word (delete two words). "yy4p" is copy line 4x paste (copy this line four times below).
It's built of verbs (or operators, like delete, yank, make-uppercase), counts, movements (motions, like up,down,to end of line, to end of word, to start of next word, to search match) and objects (like characters, words, lines, paragraphs, blocks inside braces, text inside quotes, 'the selection') and you compose them together to say what editing you want to do on the text.
":help gU" will tell you that gU makes {motion} uppercase, that means you can do gUe to uppercase to the end of the current word, gU2e to uppercase to the end of the next word, gUfx to uppercase until the next x character, gU/thing to uppercase until the regex search for 'thing' matches...
and Vim being around a long time, it has a lot of different verbs, motions, objects to allow you to slice and dice your text just so for the edits you want to make.
Try
:help motion
:help word-motions
:help operator
:help objectsSecond bugbear is running in terminal so all my GUI conveniences are missing, but it's emacs so that's a distant second to the first.
Agreed with the GUI stuff, needing to write graphs to a specific file and have a web server was super, super annoying.
At the place(s) I did this, pretty much all dev took place on remote servers so it was pretty normal for a lot of people.
The amazing thing is that this contraption is actually usable.
https://www.gnu.org/software/emacs/manual/html_node/emacs/Sa...
one thing I've customized in emacs that has helped over the years:
(global-set-key "\C-z" 'bury-buffer)
I use control-z to cycle through my buffers.> people want to play the game of “who can spin the most plates in their head”. It is a stupid game to play, and only stupid people like playing it.
Modes are exactly the first part of the solution - you remember 1-key prefix for a bunch of other 1-key prefixes
> If you are learning Emacs, there is nothing wrong with writing down commands, either on paper, or even in another editor, or using an online cheat sheet.
There is, it's a much bigger effort vs. the editor conveniently(!) showing you that cheat sheet (that's the second part of the solution). Not sure about emacs, but e.g., Helix does this almost correctly - when you press the first 1-key prefix it would show a panel that lists all the other keys/commands within that mode so you don't need to remember all 50 commands in your "goto" mode
You don't need any papers/online cheatsheets (context switches/wasting time searching, which is especially awful with physical paper), instead you get help right when you need it right where you need it!
Global Bindings Starting With C-x 5:
key binding
--- -------
C-x 5 C-f find-file-other-frame
C-x 5 C-o display-buffer-other-frame
C-x 5 . xref-find-definitions-other-frame
C-x 5 0 delete-frame
C-x 5 1 delete-other-frames
C-x 5 2 make-frame-command
C-x 5 5 other-frame-prefix
C-x 5 b switch-to-buffer-other-frame
C-x 5 c clone-frame
C-x 5 d dired-other-frame
C-x 5 f find-file-other-frame
C-x 5 m compose-mail-other-frame
C-x 5 o other-frame
C-x 5 p project-other-frame-command
C-x 5 r find-file-read-only-other-frame
Each function name in the output is a link to function documentation, which itself links to the source for that function, all entirely within Emacs. Emacs is really well thought out due to its age, but the real trick in using it (I've found) is understanding the full scope of its capabilities. My solution to this was inelegant, but worked really well: I bought a copy of the Emacs Manual in print and left it in my bathroom for about 7 years. Problem solved. =)Well.. it is always there. If I were on my own machine all the time.. but there are many machines. As an Emacs user (for decades) I still use 'vi' for config files etc. I never bothered to learn more about vi commands than necessary for that (insert, delete, append from end of line, and esc-:wq etc).
Furthermore it's easy to sudo vi file, no idea how to do it with emacs. And even if I knew, I think it's a good idea to contain an edit to a protected file into a short lived process.
/sudo::/path/to/file
For this reason, I remapped my arrow keys to move around them. I also have `Command + Left/Right` for cycling between buffers and `ESC` to kill a window. Recently, I also started to use function keys for managing bookmarks and buffers. Though for the latter, `C-x b` has also been quite often used since I remapped my CapsLock key.
I guess with all this, I wanted to say that there is much untapped potential for eMacs just by remapping some basic keybindings to fully appreciate `C-f` and `C-b` editing nuances.
> For this reason, I remapped my arrow keys to move around them.
I don't have access right now, but on my work laptop I use a package that lets you use Shift + Arrow Key to jump between windows. Of course, if your minor mode uses those keybindings for something else (e.g. org mode), then it won't work.
> I also have `Command + Left/Right` for cycling between buffers
This is a good idea. I use C-M-[ and C-M-].
At some point I learned how to use the Hydra package and often use that for major modes I'm not too familiar with. No longer need to memorize (or make my own custom) keybindings.
Also witting your own elisp functions to manage buffers and have it mapped to some keys and commands opens a infinite dimension. For me it's like the holy grail of software, at least text based.
This is how I started. You could go with nano/pico, but then you're stuck there... if you start with emacs, you can use it just like you would use nano, but when you need something more, it's always there, just one google search and one key combination needed (and hopfeully you remember that, so you don't need to google it again).
I use prescient.el [0] with prescient-persist-mode for this, though a quick look seems that SMEX also has something similar [1] but I have not used that so I can't say anything about how it works.
I couldn't agree more. I've never understood vim, I just want to edit text, why turn it into a complicated task in which I must remember a thousand shortcut, and the same shortcut does a different thing in each mode.
"Search for the function name foobar; swap the parameters by cutting the first one up to the comma; delete the latter, and the space which comes after; type a comma after the other parameter, and paste."
The Vim commands are: / foobar <Enter> f ( l v t , " a d d f <Space> e a , <Space> <Esc> " a p
With VS Code, it would be like: <Cmd>+f foobar <Enter> "Carefully select the first parameter" <Cmd>+x "Place the cursor at beginning of the second parameter" <Delete> <Delete> <Option>+<Left Arrow> , <Space> <Cmd>+v
The nicest thing with vim is that I never have to touch the mouse for a lot of tasks. And I don't really think about how to edit, just what to edit as the language is very intuitive once you got it down.
You forgot the time you spend learning a counterintuitive way to edit text. The microscopic time you gain while editing text is nothing in comparison to that.
>just what to edit as the language is very intuitive once you got it down.
Everything can become intuitive when you spend hours and hours learning it. The question is whether it's worth it.
Why exactly? That's just pressing a button, like any vim command.
For example I already know the Emacs keyboard shortcuts in this article. But that gets me nowhere near the proficiency I have in vim. I tried various vim compatibility layers, but then it's harder to get help about org-mode specifically (since you're using different shortcuts).
Yes, and you should be conservative with what you install.
There is so much stuff already built into Emacs that can be amazingly helpful if taken seriously. „vc-mode“ e.g. is a great front-end for version control. It works with many systems and only comes with a couple of keyboard short cuts. So you don’t need to learn magit. Or „compile-mode“ which you just have to feed shell scripts to adapt it to any programming language or publishing system you like. Together with „.dir-locals.el“ you make Emacs even switch to the correct build command depending on the source file‘s location. Or take Emacs‘ „xref“ system. It‘s there by default by pressing „M-.“ on a function name. All you need to do is run „etags“ to generate a search index. This way you don’t even need LSP in many contexts. There is also „dired“ which is a great file manager serving many of your dev needs without resorting to extensions like „treemacs“. Emacs also comes with „customize“ to configure the various modes w/o needing to learn Lisp. It’s good enough for many things.
Then when you decide you need an extension differentiating the good from the bad extensions is the biggest hurdle for newbies I guess. It does not help that many Emacs influencers play around with cutting edge extensions that look cool on the surface but seldomly are production ready.
However, here is the workflow I am following when incorporating new extensions:
Most Emacs extensions live on GitHub these days. Usually, before I start installing anything I really need to have an urgent problem to solve. Then I google around ending up in a GitHub repo. Then I check whether the extension is actively maintained and whether it is also provided as a Melpa package. Then I evaluate the quality of the documentation. If it seems simple enough to configure I‘ll try it out in a git branch of my Emacs config. Once I tried it out a couple of hours or even days I merge the changes into „main“.
BTW: If you want to learn org-mode try writing your Emacs configuration using it.
if you are only installing a single package on top of vanilla emacs and you use git, it should definitely be magit.
I am personally using „magit“ but I just wanted to stress that newbies might want to postpone installing it until they are more comfortable with vanilla Emacs.
So at least for me, it wasn't an option. Maybe I'll try again someday :)
I bound other-window and `(lambda nil (interactive) (other-window -1))` to C-n and C-p ages ago, because I'm never on a machine without arrow keys so the default behavior of those is worthless to me and (in contrast) I'm navigating between windows continuously; having that behind `C-x o` always seemed too far away.
C-x g - magit-status
C-c c - org-capture
C-x h - mark-whole-buffer
M-: - eval-expression
C-x C-u - upcase-region
C-x C-o - ace-window
(use-package ace-window :bind ("C-x C-o" . ace-window))
Allows you to number your buffers and choose the one you want by pressing the number associated with it
In dired, C-0 w gives you the full path to the file under the cursor
https://github.com/svilendobrev/svd_bin/blob/master/qini/_vi...
have fun
Error establishing a database connection