FZF floating window and fix ESC in fzf buffer

Signed-off-by: Marko Korhonen <marko.korhonen@reekynet.com>
This commit is contained in:
Marko Korhonen 2020-01-07 17:47:06 +02:00
parent 8e49f4b4e3
commit ccf314034a
No known key found for this signature in database
GPG Key ID: 911B85FBC6003FE5
3 changed files with 46 additions and 12 deletions

View File

@ -10,17 +10,6 @@ nmap <C-s> <Plug>MarkdownPreview
nmap <M-s> <Plug>MarkdownPreviewStop
nmap <C-p> <Plug>MarkdownPreviewToggle
" FZF
nmap <C-f> :Files<CR>
nmap <C-g> :Rg<CR>
" Ripgrep command customization
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --hidden --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
set splitbelow
set splitright

View File

@ -6,7 +6,7 @@ let pyxversion=3
let g:suda_smart_edit = 1
" Remap exit terminal mode to esc
tnoremap <Esc> <C-\><C-n>
au TermOpen * tnoremap <buffer> <Esc> <c-\><c-n>
" Use system clipboard
set clipboard=unnamedplus

View File

@ -0,0 +1,45 @@
" FZF in floating window
autocmd! FileType fzf
autocmd FileType fzf call SetFZFoptions()
function SetFZFoptions()
set noshowmode noruler nonumber norelativenumber
tunmap <buffer> <Esc>
endfunction
set winblend=20
hi NormalFloat guibg=None
if exists('g:fzf_colors.bg')
call remove(g:fzf_colors, 'bg')
endif
if stridx($FZF_DEFAULT_OPTS, '--border') == -1
let $FZF_DEFAULT_OPTS .= ' --border'
endif
function! FloatingFZF()
let width = float2nr(&columns * 0.8)
let height = float2nr(&lines * 0.6)
let opts = { 'relative': 'editor',
\ 'row': (&lines - height) / 2,
\ 'col': (&columns - width) / 2,
\ 'width': width,
\ 'height': height }
call nvim_open_win(nvim_create_buf(v:false, v:true), v:true, opts)
endfunction
let g:fzf_layout = { 'window': 'call FloatingFZF()' }
" Keybinds
nmap <C-f> :Files<CR>
nmap <C-g> :Rg<CR>
" Ripgrep command customization
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --hidden --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)