Wednesday, September 1, 2010

Re: Controlling the cusor in the file browser

On Wednesday 01 September 2010 11:55:27 jyk271 wrote:

> On Aug 26, 11:27 pm, sc <tooth...@swbell.net> wrote:
> > On Thursday 26 August 2010 16:46:34 Charles Campbell wrote:
> > > jyk271 wrote:
> > > > > From the command line I enter `vim`.
> > > >
> > > > I am greeted with the Vim version number etc.
> > > > Then I type ` :e .` , which takes me to the file
> > > > browser. I get the usual long list of files,I move the
> > > > cursor, say to the fourth from the top , enter the file
> > > > and edit it ,so far so good. NOW I use` ^O ` ie.` Ctrl
> > > > O` to get back to the file browser,but instead of
> > > > returning to the name of the file I just opened the
> > > > cursor goes right to the bottom of the list.Otherwise I
> > > > find Vim fantastic!
> > >
> > > I've tried; you'll find netrw has keepj commands all over
> > > the place. I've determined the first place that a jump
> > > table change occurs; it was associated with a put command
> > > (which already had a keepj associated with it). I've
> > > swapped in a call setline() in its stead, accompanied by a
> > > keepj. Unfortunately, the jump table still changes.
> > > So I don't think I can change netrw to fix this.
> > > Unfortunately, when I try doing the commands by hand, the
> > > jump table doesn't change, so I can't submit a problem
> > > report.
> > > In the interim, use
> > >
> > > :Rex
> >
> > ooo -- Rex -- i didn't know about that one
> >
> > here's an alternative i came up with -- it always seemed
> > natural to me when opening netrw to do so with the cursor at
> > the current buffer -- for this i came up with the following
> > function:
> >
> > function! MyExplore(s)
> > if a:s == "t"
> > call MyExploret()
> > return
> > endif
> > let save_locate = @/
> > let @/ = '\<' . escape(expand("%:t"), ' .\')
> > let g:netrw_sort_by = "name"
> > let g:netrw_sort_direction = "normal"
> > if &modified
> > Sexplore .
> > else
> > Explore .
> > endif
> > normal gg
> > try
> > silent normal n
> > normal zz
> > catch
> > endtry
> > let @/ = save_locate
> > endfunction
> >
> > nmap <silent> <S-F11> :call MyExplore('')<CR>
> > imap <silent> <S-F11> <ESC>:call MyExplore('')<CR>
> >
> > i probably don't need the test for &modified any more since
> > setting 'confirm' in my .vimrc, but it looks good in there,
> > so i'm leaving it
> >
> > sc

> Many thanks sc , I'm not familiar with functions in vim , so
> I'm still scratching my head with this one . By the way, is
> this function for an MS. version ? you see I'm on Linux .
> Cheers,
> jyk271

fine, i'm on linux too, although it should work on MS too

the idea with this is to open netrw via S-F11 in either
command or input mode, and when it opens, have the cursor at
the buffer you just invoked it from

it accomplishes that by putting the name of the current buffer
into the "find" register, then performing a "normal n" to
locate that filename in netrw's list

it looks complicated because i save and restore the previous
contents of the find register, wrap the 'normal n' in a
try/catch block to avoid error messages, and open netrw in a
split window if the invoking buffer is modified

oh yes, another obfuscation is the argument that can send me
off to MyExploret() (if it's "t") which is a similar function
that invokes netrw after setting

let g:netrw_sort_by = "time"
let g:netrw_sort_direction = "reverse"

you can see them both in their natural habitat at

http://home.swbell.net/toothpik/.vimrc

enjoy

sc

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment