Skip to content

Commit c8065fe

Browse files
author
skywind3000
committed
new quickui#tools#preview_quickfix
1 parent d1d5d06 commit c8065fe

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Trying to share my configuration to my friends, I found that they did't have pat
3434
- [Buffer switcher](#buffer-switcher)
3535
- [Function list](#function-list)
3636
- [Help viewer](#help-viewer)
37+
- [Preview tag](#preview-tag)
38+
- [Preview quickfix](#preview-quickfix)
3739
- [Customize](#customize)
3840
- [How to change border style](#how-to-change-border-style)
3941
- [How to change the color scheme](#how-to-change-the-color-scheme)
@@ -350,6 +352,14 @@ It will not interfere your work, and will immediately close if you move your cur
350352

351353
Usually the syntax highlighting and cursorline will help you when you are using it to peek symbol definitions.
352354

355+
User can scroll the content in the preview window by:
356+
357+
```VimL
358+
quickui#preview#scroll(offset)
359+
```
360+
361+
Parameter `offset` is an integer, above zero to scroll down and below zero to scroll up.
362+
353363
## Tools
354364

355365
Tools are build upon basic widgets.
@@ -395,6 +405,37 @@ See the screenshot:
395405

396406
The only one argument in `display_help` is the help tag name. With this tool, you can read the help text anytime, without creating a new split window.
397407

408+
### Preview tag
409+
410+
Sometimes I just want a glimpse to the definition of the current word under cursor without actually open that file. So, the tag previewer was made for this:
411+
412+
![](images/preview_tag.png)
413+
414+
use it like:
415+
416+
```VimL
417+
nnoremap <F3> :call quickui#tools#preview_tag('')<cr>
418+
```
419+
420+
When you move the cursor around and press `<F3>`, the definition of current `<cword>` under cursor will display in the preview window. If there are multiple definitions, press `<F3>` again will circularly display the next one, and in the command line, you will see the details about how many definitions and source file name.
421+
422+
Don't forget to use `quickui#preview#scroll` to scroll the content in the preview window if you want to see more.
423+
424+
This feature requires ctags databases are loaded correctly in vim. A plugin [gutentags](https://github.com/ludovicchabant/vim-gutentags) can do it for you nicely in the background.
425+
426+
### Preview quickfix
427+
428+
If you have many items in the quickfix window, instead of open then one by one, you are able to press `p` in the quickfix window and preview them in the popup:
429+
430+
```VimL
431+
augroup MyQuickfixPreview
432+
au!
433+
au FileType qf noremap <silent><buffer> p :call quickui#tools#preview_quickfix()<cr>
434+
au FileType qf noremap <silent><buffer> P :call quickui#preview#close()<cr>
435+
augroup END
436+
```
437+
438+
This piece of code setup a `p` keymap in your quickfix window to preview items, and an upper case `P` to close the preview window.
398439

399440
## Customize
400441

autoload/quickui/preview.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ function! s:nvim_autocmd()
196196
endfunc
197197

198198

199+
"----------------------------------------------------------------------
200+
" scroll preview window
201+
"----------------------------------------------------------------------
202+
function! quickui#preview#scroll(offset)
203+
if s:private.state != 0
204+
let winid = s:private.winid
205+
if s:private.winid >= 0
206+
noautocmd call quickui#utils#scroll(winid, a:offset)
207+
noautocmd call quickui#utils#update_cursor(winid)
208+
endif
209+
endif
210+
endfunc
211+
212+
199213
"----------------------------------------------------------------------
200214
" preview file
201215
"----------------------------------------------------------------------

images/preview_tag.png

82.2 KB
Loading

0 commit comments

Comments
 (0)