Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When editing a bash script file with emacs, and trying to enter <<<, at the second < emacs insert a template for a here document, like in the following example:



This is not the desired output, because I would enter a literal <<<.

For the moment I resort to entering < < <, and then deleting spaces, but I prefer to being allowed to enter it directly.

share|improve this question
Not that I care too much, but It would be nice to leave a comment for a downvote. – enzotib Sep 5 '11 at 15:08
up vote 9 down vote accepted

There is actually no need for Tom 's custom my-disable-here-document function rebinding the keys. This feature can be enabled and disabled with sh-electric-here-document-mode:

(add-hook 'sh-mode-hook
          (lambda ()
            (sh-electric-here-document-mode -1)))

(It can also be toggled for the active buffer via M-x sh-electric-here-document-mode.)

share|improve this answer
Also: sh-mode-hook didn't work for me, but sh-set-shell-hook did. – Felipe Lema May 20 at 16:37

Bind < to self-insert-command in bash mode and then it will insert only the character.

By default it is bound to sh-maybe-here-document when in bash mode and that function does the auto-insertion.

Here is a way to rebound the key:

(add-hook 'sh-set-shell-hook 'my-disable-here-document)

(defun my-disable-here-document ()
  (local-set-key "<" 'self-insert-command))
share|improve this answer
Can you please give some more information on what to exactly insert in the init file? Sorry, but I am a beginner emacs's user. – enzotib Sep 5 '11 at 10:04
I added a simple example to my answer. It disables the automatic insertion in every kind of shell, not just bash, but probaly that's what you want anyway. – Tom Sep 5 '11 at 10:31
This solution does not work anymore (tested on emacs 24.3), because < is bound to self-insert-command by default. – T. Verron Feb 20 '15 at 15:34

If the only reason you want to disable the here-doc behaviour is that it prevents you from inserting a here-string <<<, then binding C-< to a function which contains (insert "<<<") will work, and still allow the auto here-doc template

(defun my-here-string() 
  "Insert <<< (eg. for a bash here-string)" 
  (insert "<<<"))
(global-set-key (kbd  "C-<") 'my-here-string)
share|improve this answer
Thank you, interesting solution, but I still prefer @Tom's answer, because I consider that completion wrong for a bash script file. – enzotib Sep 5 '11 at 16:37

Type < C-q < <

share|improve this answer
It is shorter than my workaround, and perhaps useful for other situations too, but not exactly what I was looking for. Thank you anyway. – enzotib Sep 5 '11 at 11:48

After taking a look at: http://web.mit.edu/dosathena/sandbox/emacs-19.28/lisp/sh-script.el I came up with this solution:

;; disable the automatic EOF generation in Shell Mode
(defvar sh-use-prefix nil
  "If non-nil when loading, `$' and `<' will be  C-c $  and  C-c < .")
(defvar sh-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (if sh-use-prefix "\C-c<" "<")
      (local-set-key "<" 'self-insert-command))
  "Keymap used in Shell-Script mode.")
share|improve this answer

I enter <<< as M-3< in the shell mode.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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