Thanks very much! But unfortunately I am on Win32. That is to say unfortunately I can not use your code ......
On 2月25日, 下午5时50分, Albie Janse van Rensburg <[email protected]> wrote: > eliweiqiang wrote: > > On 2月23日, 下午7时25分, Filipe <[email protected]> wrote: > > >> I use a kind of bookmark. These lines are from my vimrc file: > > >> nmap \s <Esc>:let cp=getpos(".")<C-CR>:echo cp<C-CR><Esc> "Saves the > >> cursor's position > >> nmap \g <Esc>:call setpos('.',cp)<C-CR><Esc> "Set's the cursor back > >> to the saved location > > >> You must save the position before scrolling. I hope that his will do > >> the trick for you. > > >> Regards, > >> Filipe Teixeira > > > I have a new idea, I want the gVim can save the cursor's position when > > the "current line" changed automatically while I am using the mouse to > > scroll . > > > So what shall I write in the vimrc > > You could probably write some sort of a function that will make a mark > if the <MouseDown> "key" is pressed. Some untested code: > > "-----------script----------- > let s:savedpos = 0 > function! <sid>HandleMouseMove(direction) > " If we have already saved a position, don't do it again > if s:savedpos != 0 > return > endif > let savepos = 0 > " Detect if we're about to scroll out of the viewport > if a:direction == "down" > if line(".") == line("w0") > let savepos = 1 > endif > elseif a:direction == "up" > if line(".") == line("w$") > let savepos = 1 > endif > endif > if savepos == 1 > let s:savedpos = line(".") > endif > endfunction > > function! <sid>ReturnCursorPos() > if s:savedpos != 0 > execute "normal " . s:savedpos . "gg" > let s:savedpos = 0 > endif > endfunction > > noremap <silent> <MouseUp> :call<sid>HandleMouseMove("up")<cr><MouseUp> > noremap <silent> <MouseDown> :call<sid>HandleMouseMove("up")<cr><MouseDown> > noremap <silent> <F10> :call<sid>ReturnCursorPos()<cr> > "-----------script----------- > > Note: this should only work on an X11 GUI. For xterm, refer to > :help xterm-mouse-wheel > for configuration. On Win32 (as I am at the moment, thus the "untested" > bit), unfortunately you'll have to find another way. > > -- > > [ Albie Janse van Rensburg ~http://morph.telspace.co.za] > > Better late than never. > -- Titus Livius (Livy) --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
