Emacs Notes

Emacs is a very feature-laden editor. As such, it can be hard to remember all of the various features that are very useful, but perhaps, not frequently used. I thought I would create a list of some features I have learned and did not want to forget.

Show a list of all currently opened buffers

C-x C-b

When there are dozens of buffers open, it can be difficult to switch to the correct one. This command will list them all, and allow you to go directly to the buffer you wish to edit.

Display current function name

M-x which-function-mode

This will add the name of the function that the cursor is currently in to the status bar at the bottom of the page. I have found this pretty useful when exploring unknown code, or long documents with hundreds of functions. I don’t enable this all the time though because I have found it can sow the responsiveness in larger documents.

Show invisible characters

M-x whitespace-mode

Sometimes its nice to see if a document is using spaces or tabs. Enabling white-space mode makes it clear the type of indentation being used, as well as making other whitespace sins apparent. This is particularly useful when you work on a file that’s been passed around multiple editors and is not consistently indented.

Along with this, you can easily remove whitespace present on the end of the lines by selection a region and using the following command:

M-x delete-trailing-whitespace

Easy alignment

M-x align-regexp

This is actually a command I do use frequently. I like to have things lined up as I feel that it improves legibility. This command, when run on selected text, will align the text to the matching user input. For example, I can use this to align multiple lines on an equal sign.

Insert Text on Multiple Lines

C-x r t

Make a selection across multiple lines, then run this command. As you type, it will insert the text on each line you selected in the column that you began/ended with. If you start and end in different columns, it will replace the text in those columns on each line.

Navigational Hot Keys

Moving within the buffer can be tedious without some hotkeys to speed things up.

M->

Go to end of document

M-<

Go to beginning of document

M-g M-g

This brings up the ‘go to line number’ prompt for quickly going to a specific line

C-v

Page down

M-v

Page up

C-l

Center cursor/cursor position in window

C-s

Search for term. Use the combination repeatedly to find the next instance of the search term

C-r

Search in reverse. As with the previous command, repeatedly using the combination will take you to previous instances of the search term.

Formatting Hotkeys

M-c

Make word capitalized from cursor position to end of word

M-l

Make word lowercase from cursor position to end of word

M-u

Make word uppercase from cursor position to end of word

Window Navigation

C-x 1

Return to single view

C-x 2

Split pane horizontally

C-x 3

Split pane vertically

C-x o

Move cursor to other pane/view

C-x left

Switch buffer to preceding buffer

C-x right

Switch buffer to next buffer

While not a comprehensive list, these are some of the commands I wish I had known when starting out with Emacs. There are so many, and while I like Emacs a lot, My main gripe with it is the lack of discoverability with commands.

Happy editing!

Leave a Reply