41

visual-line-mode is very useful to wrap lines with the window size changing without inserting any newlines. But in org-mode, it also wraps the headline and source blocks which is a little bit annoying.

So here comes my question: How can I turn off visual-line-mode for org-heading and source blocks permanently in org-mode?

7
  • 1
    If it is possible to both wrap (setq word-wrap t) and truncate (setq truncate-lines t) different portions of the same buffer, I'll definitely make this thread one of my favorites!
    – lawlist
    Commented Jan 16, 2015 at 7:14
  • @lawlist So you mean it is impossible to make it in org-mode?
    – Leu_Grady
    Commented Jan 16, 2015 at 7:15
  • 2
    Lol, you are a expert on emacs in my mind, lol. Okay, let's expect solvable answers!
    – Leu_Grady
    Commented Jan 16, 2015 at 7:23
  • 1
    Here is an idea that I use, but it is not what you had in mind. I have the default in the buffer as being (setq truncate-lines t) and (setq word-wrap nil). When I edit any entry or if I just want to zoom-in/focus on one entry in particular, I have it set to narrow to subtree, at which time it wraps with visual-line-mode -- aka (setq word-wrap t) and (setq truncate-lines nil). When I finish editing, it widens and goes back to truncated lines.
    – lawlist
    Commented Jan 16, 2015 at 7:24
  • 2
    I'm pretty sure there is no way to inhibit word wrap for some regions only, e.g. via text properties. Report it as bug. Of course, one might rationalize that code lines shouldn't be that long in the first place. As for headlines (and lists), `org-indent-mode' looks pretty nice.
    – olaf b
    Commented Mar 13, 2015 at 19:05

3 Answers 3

22
+100

Another solution is to use adaptive-wrap-prefix-mode.

This way you'll see the full header and source but it will wrap nicely indented.

With visual-line-mode:

enter image description here

With visual-line-mode and adaptive-wrap-prefix-mode:

enter image description here

4

The package phscroll written by misohena perfectly solved the problem. It adds overlays to beginning/end of line if the width of elements like org-table exceeds the length, while keeps the line-wraps work.

Currently it only supports org-table, but theoretically it can be extended to almost all org elements.

1

This is a good question! The same issue applies when you have an Org table that is wider than fill-column. What I do is open the section in an indirect buffer with org-tree-to-indirect-buffer i.e. C-c C-x b. And in the indirect buffer, I disable visual-line-mode for editing that section.

2
  • This pin-points also my major problem with adaptive-wrap-prefix-mode. Pityingly the solution is cumbersome. But, that is not your fault.
    – Tobias
    Commented Mar 9, 2018 at 8:38
  • @Tobias I made a new command that narrow the table while turning on truncate-lines, then you can enjoy the unwrapped table, which is pretty nice.
    – Leu_Grady
    Commented Sep 10, 2020 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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