Thursday, January 2, 2014

Re: Swapping between 3 or 4 buffers [Was: Retaining window layout]

On 01.01.14 15:47, Marcin Szamotulski wrote:
> On 22:47 Wed 01 Jan , Erik Christiansen wrote:
> > We have ^O and ^I to eventually work our way between recent files, via
> > many intervening moves within each file. Are there perhaps variants of
> > ^O and ^I which move back and forth by file, skipping intra-file dances?
> > Maybe it's wishful thinking, but it would be awfully convenient.

> I wrote a map for that, but I haven't made it public, yet:
>
> fun! FileJump(count, ...)
> let backward = (a:0 >= 1 ? a:1 : 'b')
> let ind = (backward == 'b' ? -1 : 1)
> for x in range(a:count)
> let file = expand('%:p')
> while file == expand('%:p')
> let line = line('.')
> if ind == 1
> exe "normal! 1\<C-I>"
> else
> exe "normal! 1\<C-O>"
> endif
> if line == line('.') && file == expand('%:p')
> break
> endif
> endwhile
> endfor
> endfun
> nm <Leader><c-o> :<c-u>call FileJump(v:count1, 'b')<cr>
> nm <Leader><c-i> :<c-u>call FileJump(v:count1, 'f')<cr>

Wow - that's magnificent.

(But it did need a minor tweak to work here.)
When I hit ^O soon enough after the ',' for the mapping to trigger,
the effect was to enter insert mode, and add the text

call FileJump(v:count1, 'b')

at the cursor position. (That's after I'd merely done a couple of
searches in a couple of files, to build a motion history.)

It does though work like a bought one after I remove the <c-u> from in
front of the call. (My .vimrc sports a few other mapped and au calls -
none of them have <c-u>, and have worked fine for a long time. I am
still on Vim 7.3 with patches 1-496. Is that relevant, I wonder?)

To give me time to achieve the keystrokes in the time limit, I've also
changed the mapping from ,^O to just ,o :

nm <Leader>o :call FileJump(v:count1, 'b')<cr>
nm <Leader>i :call FileJump(v:count1, 'f')<cr>

Many thanks for a brilliant addition to Vim's prodigious panoply of
perfect programming partners.

Erik

P.S. Just tried it again, before sending, and it's pure joy to have that
improvement.

--
The 20th Century was about dozens of markets of millions of consumers.
The 21st Century is about millions of markets of dozens of consumers.
- Joe Kraus, dotcom pioneer

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: