How to scroll line by line in GNU Emacs?

Simply put, I'm trying to get scroll in emacs, like in vim and most other editors; when I, for example, have two lines from the bottom / top, and I press down / up ( Ctrl - p , n , โ†‘ , โ†“ ), it goes only one line up or down, and not half the screen.

+78
emacs
Jul 15 '09 at 1:23
source share
14 answers

See some suggestions for EmacsWIki:

 (setq scroll-step 1
       scroll-conservatively 10000)
+46
Jul 15 '09 at 1:30
source share

If you want to precisely position the screen, you can use Ctrl-L.

  • By default, it positions the current line in the middle of the screen.

  • ESC 0 Ctrl-L positions the current line at the top.

+45
Jul 15 '09 at 4:33
source share

I'm a bit late to the party, but if you don't mind installing the package, then smooth scrolling ( github , also available on MELPA ) may be what you are looking for - this certainly works for me.

Once you have installed it, you can add the following to your init.el:

(require 'smooth-scrolling) (smooth-scrolling-mode 1) (setq smooth-scroll-margin 5) 

The last line is optional; it starts to scroll closer to the edge of the screen than to it, so you always have a little context. Adjust to taste.

+36
Mar 30 '13 at 22:16
source share

My solution is not to change the default scroll of Emac, but to create a key sequence command from a macro. This way you have a convenient way to scroll one line at a time when you want. Not perfect, but very simple. It just happens that M- (โ†“) and M- (โ†‘) are available, so I used.

Here is how I did it. First, you need to record a macro to scroll one line up and down.

Start macro

 Cx ( 

Scroll down down

 Cu 1 Cv 

Stop macro

 Cx ) 

To scroll up, use

 Cu 1 Mv 

Then you need to name the macro.

 Mx name-last-kbd-macro 

Give it a name when prompted:

 down-one-line 

Then simply use the following to bind the key sequence to the name of this command:

 Mx global-set-key 

And when prompted, use something like:

 M-(down arrow) 

He will then ask you which team you want to link, and you must give him the name that you invented earlier, for example, down one line.

This is where I got this information. You can also find instructions below and elsewhere about adding macros to your .emacs file.

Here to describe the definition of a macro

Here for scroll control

+24
Aug 04 '11 at 18:01
source share

I have been using them in my .emacs file since 2000.

 (global-set-key (quote [M-down]) (quote View-scroll-line-forward)) (global-set-key (quote [M-up]) (quote View-scroll-line-backward)) 

That way, I can save Emacs default behavior and also scroll one line at a time, depending on what I'm doing.

This worked, at least until GNU Emacs 22. I recently upgraded to Emacs 24 and found that View-scroll-line-forward and View-scroll-line-backward no longer available. After some hunting, I found that scrolling up and down and scrolling down-line work. Therefore, if you are using Emacs 24, you can use this.

 (global-set-key (quote [M-down]) (quote scroll-up-line)) (global-set-key (quote [M-up]) (quote scroll-down-line)) 

I basically skipped Emacs 23, so if this is the version you are using, you can experiment with both of the above.

Note: scroll-up-line actually scrolls one line down because the buffer moves one line up.

+20
Apr 26 '13 at 5:01
source share

I will reprogram my arrow keys to perform scroll operations.

 (global-set-key [up] (lambda () (interactive) (scroll-down 1))) (global-set-key [down] (lambda () (interactive) (scroll-up 1))) (global-set-key [left] (lambda () (interactive) (scroll-right tab-width t))) (global-set-key [right] (lambda () (interactive) (scroll-left tab-width t))) 
+12
Jul 15 '09 at 6:16
source share

The simplins do this:

 (global-set-key [M-up] (lambda () (interactive) (scroll-up 1))) (global-set-key [M-down] (lambda () (interactive) (scroll-down 1))) 

then the meta cursor moves up and the meta cursor moves down.

QED Not sure if all of the above people smoked!

+11
Mar 06 '13 at 10:37
source share

I have the following in my .emacs file to enable nice ctrl-up, ctrl-down scroll behavior. I also use this for the mouse wheel.

 (defun scroll-down-in-place (n) (interactive "p") (previous-line n) (scroll-down n)) (defun scroll-up-in-place (n) (interactive "p") (next-line n) (scroll-up n)) (global-set-key [mouse-4] 'scroll-down-in-place) (global-set-key [mouse-5] 'scroll-up-in-place) (global-set-key [C-up] 'scroll-down-in-place) (global-set-key [C-down] 'scroll-up-in-place) 
+4
Jul 15 '09 at 19:07
source share

Mx customize-variable scroll-conservatively

Set the value to 1.

You really don't want to do this.

+2
Jul 15 '09 at 1:35
source share

So that the scrolling "vim" puts this in your .emacs file:

 (defun next-line-and-recenter () (interactive) (next-line) (recenter)) (defun previous-line-and-recenter () (interactive) (previous-line) (recenter)) (global-set-key (kbd "Cn") 'next-line-and-recenter) (global-set-key (kbd "Cp") 'previous-line-and-recenter) 
+2
Jun 24 '14 at 14:36
source share

If you are looking for a quick way to create a scroll effect, type Cn and Cl sequentially, which moves the cursor down and then centers it.

+2
May 27 '15 at 11:34
source share

Since it can be annoying to use M-up , M-down , because it interferes with org-mode, which overloads these commands. To avoid this problem, I personally use the commands that combine M-page-up M-page-down ". Here I defined scrolling up and down to 1 line.

 ;;;scroll by `number-of-lines' without the cursor attached to the screen (global-set-key [M-prior] (lambda () (interactive) (let ((number-of-lines 1)) (scroll-down number-of-lines) (forward-line (- number-of-lines))))) (global-set-key [M-next] (lambda () (interactive) (let ((number-of-lines 1)) (scroll-up number-of-lines) (forward-line number-of-lines)))) ;;;scroll by `number-of-lines' with the cursor attached to the screen (global-set-key [SM-prior] (lambda () (interactive) (let ((number-of-lines 1)) (scroll-down number-of-lines)))) (global-set-key [SM-next] (lambda () (interactive) (let ((number-of-lines 1)) (scroll-up number-of-lines)))) 
+2
Jun 14 '16 at 10:29
source share

If you run emacs in .xsession, in my case setting scroll-conservatively to 100+ will not work, as well as scroll-step 1. But if u starts emacs after X, it works.

0
Jul 10 '15 at 11:09
source share

Just wanted to notice that the line "emacs init file for the interactive command given by jrockaway above:

 Mx customize-variable scroll-conservatively 

is an

 (setq scroll-conservatively 1) 

It works - for the most part - for me. If you do not press the up / down arrow key for too long, you scroll line by line. But if you leave it pressed for 3 seconds or more, at some point you will most likely see that the page has frozen and the cursor has jumped more than one line. But then it will return to scrolling in one line as soon as it reaches the end of the screen, before possibly jumping again after a random number of seconds, etc.

0
Feb 05 '19 at 9:26
source share



All Articles