8

Recently I discovered emacs as a text editor for my latex documents. So far, I am excited with how powerful the editor is. However, I have a problem with line wrapping.

More precisely, in the option menu I choose line wrapping in this buffer --> word wrap. After that, I choose save options, but when I reopen my tex file, line wrapping is back to the default setting.

So, my question is how can I set word wrap as my default wrapping option for all my documents?

Thanks in advance

9

As you noticed, the menu entry says "Line Wrapping in This Buffer" so this is not something that is saved by "Save Options".

To enable visual-line-mode in all your latex documents, add the following in your init file (~/.emacs or ~/.emacs.d/init.el):

(add-hook 'LaTeX-mode-hook #'visual-line-mode)

This ensures the function visual-line-mode (aka "word wrap") is called for each buffer that is put in LaTeX-mode (assuming you're using AUCTeX).

More information about the hook mechanism can be found in the emacs manual.

| improve this answer | |
16

JeanPierre's answer will work fine if you want to use different word wrapping per type of document.

If you want all your documents word-wrapped, use the following:

(global-visual-line-mode t)

in your ~/.emacs or ~/.emacs.d/init.el file.

You can customize that value via the menus as well, by going to "Options->Customize Emacs->All Settings Matching..." and searching for "visual."

| improve this answer | |
  • This is the right answer--the OP asked how to turn on word wrap for all files. – James Apr 10 '18 at 15:43
  • Out of curiosity, do you know why this isn't the default? What's the benefit of not having line-wrap? To me it's 99% just a nuisance – mowwwalker Jul 28 '19 at 19:00
  • @mowwwalker Visual line mode seems awkward for code buffers, especially for languages where whitespace is significant. – Tikhon Jelvis May 4 at 15:51
  • @tikhon-jelvis That's what Hollerith format is for :) Seriously though, I believe it's the default for historical reasons. Visual line mode came about in Emacs 23 I believe. Before that you had wrapping using continuation lines (the default) or by truncating the line (visually) at the right edge of the window. – Jeff Spaulding May 9 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.