How to open .org and .txt files with visual-line-mode automatically turned on?

Also, is there a way to configure cursor-movement so that cursor moves as if the visual line where a logical line? line-move-visual is not effecting Spacemacs evil mode keybindings: k (line up), j (line down).

I am running Emacs 25.2.1, with Spacemacs, evil mode, org-mode on Linux.


From .spacemacs file, after adding visual-line-mode

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
(add-hook 'org-mode-hook #'visual-line-mode)
(add-hook 'text-mode-hook #'visual-line-mode)

(setq org-use-speed-commands t)

;; Do not write anything past this comment. This is where Emacs will
;; auto-generate custom variable definitions.

With emacs open to a txt file:

SPC h d k k

k runs the command evil-previous-line (found in evil-motion-state-map), which is
an interactive compiled Lisp function in ‘evil-commands.el’.

It is bound to <up>, k.

SPC h d v line-move-visual

line-move-visual is a variable defined in ‘simple.el’.
Its value is t


Tobias's advices code worked great; j and k move cursor as if the visual line where a logical line.

Then I installed org-drill. And org-drill worked fine until I restarted Emacs, then Emacs said:

Spacemacs encountered an error while loading your '~/.spacemaces' file.
Pick your editing style for recovery:

When I completed the recovery, org-drill was missing from M-x, so I reinstall org-drill. Then restarting Emacs encountered the same error. So I removed Tobias's advices code from my .spacemacs file, and now Emacs and org-drill work fine.


I placed the new eval-after-load advices code in ~/.spacemacs. And Emacs started without errors. But long lines of text in .org file did not wrap at all.

So then I restored the previous advices code in ~/.spacemacs. And started Emacs from the terminal: emacs --debug-init. There where error messages. How to copy them to clipboard? Screen shot of error messages: enter image description here

2 Answers 2


You can switch on visual-line-mode in org-mode and text-mode by

(add-hook 'text-mode-hook #'visual-line-mode)

in your init-file (e.g. ~/.emacs). (Thanks to user lawlist for clarifying that org-mode bases on text-mode.) In emacs -Q the command visual-line-mode also sets line-move-visual buffer-locally to t therefore point movement should already work on visual lines without any customization. If you don't like that behavior set line-move-visual to nil.

emacs-version: GNU Emacs (i686-pc-linux-gnu, GTK+ Version 3.10.8) of 2016-04-25

I cite here evil-previous-line from evil-commands.el:

(evil-define-motion evil-previous-line (count)
  "Move the cursor COUNT lines up."
  :type line
  (let (line-move-visual)
    (evil-line-move (- (or count 1)))))

You can see that line-move-visual is explicitly set to nil there. So the behavior you experience is intended.

On the other hand there is a command evil-next-visual-line defined right below evil-commands.el:

(evil-define-motion evil-next-visual-line (count)
  "Move the cursor COUNT screen lines down."
  :type exclusive
  (let ((line-move-visual t))
(evil-line-move (or count 1))))

There line-move-visual is explicitly set to t.

In evil-maps.el one finds the following two lines:

(define-key evil-motion-state-map "gj" 'evil-next-visual-line)
(define-key evil-motion-state-map "gk" 'evil-previous-visual-line)

So I guess you have just to press gj and gk instead of j and k for motion along visual lines.

Please, try that for yourself since I don't have evil installed.

You can paste the following advices into your init-file and try whether they fit your purpose. The functions evil-next-line and evil-previous-line are adviced such that they respect the value of line-move-visual as set by visual-line-mode.

(eval-after-load "evil-commands"
     (defun ad-evil-next-line (count) (evil-line-move (or count 1)))
     (advice-add #'evil-next-line :override #'ad-evil-next-line)
     (defun ad-evil-previous-line (count) (evil-line-move (- (or count 1))))
     (advice-add #'evil-previous-line :override #'ad-evil-previous-line)))
  • 1
    The parent of outline-mode is text-mode, and the parent of org-mode is outline-mode.
    – lawlist
    Commented Jun 7, 2017 at 14:43
  • visual-line-mode soft-wraps the lines as expected, but line-move-visual is not effecting Spacemacs evil mode keybindings: k (line up), j (line down)
    – wolfv
    Commented Jun 7, 2017 at 15:57
  • @user2867994 Could you try describe-key k and describe-key j? Are those keys bound to previous-line and next-line? Maybe evil-mode is setting line-move-visual. Could you verify the value of that variable after loading a text file?
    – Tobias
    Commented Jun 7, 2017 at 17:20
  • @Tobias I appended UPDATE to the main question.
    – wolfv
    Commented Jun 7, 2017 at 20:32
  • @user2867994 I've added some text specific to evil-mode. Please try the suggested key sequences gj and gk. I do not have evil installed and also do not intend to install it, It is a relatively large package and I do not need it.
    – Tobias
    Commented Jun 8, 2017 at 1:51

If you are using general.el:

(general-swap-key nil 'motion
    ;; swap evil-next-line evil-next-visual-line
    "k" "gk"
    "j" "gj")

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.