For spacemacs, the canonical way to make small modification as such is to put your configs inside the defun
of dotspacemacs/user-config
inside ~/.spacemacs
file.
If this is the first time you make modifications to this function, it should look like this:
(defun dotspacemacs/user-config ()
"Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
(define-key evil-normal-state-map (kbd "C-s") #'save-buffer)
(define-key evil-insert-state-map (kbd "C-s") #'save-buffer))
Make sure you quit and restart emacs (server or daemon if you uses them) for this to work (Note that closing the emacsclient frame might not be sufficient if your setting allows the daemon/server to persist in background. Use SPC q q for a full restart). In this case, manually evaluate those define-key
expressions will also work for your current session.
But you want to put them inside another file, so please continue your reading.
Explanation:
For most cases in spacemacs when you are inside an actual file where you would want to save, evil-mode
is activated for sure. That why if you follow certain tutorial online, where you might be told to modify C-s inside global-map
, it might not work especially if you are in evil-normal-state
. That's because evil-mode
is a minor mode, whose keymap has higher priority than global-map
.
The above 2 define-key
expressions set C-s in normal
and insert
state of evil-mode
to command save-buffer
, which should be enough for most of your cases.
For spacemacs, ~/.emacs.d/init.el
belongs to spacemacs itself, thus you should not touch it.
If you wanna do something like source keybindings.el
, you would most likely do the following (dotspacemacs/user-config
is a good place to put these two lines):
(defun dotspacemacs/user-config ()
"Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
(add-to-list 'load-path "/path/to/dir") ;;; which contains `keybindings.el'
(load "keybindings"))
where keybindings.el
should contain the above two define-key
expressions.
(NOTE: Other common methods like require
together with provide
requires more elisp knowledge at this time and please refer to the manual.)