I often use my Emacs frame split vertically. This makes a problem when I list my open buffers (C-x C-b). The lines in the displayed buffer-selection list will wrap and the list becomes very untidy visually, like this:

enter image description here

If I hit M-x visual-line-mode the list become what I want it to look, easy tor read like this:

enter image description here

I need line wrapping in all my text files, but want to avoid it for the buffer-selection list.

How can I set visual-line-mode locally only for the buffer-selection list?


How are you enabling visual-line-mode currently? visual-line-mode is already buffer-local. It is not a global minor mode. Are you doing something that turns it on in all buffers (modes)?

(add-hook 'Buffer-menu-mode-hook 'visual-line-mode)

But your screenshots appear not to come from the default binding of C-x C-b, which is list-buffers, but from some Helm variant or something else. This is not stated in your question's recipe. In that case, you might need to look for some other hook to use. But the idea is the same: turn on visual-line-mode in a mode hook for the buffers (modes) you want.

|improve this answer|||||
  • Yes I invoke Helm, and then buffer cycling (bs), the latter code lines contains (global-visual-line-mode 1), so I do not understand why visual-line-mode seems to be turned off when i list my buffers. – myotis Sep 3 '17 at 15:17
  • 1
    Visual line mode will wrap lines. Since it is turned on globally, it is also affecting your buffer list. I believe you want to turn visual-line-mode off in the appropriate hook for your buffer list command. Alternatively you may want to leave it off globally and only turn it on for modes where it makes sense, e.g. text-mode-hook. – glucas Sep 3 '17 at 15:25
  • What @glucas said. If you want it to be on in some modes and off in others then you should either (1) turn it on only in specific modes or (2) turn it on globally and then turn it off in specific modes. Usually people do the former. But if bs turns it on globally unconditionally then you have little choice and must do #2. – Drew Sep 3 '17 at 18:22
  • Thans Glucas and Drew! I am unsure how I turn visual-line-mode on in a specific mode. Can you give me an example, for instance witch code to use to turn it on in org-mode? – myotis Sep 3 '17 at 22:51
  • See my answer - that's what it does, for Buffer-menu-mode. You probably want something like org-mode-hook for Org mode. To understand how to turn a minor mode on/off from Lisp, use C-h f define-minor-mode. Most minor modes are created using define-minor-mode. Sometimes the doc (C-h f) for a minor-mode function itself is not so great in terms of how to turn it on/off. – Drew Sep 4 '17 at 4:06

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.