All Projects → hlissner → Evil Snipe

hlissner / Evil Snipe

Licence: mit
2-char searching ala vim-sneak & vim-seek, for evil-mode

Projects that are alternatives of or similar to Evil Snipe

Evil Multiedit
Multiple cursors for evil-mode, based on iedit
Stars: ✭ 200 (+2.04%)
Mutual labels:  evil, emacs, emacs-packages
Org Pandoc Import
Save yourself from non-org formats, thanks to pandoc
Stars: ✭ 111 (-43.37%)
Mutual labels:  emacs, emacs-packages
Emacs Which Key
Emacs package that displays available keybindings in popup
Stars: ✭ 1,136 (+479.59%)
Mutual labels:  emacs, emacs-packages
Emacs Solaire Mode
If only certain buffers could be so grossly incandescent.
Stars: ✭ 129 (-34.18%)
Mutual labels:  emacs, emacs-packages
Perfect Margin
[emacs] auto center emacs windows, work with minimap and/or linum-mode
Stars: ✭ 26 (-86.73%)
Mutual labels:  emacs, emacs-packages
Org Evil
Evil extensions for Org-mode.
Stars: ✭ 51 (-73.98%)
Mutual labels:  evil, emacs
Emacs Smart Input Source
Less manual switch for native or OS input source (input method).
Stars: ✭ 130 (-33.67%)
Mutual labels:  evil, emacs
Frontmacs
Package-based, web-centric, customizable, awesome-by-default, acceptance-tested Emacs distribution
Stars: ✭ 445 (+127.04%)
Mutual labels:  emacs, emacs-packages
Elpa
Emacs China ELPA 镜像
Stars: ✭ 137 (-30.1%)
Mutual labels:  emacs, emacs-packages
Super Save
Save Emacs buffers when they lose focus
Stars: ✭ 184 (-6.12%)
Mutual labels:  emacs, emacs-packages
Borg
Assimilate Emacs packages as Git submodules
Stars: ✭ 145 (-26.02%)
Mutual labels:  emacs, emacs-packages
Smart Mode Line
A powerful and beautiful mode-line for Emacs.
Stars: ✭ 809 (+312.76%)
Mutual labels:  emacs, emacs-packages
Evil Collection
A set of keybindings for evil-mode
Stars: ✭ 681 (+247.45%)
Mutual labels:  evil, emacs
Emacs.g
The Emacs Collective
Stars: ✭ 51 (-73.98%)
Mutual labels:  emacs, emacs-packages
God Mode
Minor mode for God-like command entering
Stars: ✭ 570 (+190.82%)
Mutual labels:  emacs, emacs-packages
Doom Emacs
An Emacs framework for the stubborn martian hacker
Stars: ✭ 12,774 (+6417.35%)
Mutual labels:  evil, emacs
Evil
The extensible vi layer for Emacs.
Stars: ✭ 2,265 (+1055.61%)
Mutual labels:  evil, emacs
Evil Org Mode
Supplemental evil-mode keybindings to emacs org-mode
Stars: ✭ 241 (+22.96%)
Mutual labels:  evil, emacs
Evil Mc
Multiple cursors implementation for evil-mode
Stars: ✭ 308 (+57.14%)
Mutual labels:  evil, emacs
Emacs Gdscript Mode
An Emacs package to get GDScript support and syntax highlighting.
Stars: ✭ 132 (-32.65%)
Mutual labels:  emacs, emacs-packages

Release tag MIT MELPA MELPA Stable Build Status

evil-snipe

Sniper!

Evil-snipe emulates vim-seek and/or vim-sneak in evil-mode.

It provides 2-character motions for quickly (and more accurately) jumping around text, compared to evil's built-in f/F/t/T motions, incrementally highlighting candidate targets as you type.

Install

Evil-snipe is available on MELPA.

M-x package-install evil-snipe

(require 'evil-snipe)

evil-snipe comes with two global modes: evil-snipe-mode and evil-snipe-override-mode, and two local modes: evil-snipe-local-mode and evil-snipe-override-local-mode.

You can either a) enable one or both globally:

(evil-snipe-mode +1)
(evil-snipe-override-mode +1)

;; and disable in specific modes
(push 'python-mode evil-snipe-disabled-modes)

;; or disable it manually
(add-hook 'python-mode-hook #'turn-off-evil-snipe-mode)
(add-hook 'python-mode-hook #'turn-off-evil-snipe-override-mode)

Or b) enable one or both locally, where you need it:

(add-hook 'python-mode-hook 'turn-on-evil-snipe-mode
(add-hook 'python-mode-hook 'turn-on-evil-snipe-override-local-mode)

Usage

By default, snipe only binds s (forward)/S (backward) to evil-snipe-s and evil-snipe-S, respectively. In operator mode, snipe is bound to z/Z and x/X (exclusive).

The last snipe can be repeated with s/S after a successful snipe (or with s+RET).

Evil-snipe can override evil-mode's native motions with 1-char sniping:

;; Globally
(evil-snipe-override-mode 1)

;; Or locally
(add-hook 'ruby-mode-hook 'evil-snipe-override-local-mode)

The benefit of this is:

  • Incremental highlighting
  • You can repeat searches with f, F, t and T (ala Clever-F)
  • ; and , are available for repeating searches (and won't interfere with the original maps; they take effect only after a successful snipe)
  • A more streamlined experience in general

Customization

Search scope

These three variables determine the scope of snipes (and the incremental highlighter):

  • evil-snipe-scope (default: line)
  • evil-snipe-repeat-scope (default: whole-line) Scope while repeating searches with evil-snipe-repeat or evil-snipe-repeat-reverse.
  • evil-snipe-spillover-scope (default: nil) Scope to expand to when a snipe fails. Only useful if set to a broader scope than evil-snipe-scope.

These are the possible settings:

Value Description
'line rest of the current line after cursor (vim-seek behavior)
'buffer rest of the buffer after cursor (vim-sneak behavior)
'visible the rest of the visible buffer after cursor
'whole-line same as 'line, but highlights on either side of cursor
'whole-buffer same as 'buffer, but highlights all matches in buffer
'whole-visible same as 'visible, but highlights all visible matches in buffer

Character aliases

Specific characters can be aliased to regex patterns by modifying evil-snipe-aliases.

Examples

  • To map [ to any opening parentheses or bracket in all modes:

    (push '(?\[ "[[{(]") evil-snipe-aliases)
    

    Therefore, sa[ will match a[, a{ or a(

  • To map : to a python function (but only in python-mode):

    (add-hook 'python-mode-hook
      (lambda ()
        (make-variable-buffer-local 'evil-snipe-aliases)
        (push '(?: "def .+:") evil-snipe-aliases)))
    

Faces

  • evil-snipe-first-match-face: The first highlighted match.
  • evil-snipe-matches-face: The rest of the highlighted matches.

Sniping in visual mode

To avoid binding conflicts, evil-snipe has no visual mode bindings. You can add them with:

(evil-define-key 'visual evil-snipe-local-mode-map "z" 'evil-snipe-s)
(evil-define-key 'visual evil-snipe-local-mode-map "Z" 'evil-snipe-S)

Integration into avy/evil-easymotion

This will allow you to quickly hop into avy/evil-easymotion right after a snipe.

(define-key evil-snipe-parent-transient-map (kbd "C-;")
  (evilem-create 'evil-snipe-repeat
                 :bind ((evil-snipe-scope 'buffer)
                        (evil-snipe-enable-highlight)
                        (evil-snipe-enable-incremental-highlight))))

(Thanks to PythonNut for this. More info here)

Conflicts with other plugins

It seems evil-snipe-override-mode causes problems in Magit buffers, to fix this:

(add-hook 'magit-mode-hook 'turn-off-evil-snipe-override-mode)

Appendix

Other settings

  • evil-snipe-enable-highlight (default: t) Highlight first match.
  • evil-snipe-enable-incremental-highlight (default: t) Incrementally highlight all matches in scope.
  • evil-snipe-override-evil-repeat-keys (default: t) Whether or not evil-snipe will override evil's default ; and , mappings with snipe's (when evil-snipe-override-mode is on).
  • evil-snipe-repeat-keys (default t) If non-nil, pressing s/S after a search will repeat it. If evil-snipe-override-evil is non-nil, this applies to f/F/t/T as well.
  • evil-snipe-show-prompt (default t) Whether or not to show the "N>" prompt.
  • evil-snipe-smart-case (default t) If non-nil, searches will be case-insenstive unless your search contains a capital letter.
  • evil-snipe-auto-scroll (default nil) If non-nil, the window will scroll to follow the cursor.
  • evil-snipe-auto-disable-substitute (default: t) Whether or not evil's default substitute mappings (s/S) are unset. They can sometimes interfere with snipe. Must be set before evil-snipe is loaded.
  • evil-snipe-skip-leading-whitespace (default t) If non-nil, sniping will skip over leading whitespace when you search for whitespace.
  • evil-snipe-tab-increment (default nil) If non-nil, pressing TAB in the snipe prompt will increase the size of the snipe buffer.
  • evil-snipe-use-vim-sneak-bindings (default nil) If non-nil, evil-snipe binds z/Z to exclusive sniping in operator state, but leaves the x/X bindings free. This mirrors the default bindings of vim-sneak, and frees up cx/cX to be used by evil-exchange.

Functions

  • evil-snipe-mode / evil-snipe-local-mode
  • evil-snipe-override-mode / evil-snipe-override-local-mode
  • evil-snipe-repeat / evil-snipe-repeat-reverse
  • evil-snipe-s / evil-snipe-S: inclusive 2-char sniping
  • evil-snipe-x / evil-snipe-X: exclusive 2-char sniping
  • evil-snipe-f / evil-snipe-F: inclusive 1-char sniping
  • evil-snipe-t / evil-snipe-T: exclusive 1-char sniping

Default keybindings

(evil-define-key '(normal motion) evil-snipe-local-mode-map
  "s" 'evil-snipe-s
  "S" 'evil-snipe-S)

(evil-define-key 'operator evil-snipe-local-mode-map
  "z" 'evil-snipe-s
  "Z" 'evil-snipe-S
  "x" 'evil-snipe-x
  "X" 'evil-snipe-X)

(evil-define-key 'motion evil-snipe-override-local-mode-map
  "f" 'evil-snipe-f
  "F" 'evil-snipe-F
  "t" 'evil-snipe-t
  "T" 'evil-snipe-T)

(when evil-snipe-override-evil-repeat-keys
  (evil-define-key 'motion map
    ";" 'evil-snipe-repeat
    "," 'evil-snipe-repeat-reverse))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].