3

I have moved from vim to emacs using evil-mode. I've found that I prefer emacs (as long as I can edit text vim style), but I have one small inconvenience. I've found, mainly while writing prose, but also in other situations, that the evil paragraph movement does not behave as I expect.

Here is an example of the unexpected movement. Starting with the cursor/point on the # Heading 1 line and pressing } repeatedly to move forward a paragraph, I have marked with a ~ character where the cursor/point moves:

Example file

# Heading 1

## Heading 2

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Cras mollis velit vitae sem dictum fermentum.
Vivamus id varius urna. Nullam consectetur elit velit, quis molestie est malesuada non.
Aliquam pretium lacinia viverra. Sed mollis libero ac nisl porttitor dictum. Pellentesque a placerat felis.

Vim behaviour

# Heading 1
~
## Heading 2
~
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
~
Cras mollis velit vitae sem dictum fermentum.
Vivamus id varius urna. Nullam consectetur elit velit, quis molestie est malesuada non.
Aliquam pretium lacinia viverra. Sed mollis libero ac nisl porttitor dictum. Pellentesque a placerat felis.
~

Evil behaviour

# Heading 1

## Heading 2

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
~
Cras mollis velit vitae sem dictum fermentum.
Vivamus id varius urna. Nullam consectetur elit velit, quis molestie est malesuada non.
Aliquam pretium lacinia viverra. Sed mollis libero ac nisl porttitor dictum. Pellentesque a placerat felis.
~

This has meant that I cannot use commands involving the paragraph such as dap, yip, etc.

Is there a way to make emacs evil-mode paragraph motions work as they do in vim?

1 Answer 1

1

It may seem as if Evil is incompatible with Vim, but this is not really the case. In Vim paragraphs are separated by boundaries such as the empty line and nroff macros (which can be customized), so if you would ever edit such a file, you'd find that Vim behaves differently than usual. Evil chose to reuse Emacs' forward-paragraph function, this way every major mode can customize what's considered to be a paragraph. If you inspect markdown-mode.el, you'll find that it customized paragraph-start and paragraph-separate.

There's a few ways to work around such modes:

  • Customize the variables back to their default values. As markdown-mode.el sets them in the major mode function, you'll have to use the mode hook:

    (defun my-reset-paragraph-variables ()
      (kill-local-variable 'paragraph-start)
      (kill-local-variable 'paragraph-separate))
    (add-hook 'markdown-mode-hook 'my-reset-paragraph-variables)
    
  • Make forward-evil-paragraph use the default values of the variables:

    (with-eval-after-load 'evil
      (defadvice forward-evil-paragraph (around default-values activate)
        (let ((paragraph-start (default-value 'paragraph-start))
              (paragraph-separate (default-value 'paragraph-separate)))
          ad-do-it)))
    
1
  • Thanks for your answer! Both of the solutions solve my problem with regards to the example I'd given. I am using the second solution as it works across all major modes (not just markdown, but also org, latex, etc.)
    – jamesmaj
    Feb 4, 2018 at 19:17

Your Answer

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

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