summaryrefslogtreecommitdiffstats
path: root/README-VIM.md
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-01-22 17:34:38 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-01-22 17:34:38 +0900
commit4ec403347c803beccffcf7e9f12bacafcb5d24a2 (patch)
treec8bece7d774566e0c05d69127908c3f653572ca6 /README-VIM.md
parente01266ffcbd6e12de655924e63fcbe1ceb75adbf (diff)
Update Neovim floating window example to have border
Diffstat (limited to 'README-VIM.md')
-rw-r--r--README-VIM.md45
1 files changed, 30 insertions, 15 deletions
diff --git a/README-VIM.md b/README-VIM.md
index 8d799cb7..b5e3afe0 100644
--- a/README-VIM.md
+++ b/README-VIM.md
@@ -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