Find and focus an anchor window
VimL Shell
Latest commit a7d39d9 Jan 6, 2017 @lambdalisue Update

README.md

vital-Vim-Buffer-Anchor

Travis CI AppVeyor Version 1.0.2 Support Vim 7.3.429 or above MIT License Doc

Introductions

This module is used to find/focus a suitable anchor buffer which is used for opening a new buffer from a non-file buffer such as quickfix window.

Use this module to focus an anchor buffer prior to open a new buffer. The following code is an example simple file manager.

let s:Anchor = vital#vital#import('Vim.Buffer.Anchor')

function! s:open_file(opener) abort
  let filename = expand(getline('.'))
  " Note: focus() is not called when 'opener' is pedit or tabedit
  call s:Anchor.focus_if_available(a:opener)
  execute a:opener . ' ' . fnameescape(filename)
endfunction

function! s:open_file_manager(root) abort
  topleft 50 vsplit FileManager
  let candidates = split(glob(a:root . '/*'), "\r\\?\n")
  let candidates = filter(candidates, 'filereadable(v:val)')
  let candidates = map(candidates, 'fnamemodify(v:val, '':~:.'')')
  let candidates = ['File Manager'] + candidates
  call setline(1, candidates)
  nnoremap <buffer> e :<C-u>call <SID>open_file('ed')<CR>
  nnoremap <buffer> s :<C-u>call <SID>open_file('sp')<CR>
  nnoremap <buffer> v :<C-u>call <SID>open_file('vs')<CR>
  nnoremap <buffer> p :<C-u>call <SID>open_file('ped')<CR>
  nnoremap <buffer> t :<C-u>call <SID>open_file('tabe')<CR>
  " Attach an anchoring feature
  call s:Anchor.attach()
endfunction

command! FileManager call s:open_file_manager(getcwd())

Install

Install this repository with your favorite Vim plugin manager and then

:Vitalize . +Vim.Buffer.Anchor

To activate Vim.Buffer.Anchor on your plugin.