TruncateLines

Turn off wrapping for a single buffer using `M-x toggle-truncate-lines’. Long lines will show a continuation character in the right margin at the window’s edge to indicate that one can scroll to see the rest.

truncate1.png

As you move the point, for example by typing or with C-a and C-e, the buffer will scroll horizontally to show you the rest of a long line. You can also scroll manually using C-x < and C-x >.

truncate2.png

This is a buffer local variable. You can set emacs to default to truncating lines by customizing the option ‘truncate-lines’ (M-x customize-option truncate-lines) or by putting the following in your InitFile.

(set-default 'truncate-lines t)

If you would like line truncation to always be turned on whenever you open a specific file, you can do so by adding the following File Variables line to the top of any file:

-*- truncate-lines: t -*-

To make it easier to toggle truncating lines, you can bind it to a key sequence in your InitFile. For example, C-c $:

(global-set-key "\C-c$" 'toggle-truncate-lines)

Scrolling horizontally is supported by many mouses and mouse-like devices — for example, by using two fingers on a trackpad on most GNU/Linux laptops. To tell emacs you’d like those mouse events to scroll the buffer sideways, add the following to your InitFile:

;; Horizontal scrolling mouse events should actually scroll left and right.
(global-set-key (kbd "<mouse-6>") (lambda () (interactive)
				    (if truncate-lines (scroll-right 1))))
(global-set-key (kbd "<mouse-7>") (lambda () (interactive)
				    (if truncate-lines (scroll-left 1))))

The truncate-lines setting does not apply to horizontally-split windows. ‘C-x 3’ splits windows horizontally, where as ‘C-x 2’ splits them vertically.

To turn wrapping on in horizontally-split windows, use the following in your InitFile:

(setq truncate-partial-width-windows nil)

We don’t recommend it, either, because horizontally split windows are usually too small to read anyway. Note that this variable is not buffer-local.

See LineWrap for more info.

See PhysicalLineMove for a minor-mode that changes line movement commands (C-n, C-p, C-a, C-e) to take into account wrapped lines; useful if you don’t want to truncate lines!

Isn’t this deprecated by M-x visual-line-mode? I don’t see what else PhysicalLineMove would bring to the table.
What I like about truncate-lines versus visual-line-mode is that the former doesn’t split on word boundaries and adds symbols to the fringe.

If you want to set truncate-partial-width-windows just for a certain mode, you need to put the setting in a hook:

(add-hook 'diff-mode-hook (lambda () (setq truncate-lines t)))

Nano truncates lines so that when you scroll toward the end of one, the line itself moves to the left independently of the rest of the text. I’ve had a surprisingly hard time finding any talk of this feature in emacs. Is it possible?


CategoryDisplay CategoryFilling