dylanaraps / fff.vim

A plugin for vim/neovim which allows you to use fff as a file opener.
MIT License
104 stars 11 forks source link

Support neovim float term #15

Open hsanson opened 3 years ago

hsanson commented 3 years ago

This tip could be included in the documentation for those interested in using neovim float term instead of a split:

" Floating window with borders for NNN and FFF
" https://github.com/neovim/neovim/issues/9718#issuecomment-559573308
function! s:layout()
  let s:cwin = winnr()
  let height = &lines - (float2nr(&lines / 3))
  let width = float2nr(&columns - (&columns / 3))
  let row = (&lines / 2) - (height / 2)
  let column = (&columns / 2) - (width / 2)
  let opts = {
        \ 'relative': 'editor',
        \ 'row': row,
        \ 'col': column,
        \ 'width': width,
        \ 'height': height,
        \ 'style': 'minimal'
        \ }
  let top = '╭' . repeat('─', width - 2) . '╮'
  let mid = '│' . repeat(' ', width - 2) . '│'
  let bot = '╰' . repeat('─', width - 2) . '╯'
  let lines = [top] + repeat([mid], height - 2) + [bot]
  let s:buf = nvim_create_buf(v:false, v:true)
  call nvim_buf_set_lines(s:buf, 0, -1, v:true, lines)
  let s:win = nvim_open_win(s:buf, v:true, opts)
  set winhl=Normal:Floating
  let opts.row += 1
  let opts.height -= 2
  let opts.col += 2
  let opts.width -= 4
  call nvim_open_win(nvim_create_buf(v:false, v:true), v:true, opts)
  augroup NNNGroup
    autocmd!
    au BufWipeout <buffer> exe 'bw '.s:buf
    au BufWipeout <buffer> exe s:cwin . 'wincmd w'
  augroup END
endfunction
let g:fff#split = 'call ' . string(function('<SID>layout')) . '()'
bogdan-the-great commented 10 months ago

Alternatively you could just run fff in something like toggleterm using e.g. TermExec cmd="fff && exit", which will create floating window with fff.