Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Support neovim float term #15

Open
hsanson opened this issue Dec 24, 2020 · 1 comment
Open

Support neovim float term #15

hsanson opened this issue Dec 24, 2020 · 1 comment

Comments

@hsanson
Copy link

hsanson commented Dec 24, 2020

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

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants