mirror of
https://github.com/junegunn/fzf.git
synced 2024-10-26 14:54:28 +03:00
Update Neovim floating window example to have border
This commit is contained in:
parent
e01266ffcb
commit
4ec403347c
@ -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
|
||||
|
||||
let g:fzf_layout = { 'window': 'call FloatingFZF()' }
|
||||
endif
|
||||
" 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(0.9, 0.6, "Comment")' }
|
||||
endif
|
||||
```
|
||||
|
||||
#### Hide statusline
|
||||
|
Loading…
Reference in New Issue
Block a user