Here is my living cheatsheet, a growing list of vim tips and spacemacs features I find particularly useful.
In Spacemacs, jumps are bound to SPC J. Some of these features help you to navigate around your text or code fast.
You can combine jumps with any command. For instance, d
, delete, followed by a jump, will delete to the jump location.
avy-goto-char-timer
avy-goto-word-or-subword-1
I define some custom shortcuts for the tools I use the most amongst the features above. That way I can jump to words with one keystroke, instead of three.
In your configuration file, init.el (SPC f e d), in the user-config
function, add:
(define-key evil-normal-state-map (kbd "M-s") #'avy-goto-char-timer)
(define-key evil-normal-state-map (kbd "M-w") #'avy-goto-word-1)
To synchronize the settings, you can press SPC f e R.
This will allow you to “search” any character on screen with M-s, and to jump to a word with M-w.
Here are some Vim commands I use to jump a lot:
To add a function text object, add the following function to your configuration file:
(evil-define-text-object evil-outer-function (count)
(interactive)
(save-mark-and-excursion
(mark-defun)
(let ((m (mark)))
(if (looking-back "*/\n")
(progn
(previous-line)
(list m (first (sp-get-comment-bounds))))
(list m (point))))))
And add a key for it in the evil outer text objects keymap:
(define-key evil-outer-text-objects-map "d" 'evil-outer-function)