3 ms·
> Where do I start? best place would be the docs :h nvim_open_win() here is a function that takes a buffer id and creates a floating window based on it anchor
by L0stLink 7y ago
> Where do I start?
best place would be the docs :h nvim_open_win()
here is a function that takes a buffer id and creates a floating window based on it anchored to current cursor position:
let s:buff = 0
let s:buff_max_heigth = 12
function! CreateTempBuffer(buffer) abort
let text = nvim_buf_get_lines(a:buffer, 0, -1, v:true)
if s:buff == 0
let s:buff = nvim_create_buf(v:false, v:true)
endif
call nvim_buf_set_lines(s:buff, 0, -1, v:true, text)
let height = len(text)
if height > s:buff_max_heigth
let height = s:buff_max_heigth
endif
let width = 0
for index in range(len(text))
let line = text[index]
let lwd = strdisplaywidth(line)
if lwd > width
let width = lwd
endif
let text[index] = line
endfor
let width = width + 1
let opts = {'relative': 'cursor', 'width': width, 'height': height, 'col': 0,
\ 'row': 0, 'anchor': 'SW', 'style': 'minimal'}
let win = nvim_open_win(s:buff, v:false, opts)
return win
endfunction