42

[vim] Popup window support for both Vim and Neovim · junegunn/fzf@7ceb58b · GitH...

 4 years ago
source link: https://github.com/junegunn/fzf/commit/7ceb58b2aadfcf0f5e99da83626cf88d282159b2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[vim] Popup window support for both Vim and Neovim · junegunn/fzf@7ceb58b · GitHubPermalink

Browse files

[vim] Popup window support for both Vim and Neovim

e.g.
  let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }

Based on the code from junegunn/fzf.vim#821 (comment)
by @lacygoill.

junegunn

committed on Feb 3

Verified
1 parent 293dd76 commit 7ceb58b2aadfcf0f5e99da83626cf88d282159b2
Showing with 111 additions and 61 deletions.
@@ -184,6 +184,7 @@ The following table summarizes the available options.
| `dir` | string | Working directory |
| `up`/`down`/`left`/`right` | number/string | (Layout) Window position and size (e.g. `20`, `50%`) |
| `window` (Vim 8 / Neovim) | string | (Layout) Command to open fzf window (e.g. `vertical aboveleft 30new`) |
| `window` (Vim 8 / Neovim) | dict | (Layout) Popup window settings (e.g. `{'width': 0.9, 'height': 0.6}`) |
`options` entry can be either a string or a list. For simple cases, string
should suffice, but prefer to use list type to avoid escaping issues.
@@ -193,6 +194,16 @@ call fzf#run({'options': '--reverse --prompt "C:\\Program Files\\"'})
call fzf#run({'options': ['--reverse', '--prompt', 'C:\Program Files\']})
```
When `window` entry is a dictionary, fzf will start in a popup window. The
following options are allowed:
- Required:
- `width` [float]
- `height` [float]
- Optional:
- `highlight` [string default `'Comment'`]: Highlight group for border
- `rounded` [boolean default `v:true`]: Use rounded border
`fzf#wrap`
----------
@@ -276,44 +287,17 @@ The latest versions of Vim and Neovim include builtin terminal emulator
- On Terminal Vim with a non-default layout
- `call fzf#run({'left': '30%'})` or `let g:fzf_layout = {'left': '30%'}`
#### Starting fzf in Neovim floating window
#### Starting fzf in a popup window
```vim
" Using floating windows of Neovim to start fzf
if has('nvim')
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(0.9, 0.6, "Comment")' }
endif
" Required:
" - width [float]
" - height [float]
"
" Optional:
" - highlight [string default 'Comment']: Highlight group for border
" - rounded [boolean default v:true]: Use rounded border
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
```
#### Hide statusline

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK