2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Emacsでvimのf、F、; を

Last updated at Posted at 2012-04-29

vimで、カーソル行の 1文字 を検索して飛ぶコマンドがとても便利なのでEmacsでもできる限り再現しようと試みた。

M-j 押した後、次に押した文字がカーソルより右にあればそこに飛ぶ。
M-k 押した後、次に押した文字がカーソルより左にあればそこに飛ぶ。
M-u は前回のコマンドを繰り返す。

(defvar vimlike-f-recent-char nil)
(defvar vimlike-f-recent-func nil)

(defun vimlike-f (char)
  "search to forward char into current line and move point (vim 'f' command)"
  (interactive "cSearch to forward char: ")
  (when (= (char-after (point)) char)
    (forward-char))
  (search-forward (char-to-string char) (point-at-eol) nil 1)
  ;; (migemo-forward (char-to-string char) (point-at-eol) t 1)
  (backward-char)
  (setq vimlike-f-recent-search-char char
        vimlike-f-recent-search-func 'vimlike-f))

(defun vimlike-F (char)
  "search to forward char into current line and move point. (vim 'F' command)"
  (interactive "cSearch to backward char: ")
  (search-backward (char-to-string char) (point-at-bol) nil 1)
  ;; (migemo-backward (char-to-string char) (point-at-bol) t 1)
  (setq vimlike-f-recent-search-char char
        vimlike-f-recent-search-func 'vimlike-F))

(defun vimlike-semicolon ()
  "search repeat recent vimlike 'f' or 'F' search char (vim ';' command)"
  (interactive)
  (if (and vimlike-f-recent-search-char
             vimlike-f-recent-search-func)
      (funcall vimlike-f-recent-search-func vimlike-f-recent-search-char)
    (message "Empty recent search char.")))

(global-set-key "\M-j" 'vimlike-f)
(global-set-key "\M-k" 'vimlike-F)
(global-set-key "\M-u" 'vimlike-semicolon)

C-sなどの普通のインクリメンタルサーチと違って、Enter押す必要がない。
検索コマンドじゃなくてカーソル移動コマンドとして使う。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?