tags:

views:

537

answers:

5

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

+1  A: 

See some of the suggestions on the EmacsWIki:

(setq scroll-step            1
      scroll-conservatively  10000)
ars
Saw it, actually - both answers, yours and jrockway's but on Wiki both of there are not recommended. Unfortunatelly, the reasons for that are not clearly explained. That's why I posted the question, hoping someone's found a method which works without flaws.
ldigas
I can't see why this is not recommended. I've been using similar configuration and it has been working quite well. To assure you further, see this doc of scroll-step(notice the last sentence):*The number of lines to try scrolling a window by when point moves out.If that fails to bring point back on frame, point is centered instead.If this is zero, point is always centered after it moves off frame.If you want scrolling to always be a line at a time, you should set`scroll-conservatively' to a large value rather than set this to 1.
an0
Yeah, looking around a bit more I don't see much more to back up that cautionary note on the wiki. For example, scroll-step seems to be quite common in multiple .emacs files through a google search. Maybe the wiki author is referring to an old version of emacs?
ars
A: 

M-x customize-variable scroll-conservatively

Set it to 1.

You don't really want to do this, though.

jrockway
Saw it, actually - both answers, yours and ars's but on Wiki both of there are not recommended. Unfortunatelly, the reasons for that are not clearly explained. That's why I posted the question, hoping someone's found a method which works without flaws.
ldigas
+2  A: 

If you want to position the screen exactly, 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.

starblue
Don't take this wrong, but what has that got to do with scrolling line by line ? (i.e. the question)
ldigas
Offering an alternative workflow that is (in the author's opinion) more natural with the tool at hand is reasonable. But you should preface it with a disclaimer to that effect, and explain why this approach is "better" if at all possible.
dmckee
@dmckee - I've used vim ... uhmm, a long time. Very good with it. However, since I'm doing something with lisp, I started forcing myself to at least get to grips with emacs again, and this "alternative" way of moving is just too much for me at the moment. Read the tutorial, know it ... but, it's just too weird, imho. Not natural.
ldigas
@Idigas: Sure. That's fair, and you don't need to take starblue's advice. But I think this kind of answer *can* be helpful if it is up-front and includes a compelling explanation.
dmckee
@dmckee - true.
ldigas
+1  A: 

I rebind my arrow keys to perform scrolling 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)))
nullptr
+1  A: 

I have the following in my .emacs file to enable a nice ctrl-up, ctrl-down scrolling behavior. I also use this for the mousewheel.

(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)
Alex B