Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created October 25, 2009 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hokaccha/218008 to your computer and use it in GitHub Desktop.
Save hokaccha/218008 to your computer and use it in GitHub Desktop.
" ウインドウ単位で開いたファイルの履歴をたどる
function! FileJumpPush()
if !exists('w:histories')
let w:histories = []
endif
let buf = bufnr('%')
if count(w:histories, buf) == 0
call add(w:histories, buf)
endif
endfunction
function! FileJumpPrev()
if exists('w:histories')
let buf = bufnr('%')
let current = match(w:histories, '^'.buf.'$')
if current != 0 && exists('w:histories[current - 1]')
execute 'buffer ' . w:histories[current - 1]
endif
endif
endfunction
function! FileJumpNext()
if exists('w:histories')
let buf = bufnr('%')
let current = match(w:histories, '^'.buf.'$')
if exists('w:histories[current + 1]')
execute 'buffer ' . w:histories[current + 1]
endif
endif
endfunction
augroup FileJumpAutoCmd
autocmd!
augroup END
autocmd FileJumpAutoCmd BufReadPre * call FileJumpPush()
nnoremap <silent> ,p :<C-u>call FileJumpPrev()<CR>
nnoremap <silent> ,n :<C-u>call FileJumpNext()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment