12

I'm using emacs 25.1.1 with the prelude config. In Atom I used to have a setting that made my lines wrap at 80 characters (without cutting words) for better readability. I've searched on the web for something similar for emacs but I have not found anything. Any ideas on how to do this?

Drew
  • 75,699
  • 9
  • 109
  • 225
José María
  • 273
  • 1
  • 2
  • 5

1 Answers1

14

auto-fill-mode is what you're looking for. You can enable it automatically for editing text by adding this to your config:

(add-hook 'text-mode-hook #'auto-fill-mode)

You can customize how long lines in your text documents should be by customizing the fill-column variable. For example:

(setq-default fill-column 80)

If you want to to make sure that lines don't split on your screen as you're typing things, you can set up visual line mode.

To enable this for code files add:

(add-hook 'prog-mode-hook #'auto-fill-mode)

This code needs to be added in your initialization file (~/.emacs or similar). That will make the change effective the next time you start emacs, so either do that now or close and reopen files that are already open.

NickD
  • 27,023
  • 3
  • 23
  • 42
  • 1
    Added those two lines to my config but it doesn't seem to do anything. Lines still continue beyond 80 characters... – José María Jan 26 '17 at 11:11
  • The examples that I have provided will work only for editing text files, not code. Also, lines get wrapped when you type space or other character that doesn't belong it a word. I don't know how well `auto-fill-mode` would work for editing code. –  Jan 26 '17 at 11:21
  • Um, hm. And for editing code there is nothing like that? And what about org-mode? – José María Jan 26 '17 at 11:24
  • `org-mode` is derived from `text-mode`, so this will work in it. –  Jan 26 '17 at 11:25
  • 1
    Doesn't seem to... Added that but lines still extend beyond the screen bounds. – José María Jan 26 '17 at 11:32
  • In that case, you might be looking for this: https://www.gnu.org/software/emacs/manual/html_node/emacs/Visual-Line-Mode.html –  Jan 26 '17 at 11:44
  • 1
    That last thing worked beautifully! I also used this https://melpa.org/#/visual-fill-column to adjust it to the column width. Thanks! – José María Jan 26 '17 at 12:06
  • Could you edit your answer with the new info so I can mark it as solved? – José María Jan 26 '17 at 14:36