Skip to content
Snippets Groups Projects
Unverified Commit 4ec40334 authored by Junegunn Choi's avatar Junegunn Choi
Browse files

Update Neovim floating window example to have border

parent e01266ff
No related branches found
No related tags found
No related merge requests found
......@@ -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()
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 }
let win = nvim_open_win(nvim_create_buf(v:false, v:true), v:true, opts)
call setwinvar(win, '&winhighlight', 'NormalFloat:Normal')
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
" 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)
" 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment