Emulate Typewriter Scrolling in Vim

3

2

I've been using WriteRoom for a while for all my distraction free writing needs. But since I recently decided to move to Vim (or more specifically, MacVim) I've tried to reduce my usage of other text editors.

Vim can reproduce most of the features of WriteRoom, but the only one that prevents me to switch is the "typewriter scrolling" mode. For those who haven't used WriteRoom, this feature lets you write always on the same line (much like a typewriter) so you are always focussed on what you are writing and not distracted by what you have written. All the text scrolls up when you start a new line.

I've done my homework by googling everything that I thought was related, but I only found "plugins" and other Vim configurations which are making Vim look like WriteRoom but never provided the holy feature (maybe I've looked with the wrong keywords because I'm not a native speaker).

Although I found this article saying that it's possible with a simple setting I couldn't make it work, be it in the Terminal or in MacVim... If that works for you, I'd be glad to hear how (I've started with a blank .vimrc maybe you need to active some other stuff).

This feature is not very useful when it comes down to code, so I wouldn't be surprised if it wasn't possible out of the box. In this case, if you have any leads on how I could script that (even though I'm not familiar with scripting Vim, I can look into it), then I might try to make a small plugin for that.

MathieuLoutre

Posted 2011-12-15T11:55:43.137

Reputation: 133

What is the difference to the normal behaviour of vim? If you are on the last line and press enter or wrap around, the text scrolls up and you keep writing on the last line. – Nikodemus RIP – 2011-12-15T12:43:26.183

The difference is that the last line I am talking about is in fact in the middle of the screen so you never have to scroll or look down. You stare at the same line all the time while writing. Although you're right, if you reduce the window to half the size and write on last visible line, then you'd be able to reproduce the behaviour. It's just not exactly what I was looking for. – MathieuLoutre – 2011-12-15T13:26:06.373

Answers

6

set scrolloff=999 has been working perfectly, here but I found it annoying in the long run.

It doesn't depend on anything else beside Vim not being in compatible mode. Simply adding it to your ~/.vimrc is enough.

romainl

Posted 2011-12-15T11:55:43.137

Reputation: 19 227

Two things about the scrolloff=999 trick. #1 is that you can assign a shortcut to toggle it by mapping one to :let &scrolloff=999-&scrolloff<CR>. #2 is that it only really works when you have hard wrapping turned on, because a whole paragraph of soft-wrapped text is treated as one line, i.e. very awkwardly. – zelk – 2014-07-02T08:13:16.177

Ok, I reset everything and just add the scrolloff and the nocompatible mode in the .vimrc and it seems to work although it doesn't reproduce the feature in WriteRoom fully.

The problem now is that it does write everything on the same line, but this line is not always in the middle of the screen. This behaviour is somewhat more flexible but is there any way to force the cursor at the middle of the screen now?

Thank you very much for answering! – MathieuLoutre – 2011-12-15T13:31:10.530

Just so you know, set nocompatible is not needed: it is implied by the presence of a ~/.vimrc. I don't think it's possible to stay in the middle when on the first lines of the document. – romainl – 2011-12-15T14:10:51.963

The behaviour I would like is the following: Write normally until you hit the middle, and from the middle no being able to move the cursor down (every line skip will put the cursor on the same line (middle of the screen)). Do you think it's scriptable? If so, any ressources to point to? Anyway, cheers for following the answer :) – MathieuLoutre – 2011-12-15T14:23:03.800

Well, the behaviour you describe is exactly what I get with set scrolloff=999. – romainl – 2011-12-15T16:13:22.793

Ok, I should probably give it one more go before fiddling with scripting I guess. Thank you again! – MathieuLoutre – 2011-12-15T19:17:05.367

Ok, for the record, it seems to work only when you've reached the bottom (and not the middle). Once you've reached the bottom (you have enough lines to fill the whole visible space), then if you edit a line in the middle and add more line then it will do the typewriter scrolling. I'll see what I can do. – MathieuLoutre – 2011-12-15T19:37:29.663

0

I tried set setscrolloff=999, which appears to be the official solution to this, but as noted in the comments, it only worked for me after creating lines ahead of the cursor.

I've only been using Vim for a week, so I'm not an expert and I don't know if this is the best alternative, but you could add :inoremap <CR> <CR><Esc>zzi to your vimrc. At least that way your current line (i.e. paragraph) is always centered once you reach the middle of the screen.

Jon.D.

Posted 2011-12-15T11:55:43.137

Reputation: 113