在Emacs中,是否可以滚动整个可见的缓冲区,但不改变光标位置。例如:光标位于窗口底部附近,我希望查看一些已经滚动到窗口顶部之外的文本,而不移动光标。
编辑:我想C-l
C-l
有点类似于我想要的效果。
在Emacs中,是否可以滚动整个可见的缓冲区,但不改变光标位置。例如:光标位于窗口底部附近,我希望查看一些已经滚动到窗口顶部之外的文本,而不移动光标。
编辑:我想C-l
C-l
有点类似于我想要的效果。
试试这些。根据您的口味更改 M-n
和 M-p
键绑定。
;;; scrollers
(global-set-key "\M-n" "\C-u1\C-v")
(global-set-key "\M-p" "\C-u1\M-v")
(global-set-key "\M-n" (lambda () (interactive) (scroll-up 4)) )
和 (global-set-key "\M-p" (lambda () (interactive) (scroll-down 4)) )
。 - Ben;;;_*======================================================================
;;;_* define a function to scroll with the cursor in place, moving the
;;;_* page instead
;; Navigation Functions
(defun scroll-down-in-place (n)
(interactive "p")
(previous-line n)
(unless (eq (window-start) (point-min))
(scroll-down n)))
(defun scroll-up-in-place (n)
(interactive "p")
(next-line n)
(unless (eq (window-end) (point-max))
(scroll-up n)))
(global-set-key "\M-n" 'scroll-up-in-place)
(global-set-key "\M-p" 'scroll-down-in-place)
previous-line
和next-line
时才有效,否则它会跳过两行。 - E. Sambo这可能会有用。根据EmacsWiki上的滚动页面;
变量
scroll-preserve-screen-position
可能对某些人有用。 当您向下滚动,然后再向上滚动时,光标应该停留在您开始的相同位置。 该值可以通过内置模式M-x scroll-lock-mode
进行切换。
(defun gcm-scroll-down ()
(interactive)
(scroll-up 1))
(defun gcm-scroll-up ()
(interactive)
(scroll-down 1))
(global-set-key [(control down)] 'gcm-scroll-down)
(global-set-key [(control up)] 'gcm-scroll-up)
reference : emacs wiki
根据Bilal的回答:
(global-set-key [(meta down)] (lambda () (interactive) (scroll-down 1)))
(global-set-key [(meta up)] (lambda () (interactive) (scroll-up 1)))
;; Preserve the cursor position relative to the screen when scrolling
(setq scroll-preserve-screen-position 'always)
;; Scroll buffer under the point
;; 'scroll-preserve-screen-position' must be set to a non-nil, non-t value for
;; these to work as intended.
(global-set-key (kbd "M-p") #'scroll-down-line)
(global-set-key (kbd "M-n") #'scroll-up-line)
C
-l
清空屏幕 - Billal Begueradj