25 Useful Tips for Emacs (for beginners and advanced users)

tips.jpg

1. Insert today's date into the buffer

M-x shell-command or C-u M-!

date +%Y-%m-%d

2. Quickly save snippets of text from a buffer to a file

M-x shell-command-on-region or M-|

> cat >> tips

3. Links are not immediately clickable in Emacs in Text files

Change this with global-goto-address-mode

Then invoke C-c RET on the link.

4. Open multiple files in Dired

  • Mark the desired files
  • M-x dired-do-find-marked-files

5. Flush empty lines from a buffer

M-x flush-lines RET ^$ RET

6. Delete empty directories in Dired

One can just use the find tool. Navigate to the directory you want to clear of empty folders.

M-! find . -empty -type d -delete <RET>

Hit g to refresh.

The echo area confirms if the command has run successfully.

7. Repeat complex (i.e. minibuffer commands)

C-x Esc Esc

8. Insert x number of lines of a single character

C-u 70 *

9. Change the encoding system for a file

C-x C-m f

10. Cycle org lists

Try the command org-cycle-list-bullet on a list and see it change:

1. org-cycle-list-bullet
2. org-cycle-list-bullet
3. org-cycle-list-bullet

11. Auto-expand without an external package

One can use M-/ =dabbrev-expand

12. Cycle org-agenda files

Invoke org-agenda, then use C-' to cycle between files.

13. Add a package manually

Add the path of the package:

(add-to-list 'load-path "~/.emacs.d/packages/session")

Then require it:

(require 'session)

14. xah-make-backup

For easy manual backups of a given buffer:

http://xahlee.info/emacs/emacs/elisp_make-backup.html

15. Copy a link in Dired

C-0 w Provides an absolute path
C-u w Provides a relative path

16. Numbered lists in org

If you were to type this in Emacs:

  1. item 1
  2. item 2

And then go on to type text like this. It would interrupt the list and the next item would be numbered as 1) not 3). So, do this:

3) [@3] This will be item 3
4) and this will be item 4

17. Bind global keys interactively

M-x global-set-key

Bind whatever key you want. E.g. C-c f

Choose the command you want. E.g. flush-lines

Invoke: C-x ESC ESC

Yank that code into your Dot Emacs.

18. Preserve line breaks during org export

Customize this variable:

org-export-preserve-breaks

Or on a per file basis: OPTIONS: \n:t

19. Set mark at a place and return to it

C-SPC
C-u C-SPC

20. Delete text completely WITHOUT copying it to the kill ring

There are three methods:

  • M-x delete-region
  • C-d
  • Backspace (on some keyboards the DEL key)

21. Get rid of peculiar ^M characters in an Emacs file

One of the most straightforward ways is with just an Emacs command one-liner:

  • Select the buffer (C-x h)
  • Invoke C-u M-| dos2unix

(dos2unix would need to be installed.)

22. Search the web

M-s M-w

23. Dired Listing Switches: change the way Dired sorts files and folders.

C-u s

Type -alh to sort by name
Type -alt to sort by date
Type -lhS to sort by size

24. Create new lines at end of a buffer

Set this variable:

(setq next-line-add-newlines t)

Then invoking C-n at a buffer's end will create new lines without RET.

25. How to RENAME a file while working on it in a buffer

Think out the box!

Simply use C-x C-w (write-file)

This is basically equivalent to Save As in Microsoft Word.

Advantage: You do not need to leave the buffer.

Then use M-n which will insert the current file name into the mini-buffer.

One can also just use TAB or M-/ for name expansion.

The only "disadvantage" of this Method: The old file remains as a backup. But maybe that's a good thing!

You would need to delete it if you did not want it.

That's all for today folks.

Return to Home

Email Me