18

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.

  • I've never seen Spacemacs before, but it sounds like you're looking to disable auto-fill-mode. 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
9

Add this to your ~/.spacemacs config function:

(add-hook 'hack-local-variables-hook (lambda () (setq truncate-lines t)))
  • 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
27

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.

  • I've been looking for that mode hook for ages! Thanks! – hoosierEE Jul 6 '16 at 19:08
  • 2
    This is the equivalent of :set nowrap. Thanks! – shakerlxxv Jul 13 '16 at 15:23
  • 1
    SPC t L for the easy win. – sjas Oct 29 '17 at 15:59
8

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

  • 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
  • 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
2

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.

0

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)

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.