Discussion:
question about insert mode and zz
shawn bright
2007-05-04 14:14:29 UTC
Permalink
Hey there all,
i really dig the zz function to get me in the middle of the screen.
i was wondering if there were an insert mode ability to do the same thing.
So if i am writing a long function and get to the bottom of the screen
i can move where i am at to the middle of the screen while still in
insert mode?

thanks for any tips
shawn
Tim Chase
2007-05-04 14:24:07 UTC
Permalink
Post by shawn bright
i really dig the zz function to get me in the middle of the screen.
i was wondering if there were an insert mode ability to do the same thing.
So if i am writing a long function and get to the bottom of the screen
i can move where i am at to the middle of the screen while still in
insert mode?
You can use control+o (that's an "oh" not a "zero") followed by
zz which will enter normal-mode for one command (your "zz") and
then return you to where you were in insert mode. I do exactly
this on a regular basis. I started with the old-school "z." (in
original vi) instead of "zz" (a vim extension) and was irked that
it didn't keep my position...until I learned of zz. I now
regularly use zz/zt/zb instead of the old z./z<enter>/z- commands.

The above can be mapped if you do it often enough to warrant a
single keypress...something like

:inoremap <f4> <c-o>zz

If you want to read about this "temporary normal mode", you can
read the scant details at

:help i_ctrl-o

HTH,

-tim
shawn bright
2007-05-04 15:02:46 UTC
Permalink
yep, that helps,
just did the map, exactly what i was looking for, thanks
shawn
Post by Tim Chase
Post by shawn bright
i really dig the zz function to get me in the middle of the screen.
i was wondering if there were an insert mode ability to do the same thing.
So if i am writing a long function and get to the bottom of the screen
i can move where i am at to the middle of the screen while still in
insert mode?
You can use control+o (that's an "oh" not a "zero") followed by
zz which will enter normal-mode for one command (your "zz") and
then return you to where you were in insert mode. I do exactly
this on a regular basis. I started with the old-school "z." (in
original vi) instead of "zz" (a vim extension) and was irked that
it didn't keep my position...until I learned of zz. I now
regularly use zz/zt/zb instead of the old z./z<enter>/z- commands.
The above can be mapped if you do it often enough to warrant a
single keypress...something like
:inoremap <f4> <c-o>zz
If you want to read about this "temporary normal mode", you can
read the scant details at
:help i_ctrl-o
HTH,
-tim
A.J.Mechelynck
2007-05-04 15:28:25 UTC
Permalink
Post by shawn bright
Hey there all,
i really dig the zz function to get me in the middle of the screen.
i was wondering if there were an insert mode ability to do the same thing.
So if i am writing a long function and get to the bottom of the screen
i can move where i am at to the middle of the screen while still in
insert mode?
thanks for any tips
shawn
Ctrl-O zz

see ":help i_CTRL-O" (that's control-oh, not control-zero).

Or if you're lazy:

:imap <F9> <C-O>zz

then F9 does it.


Best regards,
Tony.
--
The years of peak mental activity are undoubtedly between the ages of
four and eighteen. At four we know all the questions, at eighteen all
the answers.
Halim, Salman
2007-05-04 15:37:30 UTC
Permalink
I know that a function key is a single key, but touch-typists might find
it faster to map it to something like <leader>zz so they don't have to
actually take their hands off the home keys to get to the mapping.

I've set the leader on my system to the comma instead of the backslash,
so it's even faster for me to hit ,zz (which I can do without looking)
than to look at the keyboard while I move my hand off the home keys to
get to the function key.

Here's another one I use (not mine, but I'm afraid I don't remember who
suggested it) occasionally:

map <silent> <Leader>zz :let &scrolloff=999-&scrolloff<CR>:set
scrolloff?<cr>

Hitting \zz (or ,zz for me) changes the scrolloff to a really large
number (well, it toggles between the large number and the original
value, which for me is 3). The behaviour? The cursor line is always
smack in the middle of the screen. Hitting \zz again restores the
original behaviour.

Hope this helps,

Salman.
-----Original Message-----
Sent: Friday, May 04, 2007 11:28 AM
To: shawn bright
Cc: vimlist
Subject: Re: question about insert mode and zz
Post by shawn bright
Hey there all,
i really dig the zz function to get me in the middle of the screen.
i was wondering if there were an insert mode ability to do
the same thing.
Post by shawn bright
So if i am writing a long function and get to the bottom of
the screen
Post by shawn bright
i can move where i am at to the middle of the screen while still in
insert mode?
thanks for any tips
shawn
Ctrl-O zz
see ":help i_CTRL-O" (that's control-oh, not control-zero).
:imap <F9> <C-O>zz
then F9 does it.
Best regards,
Tony.
--
The years of peak mental activity are undoubtedly between the
ages of four and eighteen. At four we know all the
questions, at eighteen all the answers.
Charles E Campbell Jr
2007-05-04 15:54:16 UTC
Permalink
Post by shawn bright
Hey there all,
i really dig the zz function to get me in the middle of the screen.
i was wondering if there were an insert mode ability to do the same thing.
So if i am writing a long function and get to the bottom of the screen
i can move where i am at to the middle of the screen while still in
insert mode?
Others have covered various sorts of maps; however, if you really like
having that cursor in the middle of the screen,
I suggest setting the scrolloff option.

ex. set scrolloff=999

will always keep the current line in the middle of the screen. If you
like some wiggle room, try

ex. set scrolloff=5

Regards,
Chip Campbell

Continue reading on narkive:
Loading...