What can I put in my .emacs file so that all lines an any kind of buffer always truncate if too long. I do this mostly because I tend to open many frames and it gets hard to read on a small screen if my 80 char lines get wrapped 2 or 3 times over.
3 Answers
Try M-x
toggle-truncate-lines
on a per buffer basis, to see if it does what you want.
In .emacs
you'd put this, to make it default for all buffers.
(setq-default truncate-lines t)
You may also like:
(setq-default global-visual-line-mode t)
Which you can try out with M-x
visual-line-mode
(it also toggles.)
EmacsWiki references: visual-line-mode
truncate-lines

- 29,401
- 18
- 105
- 117
-
So I guess (setq 'global-visual-line-mode t) ? – Jesus Ramos Sep 28 '11 at 02:16
-
It's odd since I thought I tried truncate-lines before to no avail maybe I messed something up, thanks :) – Jesus Ramos Sep 28 '11 at 02:24
-
Yeah it worked now, I tried virtual lines instead but I would just rather have them truncated but thanks for the wiki references on both. – Jesus Ramos Sep 28 '11 at 02:32
-
1`(global-visual-line-mode 1) ; 1 for on, 0 for off.` – AesopHimself Oct 01 '16 at 03:21
-
2I don't know why but `(setq-default truncate-lines t)` does not work on my case. but `M-x toggle-truncate-lines` works. @ocodo – alper Jul 22 '18 at 17:31
-
@alper - try this question on https://emacs.stackexchange.com too (https://emacs.stackexchange.com/search?q=truncate-lines) – ocodo Jul 23 '18 at 01:50
-
2`(setq-default truncate-lines t)` didn't work on my case @ocodo – alper Jul 21 '19 at 18:15
-
2As others have indicated, `(setq-default truncate-lines t)` does not work. – Wouter Beek Aug 04 '19 at 08:44
In your .emacs
or .emacs.el
or .emacs.d/init.el
(depends where you locate your main emacs config file), write :
(custom-set-variables
'(truncate-lines t))
the block custom-set-variables
may already exist, so just add '(truncate-lines t)
to the list. This way your configuration file keeps clean.
Alternatively you could hook a keybinding, like that :
(local-set-key (kbd "C-x w") 'toggle-truncate-lines)
So you can truncate when the lines are bothering the visual

- 12,272
- 14
- 80
- 106
-
-
1Like the accepted answer, the solution `(custom-set-variables '(truncate-lines t))` in this answer does not work for me either. – Wouter Beek Aug 04 '19 at 08:45
If the (setq-default truncate-lines t)
didn't work, it's possible that you are in another major mode, ie markdown-mode, etc. In that case, this worked for me. (I tested it on Emacs v28.1 / Doom Emacs on Mac)
;; in init.el, etc...
;; word-wrapping off
(setq-default truncate-lines t)
;; for markdown-mode
(add-hook 'markdown-mode-hook (lambda () (setq truncate-lines t)))

- 926
- 1
- 9
- 17