Using z in vim

3,068 views
Skip to first unread message

Ven Tadipatri

unread,
Feb 21, 2012, 11:39:12 AM2/21/12
to vim...@googlegroups.com
Hi,
   There should be a way to make the current line that you're on scroll to the top of the screen right?
I've googled for "vim scrolling" or "vim z". Apparently Google's search is not case sensitive.
   Hitting z twice will make the current line that you're on scroll to the center of the screen.
But I don't want that. I want to make the current line that I'm on scroll to the TOP of the screen.
Is that possible?
  The z key seems a bit overloaded, because zf will create a fold, zo opens it, zc will close a fold, etc.
I vaguely remember hitting some key combination to get this feature of "scrolling to the top of the screen
while still staying on the same line".
  On a somewhat related note, I notice that ZZ will quit. But isn't that exactly what :wq does?
What's the difference?

Thanks,
Ven

Taylor Hedberg

unread,
Feb 21, 2012, 11:41:39 AM2/21/12
to vim...@googlegroups.com
You want `zt`.
signature.asc

Guido Van Hoecke

unread,
Feb 21, 2012, 11:47:50 AM2/21/12
to vim...@googlegroups.com
On Tue, Feb 21, 2012 at 17:39, Ven Tadipatri <vtadi...@gmail.com> wrote:
> Hi,
>    There should be a way to make the current line that you're on scroll to
> the top of the screen right?
> I've googled for "vim scrolling" or "vim z". Apparently Google's search is
> not case sensitive.

No need to google, ask vim:

:help z

shows section 2.5 5 Commands starting with 'z'

/redraw shows z<CR>, zt, z- etc.. etc..

I hope this helps,


Guido

--
The aim of science is to seek the simplest explanations of complex
facts. Seek simplicity and distrust it.
-- Whitehead.

Tim Chase

unread,
Feb 21, 2012, 11:59:05 AM2/21/12
to vim...@googlegroups.com, Ven Tadipatri
On 02/21/12 10:39, Ven Tadipatri wrote:
> But I don't want that. I want to make the current line that I'm on scroll
> to the TOP of the screen.

You want either "zt" or "z<cr>" depending on whether you want to
reset the cursor to the first column:

:help zt
:help z<CR>

> On a somewhat related note, I notice that ZZ will quit. But isn't that
> exactly what :wq does?

One character :)

The both perform identically. I generally prefer building up
what I want to do by combining elements, so I tend to think
progressively in terms of "(w)rite (q) (a)ll really(!)" and then
drop in the respective elements into my command-prompt. I only
use "ZZ" when playing VimGolf.com which saves me one extra
character. :)

-tim


Benjamin R. Haskell

unread,
Feb 21, 2012, 12:10:11 PM2/21/12
to vim...@googlegroups.com
On Tue, 21 Feb 2012, Ven Tadipatri wrote:

> Hi,
>
> There should be a way to make the current line that you're on
> scroll to the top of the screen right? I've googled for "vim
> scrolling" or "vim z". Apparently Google's search is not case
> sensitive.

Use Vim's built-in help:

:help z

gets you the list of all commands starting with z. Similarly for:

:help g
:help CTRL-W
:help [

(Those are the ones that have the most "overloaded" behavior.)


> On a somewhat related note, I notice that ZZ will quit. But isn't that
> exactly what :wq does? What's the difference?

ZZ is faster and easier to type. (Hold shift with right pinky, tap 'z'
twice with left.) Also, it's equivalent to :x, not :wq. The help for
:x explains:

"""
Like ":wq", but write only when changes have been made.
"""

--
Best,
Ben

Tony Mechelynck

unread,
Feb 21, 2012, 1:53:50 PM2/21/12
to vim...@googlegroups.com, Tim Chase, Ven Tadipatri

They do *not* perform identically if the current window isn't modified:
in that case, ZZ wil close the current window (and exit Vim if it's the
last window with the possible exception of a help window), :wq will
write it first even if unmodified.

ZZ can be regarded as faster even than :x (with which it _is_
synonymous) in that it uses a single key twice with no change in shift
status between them.


Best regards,
Tony.
--
And so, men, we can see that human skin is an even more complex and
fascinating organ than we thought it was, and if we want to keep it
looking good, we have to care for it as though it were our own. One
approach is to undergo a painful surgical procedure wherein your skin
is turned inside-out, so the young cells are on the outside, but then
of course you have the unpleasant side effect that your insides
gradually fill up with dead old cells and you explode. So this
procedure is pretty much limited to top Hollywood stars for whom
youthful beauty is a career necessity, such as Elizabeth Taylor and
Orson Welles.
-- Dave Barry, "Saving Face"

Reply all
Reply to author
Forward
0 new messages