Update Neovim floating window example to have border

This commit is contained in:
Junegunn Choi 2020-01-22 17:34:38 +09:00
parent e01266ffcb
commit 4ec403347c
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
1 changed files with 28 additions and 13 deletions

View File

@ -281,24 +281,39 @@ The latest versions of Vim and Neovim include builtin terminal emulator
```vim
" Using floating windows of Neovim to start fzf
if has('nvim')
let $FZF_DEFAULT_OPTS .= ' --border --margin=0,2'
function! FloatingFZF(width, height, border_highlight)
function! s:create_float(hl, opts)
let buf = nvim_create_buf(v:false, v:true)
let opts = extend({'relative': 'editor', 'style': 'minimal'}, a:opts)
let win = nvim_open_win(buf, v:true, opts)
call setwinvar(win, '&winhighlight', 'NormalFloat:'.a:hl)
call setwinvar(win, '&colorcolumn', '')
return buf
endfunction
function! FloatingFZF()
let width = float2nr(&columns * 0.9)
let height = float2nr(&lines * 0.6)
let opts = { 'relative': 'editor',
\ 'row': (&lines - height) / 2,
\ 'col': (&columns - width) / 2,
\ 'width': width,
\ 'height': height }
" Size and position
let width = float2nr(&columns * a:width)
let height = float2nr(&lines * a:height)
let row = float2nr((&lines - height) / 2)
let col = float2nr((&columns - width) / 2)
let win = nvim_open_win(nvim_create_buf(v:false, v:true), v:true, opts)
call setwinvar(win, '&winhighlight', 'NormalFloat:Normal')
" Border
let top = '╭' . repeat('─', width - 2) . '╮'
let mid = '│' . repeat(' ', width - 2) . '│'
let bot = '╰' . repeat('─', width - 2) . '╯'
let border = [top] + repeat([mid], height - 2) + [bot]
" Draw frame
let s:frame = s:create_float(a:border_highlight, {'row': row, 'col': col, 'width': width, 'height': height})
call nvim_buf_set_lines(s:frame, 0, -1, v:true, border)
" Draw viewport
call s:create_float('Normal', {'row': row + 1, 'col': col + 2, 'width': width - 4, 'height': height - 2})
autocmd BufWipeout <buffer> execute 'bwipeout' s:frame
endfunction
let g:fzf_layout = { 'window': 'call FloatingFZF()' }
let g:fzf_layout = { 'window': 'call FloatingFZF(0.9, 0.6, "Comment")' }
endif
```
#### Hide statusline