Frage

I want to customize Emacs so that pressing

ESC : n RET

takes me to line number n

and

ESC : $ RET

takes me to the last line. (That's how the vi editor works.)

How can I achieve this inside my Emacs configuration file? Currently I have this in my .emacs:

(global-set-key (kbd "M-9") 'prev-window)
(global-set-key (kbd "M-0") 'other-window)

I don't want to use any of the off-the-shelf solutions (eg. evil) because they are bloated and mess with my existing shortcuts.

War es hilfreich?

Lösung

Put this in a file and load it (load means execute):

(defun vi-goto-line (arg)
 (interactive "sLine:")
 (message arg)
 (if (string= "$" arg)
  (end-of-buffer)
  (goto-line (string-to-int arg))
 )
)

(global-set-key (kbd "M-:") 'vi-goto-line)

To load it you can use M-xload-file and then enter interactively the path to the file.

Keep in mind that the key combo M-: (which is the same as ESC:) already has a meaning in Emacs, so this now gets cloaked.

Of course you also can load the file from your .emacs by putting (load-file "/path/to/my/file") into the .emacs or put these lines directly into your .emacs file (or any other configuration file which gets loaded)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top