LoginSignup
0
0

More than 1 year has passed since last update.

Evil で縦方向 f/F (リピート不可 😢)

Last updated at Posted at 2021-12-08

Emacs Advent Calendar 2021 9 日めの記事です。

デモ

うおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおおお

vf-4x.gif

Firefox では画像をクリックしないと gif 画像がアニメーションしませんでした……

コンテキスト

解説
Evil Vim 再現プラグイン
f/F 横方向ジャンプ (Vim バインディング)
縦方向 f/F 縦方向ジャンプ

コード

実装

1 行ずつ移動して目当ての文字を探します。また evil-read-key のおかげで digraph も読めます:

(defun toy/vf--impl (target-char delta-move)
    (let* ((start-point (point))
           (start-col (current-column))
           (jump-point nil))
        (while (and (not jump-point)
                    (eq 0 (forward-line delta-move)))
            (when (and (eq (move-to-column start-col) start-col)
                       (eq (char-after) target-char))
                (setq jump-point (point))))
        (goto-char (or jump-point start-point))
        jump-point))

(defun toy/vf (&optional target-char)
    "Searches forward a character in the same column. Returns the point on jump or nil on failure."
    (interactive)
    (toy/vf--impl (or target-char (evil-read-key)) 1))

(defun toy/vF (&optional target-char)
    "Searches backward a character in the same column. Returns the point on jump or nil on failure."
    (interactive)
    (toy/vf--impl (or target-char (evil-read-key)) -1))

しかし ; キーで検索のリピート……はできないなんちゃって実装です。

Tip

縦方向ジャンプ後にカーソルを画面中央へ持っていくキーバインディング例:

(defun toy/force-center()
    (evil-scroll-line-to-center (line-number-at-pos)))

(evil-define-key 'normal 'global
    " v" (lambda () (interactive) (when (toy/vf) (toy/force-center)))
    " V" (lambda () (interactive) (when (toy/vF) (toy/force-center))))

ご閲覧いただきありがとうございました

 ベター版をお持ちの方はお知らせください

     _(._.)_

真の姿

+---------------------------------+
| ベター版をお持ちの方はお知らせください |
+-------+---------+----------------+
        |         |
        \__(._.)__/
            |  |
            \  \
              \  \
                \  \
                  \  \
                     \ \
                        \\
                           \
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0