Question

In Emacs 24.3 (9.0) I'm using the latest yaml-mode installed via el-get-update. When I hit ENTER at the end of a line, it has the unfortunate habit of auto-indenting the line I'm on before inserting the newline.

E.g. starting with this buffer:

foo:
  bar:
    - baz

baz:# <- Cursor here

Hitting enter results in the following buffer:

foo:
  bar:
    - baz

    baz: # <- unwanted indentation!
      # <- Cursor here

I've been working in a lot of YAML files lately, and this is slowly driving me mad. How do I stop it?

UPDATE:

To clarify, I'm not seeing this behavior in any other mode, just yaml-mode. I'm presently on commit 6d40a1dbd4c83f91d70f0e646e7bd8a45acc6fbf from http://github.com/yoshiki/yaml-mode.

Was it helpful?

Solution

As we discovered in the comments, something has caused reindent-then-newline-and-indent to get bound to RET.

I'm not sure where that binding came from, but you should be able to rebind RET to newline-and-indent in YAML mode like this:

(add-hook 'yaml-mode-hook
      '(lambda ()
        (define-key yaml-mode-map "\C-m" 'newline-and-indent)))

or simply to newline if you don't want automatic indenting of the next line:

(add-hook 'yaml-mode-hook
      '(lambda ()
        (define-key yaml-mode-map "\C-m" 'indent)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top