0

I find a lot of questions similar to this, but not one with an answer that matches what I need. I'm using spacemacs in evil mode, and I want "new lines" (done with RET in insert mode, or o or O etc) to either:

  1. Just appear with no indentation at all, just like I'm used to in vim

or

  1. Appear with exactly the whitespace prefix of the line that precedes them

How can I acheive one of these?

1

It depends on what is bound to RET or returnin the mode you're looking to modify (note that this key in particular might be different in terminal or graphical environment).

To know what is bound to use C-h k RET. You'll learn what function is bound, on what key map it was asked, and bound function documentation.

For example if it's bound to (newline) and Electric-Indent minor mode is enabled you may want it bound to electric-indent-just-newline. This can be achieved with:

 (define-key found-mode-map (kbd "<return>") 'electric-indent-just-newline)  

As rule of thumb it's a better idea making changes exactly where you need them using the specific mode map key than modifiying the global map.

0

To get (1), just disable electric-indent-mode, e.g. with:

(electric-indent-mode -1)

To get (2), it depends on exactly why and when (e.g. in all buffers, or only in org-mode but not in rust-mode, ...) you want that and how you want it to interact with TAB-indentation.

1
  • I already have (electric-indent-mode -1)
    – singpolyma
    Apr 18 '20 at 23:59
0

This appears to be working for me:

(defun singpolyma/indent-line ()
    "Don't auto indent lines."
    )

(defun dotspacemacs/user-config ()
    ...
    (add-hook 'prog-mode-hook (lambda ()
        (setq indent-line-function 'singpolyma/indent-line)
    ))
    (add-hook 'text-mode-hook (lambda ()
        (setq indent-line-function 'singpolyma/indent-line)
    ))
    ...
)
3
  • That may work, but doesn't comply with indent-line-function documentation.
    – Muihlinn
    Apr 19 '20 at 5:53
  • @Muihlinn curious how not? Documentation says this function is called when a line should be indented. This function does nothing, thus effectively disabling the indentation feature.
    – singpolyma
    Apr 20 '20 at 2:48
  • Perhaps I'm being overzealous here, but part of indent-line-function tells that "If it is called somewhere where auto-indentation cannot be done (e.g. inside a string), the function should simply return ‘noindent’."
    – Muihlinn
    Apr 20 '20 at 6:34

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.