Skip to content

Instantly share code, notes, and snippets.

@LinArcX
Created January 17, 2020 15:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LinArcX/0aba3e0d5876a0e2f856c0bb92c77573 to your computer and use it in GitHub Desktop.
Save LinArcX/0aba3e0d5876a0e2f856c0bb92c77573 to your computer and use it in GitHub Desktop.
"-------------------------------------------------------"
function! CreateCenteredFloatingWindow()
let width = min([&columns - 4, max([80, &columns - 20])])
let height = min([&lines - 4, max([20, &lines - 10])])
let top = ((&lines - height) / 2) - 1
let left = (&columns - width) / 2
let opts = {'relative': 'editor', 'row': top, 'col': left, '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)
call 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)
au BufWipeout <buffer> exe 'bw '.s:buf
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment