Reworking some evil keys that conflict by default.

Oh, and adding the evil-text-object designed for Python code.
This commit is contained in:
Howard Abrams 2022-04-27 22:09:03 -07:00
parent 85a1446ca4
commit 608ab39e07
2 changed files with 49 additions and 25 deletions

View file

@ -390,12 +390,20 @@ Can we change Evil at this point? Some tips:
(let ((mode (make-symbol (format "%s-mode" name)))) (let ((mode (make-symbol (format "%s-mode" name))))
(add-to-list 'evil-emacs-state-modes mode))) (add-to-list 'evil-emacs-state-modes mode)))
;; Use escape to get out of visual mode, eh? ;; Use escape to get out of visual mode, but hitting v again expands the selection.
(evil-define-key 'visual global-map (kbd "v") 'er/expand-region) (evil-define-key 'visual global-map (kbd "v") 'er/expand-region)
(evil-mode)) (evil-mode))
#+END_SRC #+END_SRC
While Im pretty good with the VIM keybindings, I would like to play around with the text objects and how it compares to others (including the surround), for instance:
- ~diw~ :: deletes a word, but can be anywhere in it, while ~de~ deletes to the end of the word.
- ~daw~ :: deletes a word, plus the surrounding space, but not punctuation.
- ~xi,w~ :: changes a word that is snake or camel-cased, as in programming languages. The ~x~ can be ~c~ to change, ~d~ to delete, ~y~ to copy, etc.
- ~xis~ :: changes a /sentence,/ and if ~i~ is ~a~, it gets rid of the surrounding whitespace as well. Probably ~das~ and ~cis~.
- ~xip~ :: changes a /paragraph/.
- Surrounding punctuation, like quotes, parenthesis, brackets, etc. Also work, so ~ci)~ changes all the parameters to a function call.
Using the key-chord project allows me to make Escape be on two key combo presses on both sides of my keyboard: Using the key-chord project allows me to make Escape be on two key combo presses on both sides of my keyboard:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package key-chord (use-package key-chord
@ -901,7 +909,7 @@ The [[https://github.com/oantolin/embark/][embark]] project offers /actions/ on
#+END_SRC #+END_SRC
** Evil Snipe ** Evil Snipe
Doom introduced me to [[https://github.com/hlissner/evil-snipe][evil-snipe]] which is similar to =f= and =t=, but does two characters, and can, when configured, search more than the current line: Doom introduced me to [[https://github.com/hlissner/evil-snipe][evil-snipe]] which is similar to =f= and =t=, but does two characters, and can, when configured, search more than the current line. When I use it, I stop and analyze to see the two characters to work on, so Ive changed from the default, single ~s~, to ~g s~ so as not to get it confused with the =evil-surround=.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package evil-snipe (use-package evil-snipe
@ -909,45 +917,53 @@ Doom introduced me to [[https://github.com/hlissner/evil-snipe][evil-snipe]] whi
:init :init
(setq evil-snipe-scope 'visible) (setq evil-snipe-scope 'visible)
:config :config
(evil-define-key '(normal motion operator visual) (evil-define-key '(normal motion operator visual) global-map
"s" #'evil-snipe-s "gs" #'evil-snipe-s
"S" #'evil-snipe-S) "gS" #'evil-snipe-S))
(evil-snipe-mode +1))
#+END_SRC #+END_SRC
It highlights all potential matches, use ~;~ to skip to the next match, and ~,~ to jump back. It highlights all potential matches, use ~;~ to skip to the next match, and ~,~ to jump back.
** Evil Surround ** Evil Surround
I like both [[https://github.com/emacs-evil/evil-surround][evil-surround]] and Henrik's [[https://github.com/hlissner/evil-snipe][evil-snipe]], however, they both start with ~s~, and conflict, and getting them to work together means I have to remember when does ~s~ call sniper and when calls surround. As an original Emacs person, I am not bound by that key history, but I do need them consistent: I like both [[https://github.com/emacs-evil/evil-surround][evil-surround]] and Henrik's [[https://github.com/hlissner/evil-snipe][evil-snipe]], however, they both start with ~s~, and conflict, and getting them to work together means I have to remember when does ~s~ call sniper and when calls surround. As an original Emacs person, I am not bound by that key history, but I do need them consistent, so Im choosing the ~s~ to be /surround/.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package evil-surround (use-package evil-surround
:after evil-snipe :after evil-snipe
:config :config
(evil-define-key '(normal motion operator visual) evil-surround-mode-map (push '(?\" . ("“" . "”")) evil-surround-pairs-alist)
"z" 'evil-surround-edit (push '(?\' . ("" . "")) evil-surround-pairs-alist)
"Z" 'evil-Surround-edit) (push '(?\` . ("`" . "'")) evil-surround-pairs-alist)
(push '(?b . ("*" . "*")) evil-surround-pairs-alist)
(push '(?* . ("*" . "*")) evil-surround-pairs-alist)
(push '(?i . ("/" . "/")) evil-surround-pairs-alist)
(push '(?/ . ("/" . "/")) evil-surround-pairs-alist)
(push '(?= . ("=" . "=")) evil-surround-pairs-alist)
(push '(?~ . ("~" . "~")) evil-surround-pairs-alist)
:hook (text-mode . evil-surround-mode)) ; Don't globally use it on Magit, et. al :hook (text-mode . evil-surround-mode)) ; Don't globally use it on Magit, et. al
#+END_SRC #+END_SRC
Notes: Notes:
- ~cz'"~ :: to convert surrounding single quote string to double quotes. - ~cs({~ :: to convert surrounding parens to curly braces.
- ~dz"~ :: to delete the surrounding double quotes. - ~ds"~ :: to delete the surrounding *double* quotes.
- ~yze"~ :: puts single quotes around the next word. - ~yse"~ :: puts double quotes around the next word… but only if you are at the beginning of the word, otherwise,
- ~yZ$<p>~ :: surrouds the line with HTML =<p>= tag (with extra carriage returns). - ~ysiw'~ :: puts single quotes around the word, no matter where the point is positioned.
- ~yS$<p>~ :: surrouds the line with HTML =<p>= tag (with extra carriage returns).
- ~(~ :: puts spaces /inside/ the surrounding parens, but ~)~ doesn't. Same with ~[~ and ~]~. - ~(~ :: puts spaces /inside/ the surrounding parens, but ~)~ doesn't. Same with ~[~ and ~]~.
** Jump, Jump, Jump! ** Jump, Jump, Jump!
While I grew up on =Control S=, I am liking the /mental model/ associated with the [[https://github.com/abo-abo/avy][avy project]] that allows a /jump/ among matches across all visible windows. I use the ~F18~ key on my keyboard that should be easy to use. While I grew up on =Control S=, I am liking the /mental model/ associated with the [[https://github.com/abo-abo/avy][avy project]] that allows a /jump/ among matches across all visible windows. I use the ~F18~ key on my keyboard that should be easy to use, but ~g o~ seems obvious.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package avy (use-package avy
:init :init
(setq avy-all-windows t (setq avy-all-windows t
avy-single-candidate-jump t avy-single-candidate-jump t
avy-orders-alist avy-orders-alist
'((avy-goto-char . avy-order-closest) '((avy-goto-char . avy-order-closest)
(avy-goto-word-0 . avy-order-closest))) (avy-goto-word-0 . avy-order-closest)))
:config (ha-leader "j" '("jump" . avy-goto-char-timer)) :config (ha-leader "j" '("jump" . avy-goto-char-timer))
:bind ("<f18>" . avy-goto-char-timer)) (evil-define-key '(normal motion operator visual) global-map
"go" #'avy-goto-char-timer)
:bind ("<f18>" . avy-goto-char-timer))
#+END_SRC #+END_SRC
*Note:* The links should be shorter near the point as opposed to starting from the top of the window. *Note:* The links should be shorter near the point as opposed to starting from the top of the window.
** Miscellaneous Keys ** Miscellaneous Keys

View file

@ -84,6 +84,14 @@ use_python() {
fi fi
} }
#+end_src #+end_src
** Editing Python Code
Lets integrate this [[https://github.com/wbolster/evil-text-object-python][Python support for evil-text-object]] project:
#+BEGIN_SRC emacs-lisp
(use-package evil-text-object-python
:hook python-mode . evil-text-object-python-add-bindings)
#+END_SRC
This allows me to delete a Python “block” using ~dal~.
** Docker Environment ** Docker Environment
Docker really allows you to isolate your project's environment. The downside is that you are using Docker and probably a bloated container. On my work laptop, a Mac, this creates a behemoth virtual machine that immediately spins the fans like a wind tunnel. Docker really allows you to isolate your project's environment. The downside is that you are using Docker and probably a bloated container. On my work laptop, a Mac, this creates a behemoth virtual machine that immediately spins the fans like a wind tunnel.