25

I have limited emacs experience. Tried to find a solution to disable line wrapping in Spacemacs but couldn't find any.

The solution to this problem in Vim is to execute set nowrap. But it's not working in Spacemacs.

Any solution to this would be much appreciated.

Dan
  • 32,584
  • 6
  • 98
  • 168
Vamsee
  • 353
  • 1
  • 3
  • 5
  • I've never seen Spacemacs before, but it sounds like you're looking to disable [`auto-fill-mode`](http://www.emacswiki.org/emacs/AutoFillMode). Try `M-x auto-fill-mode` (which will toggle it on and off) and, if that works and is what you mean, you can disable it automatically in your init file. – Dan Nov 20 '14 at 14:40
  • 3
    Try the following `C-h v` `truncate-lines` after starting Spacemacs. This will tell you what it is set to when starting up. – Jonathan Leech-Pepin Nov 20 '14 at 18:27
  • @JonathanLeech-Pepin Thanks your tip helped me debug the issue. – Vamsee Nov 20 '14 at 19:01

5 Answers5

34

On November 23 syl20bnr added a new toggle called spacemacs/toggle-truncate-lines, available on SPC t l. Another toggle you may also find useful is spacemacs/toggle-visual-line-navigation, available on SPC t L. See Github commit.

This is how your dotspacemacs/user-config can look like to enable both toggles:

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration. You are free to put any user code."
  (spacemacs/toggle-truncate-lines-on)
  ;; Visual line navigation for textual modes
  (add-hook 'text-mode-hook 'spacemacs/toggle-visual-line-navigation-on)
)

If you don't know where dotspacemacs/user-config is, it's in your .spacemacs file, available by pressing SPC f e d.

The hook for spacemacs/toggle-visual-line-navigation-on is because it doesn't work globally otherwise.

Mirzhan Irkegulov
  • 1,088
  • 1
  • 9
  • 16
12

Add this to your ~/.spacemacs config function:

(add-hook 'hack-local-variables-hook (lambda () (setq truncate-lines t)))
Constantine
  • 9,072
  • 1
  • 34
  • 49
syl20bnr
  • 2,095
  • 11
  • 21
  • 1
    I respectfully disagree with this answer, because it is essentially trumping (overriding) previous settings (if any contradict) and it works in this instance because the `hack-local-variables-hook` is called later in time in the loading process of a buffer. The better solution would be to make it major-mode specific, or design a better global solution that does not use the `hack-local-variables-hook`. – lawlist Nov 20 '14 at 19:23
  • @lawlist I agree it's a hack but AFAIK there is no mode for truncate lines. If you want it globally it can be tricky via major mode hooks, and it won't be better than this. It may be better to use the toggle function instead but it does not offer to force activation of truncate lines. – syl20bnr Nov 20 '14 at 19:44
9

M-x toggle-truncate-lines RET is the Emacs equivalent of Vim's :set wrap!

nanny
  • 5,704
  • 18
  • 38
  • 1
    And programmatically: `(setq truncate-lines t)` – lawlist Nov 20 '14 at 17:27
  • @nanny Thanks, you suggestion works for disable line wrapping after starting spacemacs. But @lawlist suggestion of adding `(setq truncate-lines t)` to ~/.spacemacs not working. – Vamsee Nov 20 '14 at 18:22
  • @Vamsee -- That line of code that I suggested is meant to be used *programmatically* -- e.g., when writing a function. It can be used on demand by typing: `M-x eval-expression RET (setq truncate-lines t) RET` – lawlist Nov 20 '14 at 18:24
  • @lawlist I actually wrote it inside the function `dotspacemacs/config` which is inside file ~/.spacemacs. This file is executed after spacemacs is loaded. I can say this file is loading since my theme settings, font customisations are working. – Vamsee Nov 20 '14 at 18:43
  • 2
    @Vamsee -- `truncate-lines` is a buffer-local variable, which means that the code needs to be executed while focus is inside the target buffer. The library you cited is a collection of a million and one preselected user customizations, including certain selections based on various major modes. To really track down your issue, you would need to specify what major mode you are using -- then it would be necessary to check all the major mode hooks used by the library in question, and even then, its possible you have that setting somewhere else. For example, `visual-line-mode` enables wrapping – lawlist Nov 20 '14 at 18:45
  • 1
    @lawlist Finally it's working I had to set custom variable inside the function `custom-set-variables` and not in `dotspacemacs/config` function. Thanks for your help. – Vamsee Nov 20 '14 at 19:00
4

I added this to my init file inside dotspacemacs/user-config to disable automatic line breaking:

(spacemacs/toggle-auto-fill-mode-off)

By default, you can toggle on/off with SPC t F.

Dan
  • 32,584
  • 6
  • 98
  • 168
Guy Gur-Ari
  • 201
  • 1
  • 3
1

I would have commented, but I don't have enough reputation, so I will just write it here.

Mirzhan Irkegulov's first expression worked, but the second one didn't work (add-hook 'text-mode-hook 'spacemacs/toggle-visual-line-navigation-on)

Instead, I had to use (global-visual-mode t)