Thursday, January 23, 2014

Re: Avoid switching files with ctrl-o

On 23.01.14 10:00, Christian Brabandt wrote:
> I have actually also recently just thought about adding a
> g<C-O>/g<C-I> command to Vim, that would jump by file steps which
> means there would be a built-in way to do what you want.

I'm not sure how many keys need to be pressed simultaneously to produce
g<C-O>, but following a recent thread, I'm using Marcin Szamotulski's
function, on Alt-O & Alt-I:

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

" Alt-O & Alt-I between files, just as ^O & ^I retrace move history:
" Thanks to Marcin Szamotulski.

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

Since that's a lot shorter, I figure that your version does something
beyond the straightforward file hopping which meets all the needs I'm
aware that I have. (So what are we missing out on? :-)

I ask because to my eyes, viml has that quintessentially "perl" property
of being "write only". Perhaps due to decades of 'C' programming, the
only scripting language which I have my head around is awk.

Erik

--
Yes, sometimes Perl looks like line-noise to the uninitiated, but to the
seasoned Perl programmer, it looks like checksummed line-noise with a
mission in life. - The Llama Book

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