• Stars
    star
    167
  • Rank 226,635 (Top 5 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The missing preview window for vim

Preface

This plugin solves a series of user experience problems in vim's preview window and provide a handy way to preview tags, files and function signatures.

Note: Active development on this plugin has stopped. The only future changes will be bug fixes.

Please see vim-quickui.

Installation

Plug 'skywind3000/vim-preview'

Commands

vim-preview introduces several commands:

Command Arguments Description
PreviewTag [tagname] Display the tag in the preview window circularly
PreviewFile [+cmd] filename Display the file in the preview window
PreviewClose N/A Close the preview window
PreviewGoto command Open the previewing file in a non-preview window
PreviewScroll offset Scroll preview window without leaving current window or inser mode
PreviewQuickfix [linenr] Preview file in quickfix list
PreviewSignature [function name] Preview the function signature circularly in the command line

PreviewTag

This command can display tag definition in the preview window circularly:

PreviewTag [tagname]

When the first argument tagname is not provided, current word under cursor is chosen as the tag name.

Every body uses a wide-screen display today, but the default preview window can still only be opened in a new split above or below current window. vsplit is usually better than split when you are working with a 16:9 LCD.

:PreviewTag command will open the preview window on your favorite position (right by default), and the tag name will be highlighted.

Previously, when we got multiple matches, CTRL+] or CTRL+W } will display a list:

	 nr pri kind tag		file
	  1 F	f    mch_delay		os_amiga.c
			mch_delay(msec, ignoreinput)
	> 2 F	f    mch_delay		os_msdos.c
			mch_delay(msec, ignoreinput)
	  3 F	f    mch_delay		os_unix.c
			mch_delay(msec, ignoreinput)
	Enter nr of choice (<CR> to abort):

And you have to choose one of them, this is very annoying and disturbing when you are focusing on editing or navigating the sources.

You don't need to care about this anymore when you use :PreviewTag with a new tag name, the first match will be displayed in the preview window, execute :PreviewTag with the same tag name again, the next match will be used. If there is no more result, the first one is used again.

When you get multiple matches, the current match will be displayed in the command line. (1/2) represents there are two tags matched and this is the first one. Assume that you bind :PreviewTag to F3, all your need is move the cursor on an identifier and repeatly press F3, and all the matches will be displayed on the right preview window circularly.

In the past, scrolling the preview window may involve mode change and window switching. If the preview window is not height enough to view the whole function implementation, you must jump to the preview window press CTRL+F to scroll down then jump back. Leaving and Re-entering insert mode may also be required.

noremap <m-u> :PreviewScroll -1<cr>
noremap <m-d> :PreviewScroll +1<cr>
inoremap <m-u> <c-\><c-o>:PreviewScroll -1<cr>
inoremap <m-d> <c-\><c-o>:PreviewScroll +1<cr>

With the keymaps above, you can use <m-u> and <m-d> directly to scroll preview window without switching window or leaving insert mode.

When you are done, press CTRL+w z to close the preview window or :PreviewGoto to open the previewing file and location in a non-preview window.

PreviewFile

Open arbitrary file in the preview window:

PreviewFile [++opt] [+cmd] filename

Just like PreviewTag but preview a given file, the +cmd could be any vim command which will be executed after opening the file. For example:

PreviewFile +:10 ~/.vimrc

This will open .vimrc in the preview window and jump to line 10.

PreviewFile ++nohl +:10 ~/.vimrc

This will do the same without highlighting line 10.

PreviewGoto

When you want to open the current previewing tag in a non-preview window you can use:

PreviewGoto action

The action can be either edit, split, vsplit or tabe.

PreviewClose

Close the preview window

PreviewClose

A command version of CTRL+W z.

PreviewQuickfix

This command can preview files listed in quickfix window without opening it directly.

PreviewQuickfix [linenr]

The [linenr] parameter is the line number in the quickfix window. The current line number in the quickfix window will be taken if it is not provided.

autocmd FileType qf nnoremap <silent><buffer> p :PreviewQuickfix<cr>
autocmd FileType qf nnoremap <silent><buffer> P :PreviewClose<cr>

We can have the above keymap in quickfix window for convenience.

Now we switch to quickfix window and press p, the item under cursor will be displayed in the preview window immediately, then move around the cursor choose another item and press p again, all files is displayed in the same preview window.

It will not open new split or switch away your current buffer no matter what switchbuf is. When you finished, just use P (upper case) or CTRL+W z to close the preview window.

PreviewSignature

Preview the function signature circularly in the command line:

PreviewSignature[!] [function name]

If the function name is not provided, current word under cursor will be taken as function name. If bang ! sign is given, the nearest function name to the cursor position is chosen.

Function signature is displayed at the bottom including file name and line number. Execute PreviewSignature again, the next signature will be displayed if there are multiple matches, just like PreviewTag.

Calling PreviewSignature without any argument will use the current word under cursor as the function name and PreviewSignature! will find a function name closest to the cursor position.

The bang sign is very useful, think that:

printf(<cursor position>

When you input printf( and you can't remember the parameters, you can execute PreviewSignature! directly in the insert mode. The cursor is on the right side of left paren the function name printf is on the left side, but with the bang sign, function name printf can be find out because it is the nearest function name to the cursor position.

Now we have the below setting:

noremap <F4> :PreviewSignature!<cr>
inoremap <F4> <c-\><c-o>:PreviewSignature!<cr>

Then we can have F4 to display the signature of printf even if we typed a (. And signatures can be displayed automatically by using CursorMovedI autocommands or remapping ( in insert mode.

F4 can be pressed multiple times until you find the right signature when you got multiple results. Remember to set noshowmode before this, displaying signature in insert mode requires turn off showmode option.

Requirements

When you are generating tags file, the n and S fields are required:

ctags --fields=+nS

n will tell ctags add a line number filed in each tag record and S means including function signatures.

vim-preview can work fine without these two fields but it can't tell you line number in the command line and it will guess the function signature which may get an incorrect result sometimes.

Tips

Don't generate tags file manually, use some tags manager like gutentags and gen_tags. They will take good care of your tags files.

When you are using Language Servers with LanguageClient-neovim, You can use PreviewFile to preview definition instead of jump to it:

call LanguageClient#textDocument_definition({'gotoCmd':'PreviewFile'})

Your current buffer will not be switched away, and just close the preview window by CTRL+W z when you are done.

More Repositories

1

kcp

โšก KCP - A Fast and Reliable ARQ Protocol
C
15,270
star
2

awesome-cheatsheets

่ถ…็บง้€ŸๆŸฅ่กจ - ็ผ–็จ‹่ฏญ่จ€ใ€ๆก†ๆžถๅ’Œๅผ€ๅ‘ๅทฅๅ…ท็š„้€ŸๆŸฅ่กจ๏ผŒๅ•ไธชๆ–‡ไปถๅŒ…ๅซไธ€ๅˆ‡ไฝ ้œ€่ฆ็Ÿฅ้“็š„ไธœ่ฅฟ โšก
Shell
11,094
star
3

ECDICT

Free English to Chinese Dictionary Database
Python
5,922
star
4

preserve-cd

Game Preservation Project
3,654
star
5

z.lua

โšก A new cd command that helps you navigate faster by learning your habits.
Lua
2,979
star
6

mini3d

3D Software Renderer in 700 Lines !!
C
2,173
star
7

asyncrun.vim

๐Ÿš€ Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
Vim Script
1,852
star
8

RenderHelp

โšก ๅฏ็ผ–็จ‹ๆธฒๆŸ“็ฎก็บฟๅฎž็Žฐ๏ผŒๅธฎๅŠฉๅˆๅญฆ่€…ๅญฆไน ๆธฒๆŸ“
C++
1,333
star
9

vim-quickui

The missing UI extensions for Vim 9 (and NeoVim) !! ๐Ÿ˜Ž
Vim Script
1,094
star
10

vim

Personal Vim Profile
Vim Script
911
star
11

asynctasks.vim

๐Ÿš€ Modern Task System for Project Building, Testing and Deploying !!
Vim Script
910
star
12

vim-init

่ฝป้‡็บง Vim ้…็ฝฎๆก†ๆžถ๏ผŒๅ…จไธญๆ–‡ๆณจ้‡Š
Vim Script
907
star
13

emake

ไฝ ่ง่ฟ‡็š„ๆœ€็ฎ€ๅ•็š„ GCC/CLANG ้กน็›ฎๆž„ๅปบๅทฅๅ…ท๏ผŒๅฎšไน‰ๅผๆž„ๅปบ๏ผŒๆฏ”ๅ‘ฝไปคๅผๆ›ด็ฎ€ๅ•
Python
802
star
14

PyStand

๐Ÿš€ Python Standalone Deploy Environment !!
C++
736
star
15

FastMemcpy

Speed-up over 50% in average vs traditional memcpy in gcc 4.9 or vc2012
C
585
star
16

preserve-iso

็ป็‰ˆ่ฝฏไปถไฟๆŠคๅทฅ็จ‹
580
star
17

avlmini

AVL implementation which is as fast/compact as linux's rbtree
C
347
star
18

quickmenu.vim

A nice customizable popup menu for vim
Vim Script
275
star
19

vim-auto-popmenu

๐Ÿ˜Ž Display the Completion Menu Automantically (next AutoComplPop) !!
Vim Script
271
star
20

gutentags_plus

The right way to use gtags with gutentags
Vim Script
266
star
21

vim-terminal-help

Small changes make vim/nvim's internal terminal great again !!
Vim Script
243
star
22

translator

ๅ‘ฝไปค่กŒ่šๅˆ็ฟป่ฏ‘ๅทฅๅ…ท๏ผŒๆ”ฏๆŒ่ฐทๆญŒ๏ผŒๅฟ…ๅบ”๏ผŒๆœ‰้“๏ผŒ็™พๅบฆ๏ผŒ่ฏ้œธ๏ผŒ360
Python
227
star
23

ECDICT-ultimate

Ultimate ECDICT Database
219
star
24

GONGLUE

ๅ•ๆœบๆธธๆˆๆ”ป็•ฅ็ง˜็ฑ๏ผˆ1580+ ็ฏ‡๏ผ‰
Python
180
star
25

pixellib

High Quality 2D Graphics Library
C
157
star
26

KanaQuiz

Hiragana/Katakana Speed Reading Quiz in Command Line !! ๐Ÿ˜Ž
Python
147
star
27

images

Static Page
C++
144
star
28

BasicBitmap

Simple and high-performance and platform independent Bitmap class (34% faster than GDI/GDI+, 40% faster than DDraw)
C++
131
star
29

AsyncNet

AsyncNet
C
117
star
30

gobang

Gobang game with artificial intelligence in 900 Lines !!
Python
115
star
31

vim-rt-format

๐Ÿ˜Ž Prettify Current Line on Enter !!
Vim Script
113
star
32

vim-keysound

๐Ÿท Play typewriter sound in Vim when you are typing a letter
Vim Script
112
star
33

Intel2GAS

Convert MSVC Style Inline Assembly to GCC Style Inline Assembly
Python
103
star
34

CloudClip

Your own clipboard in the cloud, copy and paste text with gist between systems !!
Python
79
star
35

googauth

The Python Command-line Reimplementaion of Google Authenticator
Python
74
star
36

LIBLR

Parser Generator for LR(1) and LALR
Python
68
star
37

markpress

Write WordPress in Markdown in Your Favorite Text Editor !! ๐Ÿ˜Ž ๐Ÿ˜Ž
Python
67
star
38

vim-dict

ๆฒกๅŠžๆณ•๏ผŒ่ขซ้€ผ็š„๏ผŒ้‡ๆ–ฐๆ•ด็†ไธ€ไธช่ฏๅ…ธ่กฅๅ…จ็š„ๆ•ฐๆฎๅบ“
Vim Script
56
star
39

terminal

Open Terminal Window to execute command in Windows / Cygwin / Ubuntu / OS X
Python
51
star
40

LeaderF-snippet

Intuitive Way to Use Snippet
Vim Script
46
star
41

nanolib

Cross-Platform Networking Library
C
44
star
42

vim-gpt-commit

๐Ÿš€ Generate git commit message using ChatGPT in Vim (and NeoVim) !!
Python
43
star
43

czmod

๐Ÿš€ Native Module Written in C to Boost z.lua !!
C
42
star
44

collection

ๆฒกๅœฐๆ–นๆ”พ็š„ไปฃ็ ๏ผŒๆ‡’ๅพ—ๅผ€ๆ–ฐ้กน็›ฎไบ†๏ผŒๆ”พ่ฟ™้‡Œๅงใ€‚
Python
40
star
45

atom-shell-commands

Execute user defined shell commands (looking for new maintainers)
JavaScript
36
star
46

vim-navigator

๐Ÿš€ Navigate Your Commands Easily !!
Vim Script
32
star
47

lemma.en

English Lemma Database - Compiled by Referencing British National Corpus
29
star
48

ml

Machine Learning From Scratch
C
28
star
49

memslab

Slab Memory Allocator in Application Layer
C
28
star
50

asyncrun.extra

Extra runners for asyncrun to run your command in Tmux/Gnome-terminal panel, xterm, Floaterm and more.
Vim Script
27
star
51

vim-color-patch

๐ŸŒˆ Load colorscheme patch script automatically !!
Vim Script
25
star
52

zvi

๐Ÿš€ Smallest Vi-clone Text Editor for Windows CLI and SSH session (only 62KB) !!
23
star
53

vim-color-export

๐ŸŒˆ A tool to backport NeoVim colorschemes to Vim !!
Vim Script
20
star
54

QuickNet

UDP Networking Library
C
19
star
55

asmpure

Asmpure is a library written in C for compiling assembly code at run-time
C
16
star
56

docker

Docker Images
Python
16
star
57

VmBasic

ๅŸบไบŽ่™šๆ‹Ÿๆœบ็š„ไปฟ QuickBasic ่ฏญ่จ€
C++
15
star
58

vim-cppman

Read Cppman/Man pages right inside your vim.
Vim Script
15
star
59

language

Language Collection
Python
12
star
60

tcz_cd

Autojump for Total Commander !!
Python
11
star
61

LanguageMark

Native Language Benchmark in Numerous Algorithms
C
9
star
62

abandonware

Abandonware Collection
9
star
63

rogue-clone

A fork of rogue-clone with bug fixes and improvements.
C
8
star
64

vim-proposal

Collection of Proposals for Vim
TypeScript
7
star
65

gosub

Golang Sub-routines for Network Development
Go
7
star
66

winxp-editors

๐Ÿท Text Editors Preservation Project for Windows XP+
Batchfile
7
star
67

cannon

Cross Platform Network Framework
C
6
star
68

shell-scripts

ๅธธ็”จ็š„ๅ‘ฝไปค่กŒ่„šๆœฌๅˆ้›†๏ผŒ่ฎฉไฝ ๆฏๅคฉ็š„ๅ‘ฝไปค่กŒ็”Ÿๆดปๆ›ดๅŠ ้ซ˜ๆ•ˆ
Shell
6
star
69

crtzero

Zero Dependent on CRT (libc)
C
6
star
70

pyp2p

Python P2P Framework
Python
6
star
71

SimdVector

Cross Platform SIMD Vector Math In A Single Header File (SimdVector.h)
C++
5
star
72

support

Win32 Command Line Tools for Development
Python
5
star
73

treasure

Single-file MIT Licensed C/C++ Portable Libraries
C
4
star
74

asyncredis

Async Redis Client for Python
Python
3
star
75

skywind

Personal Blog
HTML
3
star
76

directx9-samples

samples
C++
3
star
77

gfx

Just Another Toy yet !!
C++
3
star
78

script

Script I am using
Python
3
star
79

colors-from-neovim.vim

๐ŸŒˆ Backported NeoVim Colors for Vim
Vim Script
3
star
80

ones

One single file MIT licensed C/C++ Libraries
2
star
81

asclib

Basic Java Network Lib
Java
2
star
82

transmod

Automatically exported from code.google.com/p/transmod
C
2
star
83

toys

My PyQt Desktop Toys
Python
2
star
84

rust

Rust Learning Repository
1
star
85

vile

Vile the vi-clone text editor
C
1
star
86

xvi

A portable multi-file text editor and the smallest full-function vi clone
C
1
star
87

emacs

Personal Emacs Profile
Emacs Lisp
1
star
88

cmake-scratch

Cmake Templates
CMake
1
star