以下链接在vim中给出了答案,
https://superuser.com/questions/216411/go-to-middle-of-line-in-vim
使用以下脚本
map gm :call cursor(0, virtcol('$')/2)<CR>
但是如何在emacs中做到这一点?把它放在.emacs里面?如何 ?
以下链接在vim中给出了答案,
https://superuser.com/questions/216411/go-to-middle-of-line-in-vim
使用以下脚本
map gm :call cursor(0, virtcol('$')/2)<CR>
但是如何在emacs中做到这一点?把它放在.emacs里面?如何 ?
此功能将光标放在行的中点。以下行将其绑定到gm
(顺便说一下,它破坏了 default evil-middle-of-visual-line
):
(defun middle-of-line ()
"Put cursor at the middle point of the line."
(interactive)
(goto-char (/ (+ (point-at-bol) (point-at-eol)) 2)))
(define-key evil-motion-state-map "gm" 'middle-of-line)
将这些行放入您的.emacs
文件中;该define-key
行应该在初始化的部分之后evil
。(仅供参考:法线状态图继承自运动状态图。)
这样的事情怎么样?
(defun middle-of-line ()
(interactive)
(let ((eol-pos (progn
(end-of-line)
(point)))
(bol-pos (progn
(beginning-of-line)
(point))))
(forward-char (/ (- eol-pos bol-pos) 2))))
我使用这个版本:
(defun aborn/move-middle-of-line (arg)
"Smart move point to the middle of current displayed line."
(interactive "P")
(if (or (bolp) (eolp))
(goto-char (/ (+ (point-at-bol) (point-at-eol)) 2))
(progn
(goto-char (/ (+ (point)
(if arg (point-at-eol) (point-at-bol)))
2)))))