This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-31
Channels
- # announcements (5)
- # babashka (105)
- # beginners (92)
- # calva (77)
- # cider (17)
- # cljdoc (8)
- # cljs-dev (8)
- # cljsrn (8)
- # clojure (272)
- # clojure-dev (25)
- # clojure-europe (5)
- # clojure-italy (6)
- # clojure-nl (7)
- # clojure-norway (3)
- # clojure-uk (108)
- # clojurescript (326)
- # code-reviews (4)
- # cursive (6)
- # datomic (37)
- # duct (5)
- # emacs (14)
- # fulcro (23)
- # graphql (1)
- # juxt (1)
- # kaocha (2)
- # leiningen (10)
- # malli (9)
- # music (1)
- # nrepl (12)
- # pathom (21)
- # pedestal (2)
- # planck (4)
- # quil (3)
- # reitit (29)
- # rewrite-clj (10)
- # shadow-cljs (82)
- # spacemacs (29)
- # sql (6)
- # tools-deps (19)
hi, i'd like to bind the key K
in evil mode to be equivalent to the key sequence: k J
. what's the easy way to accomplish that?
@johanatan Would you like to bind to the target of k J
directly or do you want it to emulate the keypress?
You can bind sequences with (spacemacs/set-leader-keys <key> <mapping> [<key> <mapping>...])
(spacemacs/set-leader-keys
"a" some-command)
(spacemacs/set-leader-keys
"b" another-command
"c" third-command)
If you want to emulate a keypress, you can actually pass (kbd <sequence>)
as the target command, and it will be treated as a keyboard macro which emulates that keypress. So for example:
(spacemacs/set-leader-keys
"K" (kbd "SPC k J"))
(This is probably not the correct key sequence.)There are other macros for mode-specific bindings. Three total:
spacemacs/set-leader-keys
spacemacs/set-leader-keys-for-minor-mode
spacemacs/set-leader-keys-for-major-mode
@jack.crawley92 i think emulating the keypress is fine. but is there no way to create an independent key binding without making it a "leader key". I think "leader key" in this context is a bit off the mark as a) there are no follower keys and b) we are talking about editing text in evil mode (vim commands do not require a "SPC X ..." prefix-- e.g., to "join" the current line with the next one you simply press the single key "J". I want to do the same for the single key "K" to join the current line onto the previous line.
You could certainly bind it to the evil mode map too - treating it as a macro is default Emacs behaviour, it's not handled by the spacemacs macro
I think there's another macro (might be a function), evil-define-key
, which acts on the edit state by default - not sure though.
@jack.crawley92 perfect! thank you
i.e., after pressing "K" and then "u" the cursor is left on the top line instead of the bottom one
In that case I wouldn't emulate - wrap the two commands you want to run in another command
(defun join-to-previous (&optional prefix-arg)
(interactive "P")
(first-command prefix-arg)
(second-command prefix-arg))
You might have to call the individual commands interactively for them to behave properly.
It defines the type of prefix argument the command demands. In this case you probably actually want lowercase "p" - that's the numeric prefix argument.