vim-skylight
Search and preview file/symbol under cursor in the floating window.
Rationale
File searching is initially inspired by vim's gf
. It fundamentally works by invoking the build-in function findfile
but asynchronously. Therefore it will never block your actions.
Symbol searching basically depends on pre-generated tag files. Other than using tags, the plugin can also use LSP for searching symbols. Therefore it would be better to have an LSP client (only support coc.nvim by now) installed.
Installation
Plug 'voldikss/vim-skylight'
Only works in NVIM >= 0.4.3
Commands
-
:SkylightPreview
-
:SkylightJumpTo
NOTE: Both commands can also be in visual mode, e.g., '<,'>:SkylightPreview
.
Options
-
g:skylight_width
Type
Number
(number of columns) orFloat
(between 0 and 1). IfFloat
, the width is relative to&columns
.Default:
0.5
-
g:skylight_height
Type
Number
(number of lines) orFloat
(between 0 and 1). IfFloat
, the height is relative to&lines
.Default:
0.5
-
g:skylight_position
Type
String
. The position of the floating window.Available:
'top'
,'right'
,'bottom'
,'left'
,'center'
,'topleft'
,'topright'
,'bottomleft'
,'bottomright'
,'auto'(at the cursor place)
.Default:
'topright'
(recommended) -
g:skylight_borderchars
Type
List
ofString
. Characters for the border.Default:
['─', '│', '─', '│', '╭', '╮', '╯', '╰']
-
g:skylight_jump_command
Type
String
. Command used for:SkylightJumpTo
.Available:
'edit'
,'split'
,'vsplit'
,'tabe'
,'drop'
.Default:
'edit'
Functions
-
skylight#float#has_scroll()
-
skylight#float#scroll({forward}, [amount])
Keymaps
" Configuration example
nnoremap <silent> go :SkylightJumpTo<CR>
nnoremap <silent> gp :SkylightPreview<CR>
The following mappings can be used for scrolling floating widow.
nnoremap <silent><expr> <C-f> skylight#float#has_scroll() ? skylight#float#scroll(1)
nnoremap <silent><expr> <C-b> skylight#float#has_scroll() ? skylight#float#scroll(0)
Highlights
SkylightBorder
, which is linked to Normal
by default, can be used to specify the border style.
" Configuration example
hi SkylightBorder guibg=orange guifg=cyan
Why
For a long time I was hoping to preview file under cursor in a disposable floating window without actually opening it. Then I dug into the web and found some awesome projects, which, however, only support previewing files that are listed in the quickfix window. What I want is to preview the file that occurs anywhere in vim, even those in the builtin terminal window (when I am using gdb's bt
command).
The codes were initially buildup in my personal dotfiles. After the whole feature was almost implemented, I decided to detach them from the dotfiles and reorganize them into a plugin in case of someone who has the same requirement needs it.
Known issues
Sometimes can not find the files in the hidden folders when performing downward searching. That is because vim's file searching doesn't include hidden directories, I am considering using another suitable file-finder cli tool for the plugin but this will not come out in the short term.
Screenshots
- Preview files from quickfix window
- Preview symbol
- Preview files from terminal window