3

I'm using evil with this sample org file:

* test0
  test1
  test2

  test3
* test4

    |test5
* test6

When the cursor is on line "test6" and I press { (evil-backward-paragraph), Emacs places the cursor between lines "test2" and "test3". Then, when I press } (evil-forward-paragraph), the cursor goes to "test4". That's not how it works in Vim.

How do I make next/prev paragraph keys place the cursor on the first empty line below/above current cursor position, like in Vim?

  • And what if the cursor is already at an empty line? What behavior do you expect in this case? – Name Aug 26 '15 at 15:00
  • The same which is first empty line above or below current line :) – Kossak Aug 26 '15 at 15:04
  • The functions work as you expect when in text-mode, but not org-mode. That's probably because org-mode uses a different concept of what constitutes a paragraph break. See the variable paragraph-separate. – Dan Aug 26 '15 at 15:28
1

Add these to the org-mode hook:

(setq paragraph-start "\\|[     ]*$")
(setq paragraph-separate "[     ]*$")

(Note that these character classes, the contents of [], contain one space and one literal tab, which may not render correctly in your browser)

These are the paragraph boundaries definitions from text-mode. So:

(add-hook 'org-mode-hook (lambda ()
                           (setq paragraph-start "\\|[  ]*$"
                                 paragraph-separate "[  ]*$")))

Instead of a lambda, you could wrap it in a named function:

(defun my-org-hook ()
  (setq paragraph-start "\\|[    ]*$"
        paragraph-separate "[     ]*$"))
(add-hook 'org-mode-hook #'my-org-hook)
  • I don't know how to add it to "org-mode hook" (just adding these lines to .emacs doesn't work), but I solved this issue by moving to Spacemacs - it works much better there. – Kossak Sep 14 '15 at 14:58
  • if you're using emacs you should get familiar with hooks – Lionel Henry Sep 14 '15 at 18:02
  • @Kossak if you moved to Spacemacs, could you close your issue then? – ReneFroger Mar 12 '16 at 18:54
  • @Kossak: if this answer resolves the problem, could you accept it so that we can close the post as answered? – Dan Mar 12 '16 at 20:35
  • I just checked and using this org-mode hook doesn't make it work like in vim (in org-mode at least, in text files it does, without the hook). – Kossak Mar 18 '16 at 9:49

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.