Skip to content
Myr

Update Neovim floating window example to have border

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent e01266f · Browse files · 1 file+28 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+28 added−13 removed

  • other:+28 added−13 removed

1 file+28 added−13 removed

modified:README-VIM.md+28 added-13 removed
279 unmodified lines
280281```vim282" Using floating windows of Neovim to start fzf283if has('nvim')284 let $FZF_DEFAULT_OPTS .= ' --border --margin=0,2'284 function! FloatingFZF(width, height, border_highlight)285 function! s:create_float(hl, opts)286 let buf = nvim_create_buf(v:false, v:true)287 let opts = extend({'relative': 'editor', 'style': 'minimal'}, a:opts)288 let win = nvim_open_win(buf, v:true, opts)289 call setwinvar(win, '&winhighlight', 'NormalFloat:'.a:hl)290 call setwinvar(win, '&colorcolumn', '')291 return buf292 endfunction293286 function! FloatingFZF()287 let width = float2nr(&columns * 0.9)288 let height = float2nr(&lines * 0.6)289 let opts = { 'relative': 'editor',290 \ 'row': (&lines - height) / 2,291 \ 'col': (&columns - width) / 2,292 \ 'width': width,293 \ 'height': height }294 " Size and position295 let width = float2nr(&columns * a:width)296 let height = float2nr(&lines * a:height)297 let row = float2nr((&lines - height) / 2)298 let col = float2nr((&columns - width) / 2)299295 let win = nvim_open_win(nvim_create_buf(v:false, v:true), v:true, opts)296 call setwinvar(win, '&winhighlight', 'NormalFloat:Normal')300 " Border301 let top = '╭' . repeat('─', width - 2) . '╮'302 let mid = '│' . repeat(' ', width - 2) . '│'303 let bot = '╰' . repeat('─', width - 2) . '╯'304 let border = [top] + repeat([mid], height - 2) + [bot]305306 " Draw frame307 let s:frame = s:create_float(a:border_highlight, {'row': row, 'col': col, 'width': width, 'height': height})308 call nvim_buf_set_lines(s:frame, 0, -1, v:true, border)309310 " Draw viewport311 call s:create_float('Normal', {'row': row + 1, 'col': col + 2, 'width': width - 4, 'height': height - 2})312 autocmd BufWipeout <buffer> execute 'bwipeout' s:frame313 endfunction314299 let g:fzf_layout = { 'window': 'call FloatingFZF()' }315 let g:fzf_layout = { 'window': 'call FloatingFZF(0.9, 0.6, "Comment")' }316endif301317```318319#### Hide statusline320
21 unmodified lines