Meino Christian Cramer wrote:
From: Tim Chase <[EMAIL PROTECTED]>
Subject: Re: glued Cursor trick anyone ?
Date: Thu, 21 Sep 2006 05:35:54 -0500
So "nzz" and "Nzz" is more what I want than to "solder" the
cursor onto the screen "forever and ever" with "set
scrolloff=1000". Ah, by the way: The initial /<pattern> still
jumps to a place whereever it wants to. Is there also a neat
trick to "zz" the "/" ("Are you talking vim?", hihihihi ).
Well, though it's a horrible hack, you could do something like
:cnoremap <cr> <cr>zz
which will center the line after *every* ex command...not
necessarily a bad thing, just an odd thing.
To make it selective for only searches may take a lot more work
(I'm not on vim7 at home yet, and vim7 might have a mapping
specific to searching, rather than applying to all
command-lines). I've done them before, where pressing "/" or "?"
creates a pair of command-mode mappings, one that maps <cr> to do
what I want, as well as then unmap the <cr>; the other mappings
dealing with <c-c> and <esc> which would cancel the command-line
mode, and thus need to unmap the <cr> as well. It's a horribly
ugly and opaque hack, and I might be able to dig up a previous
post from the list archives that demonstrates some of this.
However, I'd avoid it if not absolutely necessary.
Just my 0.02 of local currency.
-tim
Hi Tim,
thank you very much for your reply.
If it is not too much effort to you I would like to know these "bad
hacks" -- just to learn a little more about "hacking vim" and not
necessaryly (ough, this world looks also very "hackish"...german
English....) to make them the base of all my later VIMy programming.
Generally I think one can learn a lot about using technique in
ways, no one else has thought about before..... ;O)
Thanks a lot for your help, Tim ! :)))
Keep hacking! (YES!)
mcc
Well, I don't usually use that kind of hack, but let me try to tackle it
as a kind of exercise. The following is untested.
map / :call <SID>Search('/')<CR>
map ? :call <SID>Search('?')<CR>
function <SID>Search(scmd)
let save_so = &scrolloff
if exists('g:cur_center') && g:cur_center
set scrolloff=999
endif
let pattern = input(a:scmd,@/)
exe 'normal' a:scmd . pattern
redraw!
let &scrolloff = save_so
endfunction
This is the best I could manage, but it doesn't take into account the
Ctrl-C or Esc case; OTOH it doesn't require a self-undoing mapping.
The "centering" function of / and ? depends on the global variable
g:cur_center; by default (if it doesn't exists) there is no centering.
To enable centering:
let g:cur_center = 1
To disable it:
let g:cur_center = 0
To toggle it:
let g:cur_center = (exists(g:cur_center) ? (!g:cur_center) : 1)
Each of these can of course be mapped to a key.
Best regards,
Tony.