I use strings like "include/lib-one", "include/lib-two", "src/lib-three" all the time.
Is there an easy way to set shortcuts for these strings, e.g. as C-c 1
, C-c 2
and so on?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityYou can also use define-key
or global-set-key
like this:
(global-set-key (kbd "C-c a") "include/lib-one")
I've used C-c a
instead of C-c 1
because the former is a reserved-for-end-users sequence, whereas the latter is reserved for major modes. See C-hig(elisp) Key Binding Conventions
RET
"\C-j"
in there, and it would be as if you hit C-j
.
Jan 18, 2015 at 11:57
You can use the insert
function to insert strings at point. You can define keybinding to an invocation of this function. For example,
(define-key your-mode-map (kbd "C-c 1") (lambda () (insert "include/lib-one")))
c++-mode
only, you will replace your-mode-map
by c++-mode-map
. Alternatively, if you want it to be defined globally, use global-set-key
.
abbrev
oryasnippet
. But auto-completion for your specific language would be better.