Spacemacs

Here is my living cheatsheet, a growing list of vim tips and spacemacs features I find particularly useful.

Jumps

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.

  • SPC j j: Jump anywhere in visible windows by typing the characters you want to jump to. avy-goto-char-timer
  • SPC j w: Jump to a word in any visible window by typing its first character. avy-goto-word-or-subword-1
  • SPC j i: Jump to a title, a function definition, a class, etc. anywhere inside the current buffer with helm. Type patterns to filter down the list and press RET to jump.
  • SPC s s: Swoop, search the current file for patterns, and navigate to the matching lines. Use Ctrl n and Ctrl p to navigate to the next and previous search results. You can do a lot with this feature, but you can also use it to intuitively move around your file.

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.

Vim commands

Here are some Vim commands I use to jump a lot:

  • *: Search the word under the cursor jumping forward.
  • #: Search the word under the cursor jumping backward.
  • Ctrl d: Move down half a page
  • Ctrl u: Move up half a page
  • Ctrl f: Move forward one page.
  • Ctrl b: Move back one page.

Vim extras

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)