Vim plugins that I use

栏目: IT技术 · 发布时间: 4年前

内容简介:This is an alphabetical list of vim plugins that I use.In C or C++ projects, source and header files often come in pairs. For example, there'sTo work efficiently with multiple files, you need to use several different commands, such as

This is an alphabetical list of vim plugins that I use.

Alternate

In C or C++ projects, source and header files often come in pairs. For example, there's utils.c and utils.h and you often need to edit both files at the same time. With Alternate, you can type the :A command and it will quickly switch between .c and .h files. If you're in a .c file, it will switch to the .h file, and if you're in a .h file, it will switch to the .c file.

Bufexplorer

To work efficiently with multiple files, you need to use several different commands, such as :ls (list buffers), :b (edit a buffer), :bn (next buffer), and :bp (previous buffer). Usually, however, you spend most of your time just typing :bn , :bn , :bn , until you find the right file.

Bufexplorer makes working with multiple files in vim a breeze. It adds the \be key binding that opens a list of all buffers and it lets you quickly switch to another buffer by moving to the line that shows the filename and pressing enter.

Bufferize

Many vim commands are inherited from vi and their output is very primitive. They print the output to the screen and you can't search or copy. If you press the space one too many times, the content disappears. It's nearly impossible to search this text and sometimes you don't even know how to make vim display it again.

Bufferize solves this problem. It takes a vim command and creates a temporary buffer from its output and opens it in a split window. For example, :Bufferize map will show all keyboard mappings in a new window and you can search them. To exit the new window, just use the regular :q command.

Bufferline

Bufferline complements Bufexplorer (above) and makes it even easier to work with multiple files/buffers. It prints a list of all open files together with their buffer numbers in the status line. You can just glance at this list and type :b 5 to switch to the 5th file/buffer or use Bufexporer and hit \be followed by /5 and enter.

Bufkill

If you have two buffers open in a split and you want to close a buffer, you can use the :bd command. Unfortunately, this command also closes the split. Often, you don't want to close the split and want to just close the buffer. In this case, use Buffkill's :BD command, which will close the buffer but leave the split open.

Characterize

Characterize adds the ga shortcut that shows the name of the Unicode character under the cursor, its code point value, and hex value.

Clever-f

This extension improves the f shortcut that is used to find the next character. For example, pressing fa will go to the next letter a . Without this extension, you have to either type fa again to find the next a or press the comma , . With this extension, you can just press f again and it will search the next a character. So, instead of doing fafafafa or fa,,, , you can now do fafff .

Colorscheme-gruvbox

A dark color scheme that I like. Gray background, light green text and functions.

Colorscheme-jellybeans

Another dark color scheme that I like. Black background, light green text, light yellow functions.

Colorscheme-seoul256

Another dark color scheme that I like. Gray background, light blue text, light yellow functions.

Commentary

One of the simplest and quickest commenting plugins. Press gcc to comment out the entire line. Press gc to comment out a visual selection. Press the same shortcuts again to uncomment.

Conflicted

This plugin helps resolving git merge conflicts. Let's say you just pulled code from the project's master branch on github and you got a merge conflict error. To resolve it, you can run the :Conflicted command that this plugin offers. This command creates a three-way diff and puts the results in three vertical split windows. The left split is upstream changes, the middle split is working changes, and the right split is local changes. You can either accept upstream diff or the local diff to resolve the conflict. Conflicted offers two key mappings for quickly accepting the right diff. The dgu command will use the upstream diff and dgl will use the local diff. To resolve the next conflict, use the :GitNextConflict command. If there are no more conflicts, vim will exit, and you can git commit the resolved files.

Ctrlp

This plugin adds the ctrl+p binding that opens a fuzzy file open dialog. For example, if you need to edit math-config.json file, then you can just type some of the letters of filename like mat.js , mjson , or even thfig (letters "th" are last two letters of "math" and "fig" are last three letters of "config"). Ctrlp will immediately narrow down the search list and offer the best match. It can also be used to open mru files (most recently used files) and buffers and you can cycle between file/mru/buffer mode with ctrl+r and ctrl+f shortcuts.

Ctrlp-funky

Ctrlp-funky extends the Ctrlp plugin (above) by adding function finding mode. You can either run the :CtrlPFunky command to immediately open Ctrlp in function search mode, or open Ctrlp by pressing ctrl+p and then press ctrl+r (or ctrl+f ) a couple of times to go to function search mode. For example, if you have the void debug_print() function, you can type vodepr (first two letters of words void, debug, print), hit enter, and vim will jump to the definition of this function.

Ctrlsf

With this plugin, you can quickly search and replace a lot of text. When you run the :CtrlSF pattern command, it creates a results window on the left with all the matches. The results window also has several context lines around the matches so that you know you're looking at the right match. You can now directly make edits in the results window. When you save the results window, the changes will be saved in the files, too. You can also press enter to open each result in the right window and edit it there.

Delimitmate

Delimitmate automatically closes quotes and parenthesis. For example, you type " and it makes it "" and puts your cursor between the quotes.

Diff-enhanced

This plugin adds a new diff visualization method to vimdiff, which tries to minimize the number of differences. When you're in diff mode, enter the :EnhancedDiff patience command and you should get better visualization of the diff.

Dsf

Dsf is short for delete surrounding functions. By pressing dsf in a function call, it will delete the surrounding function name. For example, if you have code like print_r(get_post|s(true)) and your cursor is where the | character is, then when you press dsf , you'll get get_posts(true) as output.

Easy-align

With this extension you can neatly align text in columns. It adds the :EasyAlign command that you can bind to any keyboard shortcut that you want to. When you execute it, it asks for the column separator character and then formats the selected text. For example, to align code so that all = signs were in the same column, you can visually select the lines with the V command, then run :EasyAlign followed by = and then press enter.

Easymotion

Easymotion makes it much quicker to navigate around the file. It adds the \\w shortcut that lets you quickly jump to any word after the cursor. It assigns a unique letter to each word and when you press it next, the cursor instantly jumps to that word. It also adds \\b shortcut that lets you quickly navigate backward. Similarly, if you need to jump to any line above or below, you can use \\k and \\j shortcuts.

Exchange

With the Exchange plugin, you can very quickly swap two words. Go to the first word and press cxw , then go to the second word and press cxw again. Done – you just swapped these two words!

Actually, you can swap not just two words but any two motions. After you press cx , the next shortcut is a motion (a motion is a keyboard shortcut that moves the cursor). For example, to swap two characters, you can do cxl and then cxl again ( l is a motion that moves the cursor one position to the right.) Similarly, to swap two sentences, you can do cxis and cxis again for the second sentence. In this case, the motion is is that selects the entire sentence.

Also, if both motions are the same, just press . to repeat the first motion.

Far

Far makes it easy to find and replace text in multiple files. It adds the :Far pattern1 pattern2 command. When you run this command, it splits the screen in two halves. In the upper half it shows all files and lines that pattern1 matches. In the lower half, it previews the match context. In the upper split, you can use hjkl keys to navigate matches. By default, all matches will be replaced with pattern2 but you can also use the t key to unmark the matches (and use t again to mark them). After you have selected all matches that you want to replace, run the :Fardo command. This command will perform the actual replacement.

Far also is great for grepping all matches. You can use :F pattern command and it will find all pattern matches and display them in two splits, but it won't do the replacement.

Fugitive

With Fugitive, you can use git directly from vim. It adds the :Git command or :G for short that runs git status and shows the result in a split window. You can then use the s keyboard shortcut to stage (git add) a file, u to unstage (git reset) a file. After you stage the files, you can press cc to create a commit. I don't know how to do a git push yet so that's something I still have to learn. It would be pretty handy if I could git push code and deploy without leaving vim, too.

Fzf

Fzf is an alternative to Ctrlp (above). It adds several commands for quickly opening files and switching buffers. These commands are :Files and :Buffers . If you were pressing tab multiple times to complete filenames and buffer names, now you only need to type a few letters of the filename or buffer name. For example, if you need to open options.c file, you can just type opt.c or even just oc and Fzf will offer you the best match.

Fzf-mru

Fzf-mru adds an mru mode that can be accessed via the :FZFMru command. This mode lets you quickly access files that you recently edited. Let's say you worked on a scraper yesterday. Today, when you enter the mru mode, you can just type scra and it will show all files from the scraper project that you worked on yesterday.

Gitgutter

Gitgutter adds two useful things. The first is an extra column on the left-most side of vim that quickly shows git diff information of the current file. You can quickly see which lines were added and changed. The second is the ]c and [c mappings that let you jump between the changed lines.

Goyo

I have recently switched to programming in Goyo mode. When you type the :Goyo command, this plugin centers the content and removes line numbers and status line so that you can focus on distraction-free coding. It's especially great if you also make your vim fullscreen.

Grepper

Grepper improves grepping in vim and adds ripgrep support. You can type :Grepper , then enter your search query, and it will find all matches and load them in the quickfix window. You can then use vim's :cn and :cp commands to navigate to next/previous match or use Unimpaired plugin's (below) shortcuts ]q and [q .

The author of this plugin suggests using it together with the qfenter.vim plugin and it's something I still have to try.

Gv

Gv adds git commit browser to vim. You can run the :GV command and it will show the entire commit tree. You can then view individual diffs by pressing enter or o in the commit window. To exit diff viewer, press q . If you're interested in the git log of the current file only, then use the :GV! command.

Illuminate

Illuminate highlights all occurrences of the word under the cursor in the currently visible buffer. For example, if the cursor is on the word var , then all other var s will be illuminated, too.

Interestingwords

This plugin allows you to highlight multiple words at the same time. It adds the \k shortcut that changes the background color of the word under the cursor as well as all other occurrences of the same word in the file. You can also use n and N shortcuts to jump to the next/previous highlighted word. It's very useful when you're working on complicated code and need to keep track of how multiple variables are used.

Linediff

Linediff allows you to quickly diff two blocks of text. Visually select the first block of text and run the :Linediff command. Then visually select the second block and run the same command again. This plugin will then create a new tab with a vertical split with the diff of two text blocks. If the results look too verbose, run the :EnhancedDiff patience command (from Diff-enhanced plugin, above) to improve the diff.

You can also quickly resolve git merge conflicts with this plugin. If you have a file open with a merge conflict in it, put the cursor between the merge conflict markers <<<<< and >>>>> and run the :LinediffMerge command. The plugin will then automatically create a vertical split with the merge conflict diff. You can then make edits in the left or the right split and automatically resolve the merge by running the :LinediffPick command.

Listtoggle

Once you get to a certain level of proficiency in vim, you'll start using the quickfix window (and sometimes location list windows) all the time. Grep results will go in quickfix, linting errors will go in quickfix, compile errors will go in quickfix, todo lists will go in quickfix. Everything will go in quickfix. You'll be closing and opening quickfix all the time. Unfortunately, there's no easy way to toggle the quickfix window and location list windows. You have to use :copen and :cclose commands to open/close quickfix, and :lopen and :lclose to open/close location list. This is just too much typing.

Listtoggle makes it much easier and adds two shortcuts to quickly toggle them. The \q binding will toggle the quickfix window and the \l binding will toggle the location list window.

Locate

Very often you need to find all occurrences of something in the current file. You don't want a global search, you don't want a search and replace, you don't want any splits, you just an overview of all results. Locate offers exactly that via the :Locate command or :L for short. Just type :L pattern and this plugin will open a quick location list with all occurrences of pattern in the current file. You can toggle the location list with the \l shortcut (offered by Listtoggle plugin, above) and you can navigate through the results via the ]l (next result) and [l (previous result) shortcuts (offered by Unimpaired plugin, below.)

Matchtagalways

This plugin highlights the innermost opening and closing HTML tags that your cursor is positioned in. For example, if you're between <div>cursor here</div> , then this plugin will highlight <div> and </div> tags.

Matchup

Matchup adds the % shortcut that lets you quickly jump between matching pairs of parenthesis. If your cursor is on the { character, then after pressing % it will jump to } . If you press % again, it will jump back to the opening paren. It also adds the z% shortcut that lets you jump forward inside the next pair of parenthesis. Let's say you have a function pri|nt_data("hi", 7) and your cursor is | . Then after pressing z% , you'll be in the function arguments.

Nerdcommenter

Nerdcommenter is another code comment plugin. With Commentary (above) you can quickly toggle comments with the gc shortcut but Nerdcommenter gives more control over comments. For example, you can do multi-line comments with the \cm shortcut and add comments at the end of the line with the \cA shortcut.

Nerdtree

Nerdtree shows the directory and file tree structure of a project in vim's left side. To open and close it, run the :NERDTreeToggle command. I use it so often that it's bound to \t shortcut. When it's open, you can navigate around using the regular hjkl keys. Use the O key to open all directories in the project and then search for files using the regular / search operator. To open the file under the cursor, press the o key. To see the hidden files, use the I key.

Nerdtree-syntax-highlight

This plugin adds syntax highlighting to Nerdtree. Files and directories now have different colors.

Peekaboo

Vim has many different registers. When you copy text, it goes in the " register. When you delete text, it goes in the number registers. Then there are lowercase and uppercase registers for your personal use, and many more.

This plugin previews the registers when you're about to use them. When you press the " key, it opens a register cheat sheet on the right and you can see the contents of each register and choose the right register. You can also press the space key to make the register cheat sheet larger.

Qfgrep

Quickfix is one of vim's greatest features. Unfortunately, once a quickfix list is populated with the results, it's frozen. You can't filter the quickfix list further. This behavior doesn't make much sense because you always want to refine the results.

Qfgrep lets you do that. You can now filter the results in the quickfix window. Use the \g shortcut to filter results, \v to invert filtering results, and \r to restore the original entries. It also adds the :QFGrepPat command that does the same as \g and :QFGrepPatV that does the same as \v .

Qlist

Qlist adds the :Ilist function that is an improved version of vim's built-in :ilist function. The built-in :ilist function comes from a time when computers didn't have much memory so it's not very useful as it prints everything to the screen in a hurry and you can't use the results (also see Bufferize plugin, above). The improved :Ilist function creates a quickfix list from the results. You can now run :Ilist pattern and this plugin will find all uses of the word pattern in the current and included project files and put them in the quickfix window, exactly where you want all the results always to go.

Quickfix-reflector

Not only do you want to filter quickfix results (with Qfgrep, above), you also want to edit the quickfix window as if it was simply just another buffer. This plugin makes the quickfix window modifiable. You can now use dd to delete quickfix entries and i to add new entries. You can also directly edit the quickfix results and when you save the quickfix window via :w , the files will get updated, too.

Ragtag

Ragtag adds three useful keyboard shortcuts for working with HTML tags. The first one is ctrl+x/ that closes any open tag. For example, if you're in a <div> tag, then you can immediately close it and get <div>...</div> . The second is ctrl+xSPACE that creates an opening and closing tags from the word that you just typed. For example, if you typed tag and then immediately pressed this shortcut, then you'll get <tag>|</tag> , where | is the cursor. The third is ctrl+xENTER that works the same way as the previous shortcut but puts an empty line between the two tags.

Repeat

Repeat improves the . command. It lets you repeat commands and actions of other plugins. For example, if you wrap text in quotes using the Surround plugin (below), then pressing . will repeat that.

Rooter

As vim is not an IDE, it has little to no notion of projects and doesn't know what a project's root directory is. When you try to open a file, vim searches either your home directory or some other directory and not the project's directory.

This plugin makes working with projects a tiny bit easier by automatically setting vim's current working directory to project's directory. It does it by looking for the root-most .git directory. Usually, the presence of such directory indicates where the project starts.

Scratch

Vim's documentation mentions a special buffer type called a scratch buffer. This plugin implements it. A scratch buffer is a temporary throw-away buffer. It's useful for making quick notes as you're working on a project. Use the :Scratch command to open it. The cursor will jump to the scratch window at the top. When you move the cursor to another window, the scratch window will automatically close.

Speeddating

In normal mode, ctrl+a and ctrl+x increment and decrement numbers. This plugin makes these keyboard shortcuts also increment dates and clock times. For example, if the cursor is on a string 2000-01-31 , then pressing ctrl+a will make it 2000-02-01 and pressing ctrl+z will make it 2000-01-30 .

Splitjoin

Splitjoin lets you switch code snippets from single-line statements to multi-line statements and back. Let's say you have a single-line HTML snippet <div> hi </div> , then after pressing gS (split), it will turn into a multi-line HTML snippet <div>\n hi \n</div> . If you press gJ (join) on this multi-line snippet will turn it back into a single-line snippet.

Surround

With Surround, you can quickly delete, change, and add matching pairs of surrounding symbols around text. Let's say you have a string "hello world" . By pressing ds" , you'll delete the quotes and the string will become hello world . By pressing cs"' you'll change double quotes to single quotes and the string will become 'hello world' . You can also press cs"<div> and that will change quotes to <div></div> HTML tags and the string will become <div>hello world</div> . If you have a plain string hello world , then to wrap it in quotes, visually select it with v and then press S and enter the wrapping symbol. If you have a single word hello , then to wrap it in single quotes, press ysiw' .

Swap

Swap lets you swap words or comma separated function arguments quickly. For example, if you have a function print(a, b, c) , then you can press g> and it will become print(b, a, c) . Press g< and it will become print(a, b, c) again. You can also enter visual swap mode by pressing gs . Then use hjkl keys to swap arguments around.

Syntax-css3

Syntax highlighting plugin for CSS3.

Syntax-dockerfile

Syntax highlighting plugin for Dockerfiles.

Syntax-html5

Syntax highlighting plugin for HTML5.

Syntax-i3config

Syntax highlighting plugin for i3 window manager configuration files.

Syntax-javascript

Syntax highlighting plugin for JavaScript.

Syntax-json

Syntax highlighting plugin for JSON.

Syntax-nginx

Syntax highlighting plugin for Nginx configuration files.

Syntax-php

Syntax highlighting plugin for PHP.

Syntax-tmux

Syntax highlighting plugin for tmux configuration files.

System-copy

Terminal vim doesn't have the * or + registers that are used for copying and pasting to/from system clipboard. This plugin adds the cp shortcut that copies the selected text or a motion to system clipboard by calling xsel external utility. It also has the cv shortcut for pasting from system clipboard.

Tabular

Tabular does the same as EasyAlign (above). It aligns text in columns. It has an advantage over EasyAlign that you can immediately pass it a regular expression for the alignment. The position where the regular expression matches is where the alignment happens. For example, :Tabular /regex will create neat columns of regex .

Tagalong

This plugin makes it easy to rename pairs of opening/closing HTML tags. You only have to rename one of them and this plugin will automatically rename the other. For example, if you have a <div>...</div> and you rename the opening <div> to <section> , then the closing tag will automatically be renamed to </section> and you'll get <section>...</section> in the output.

Targets

One of the steps in reaching vim mastery is learning to use text objects. Text objects let you operate on entire text constructs rather than individual characters. Vim ships with many text objects already – you can delete words, sentences, paragraphs, and code blocks. This plugin adds a hundred more text objects. For example, you can delete comma separated items with di, or you can change the next comma separated item with cin, .

Tmux-complete

When you're in the flow, a lot is happening at once and you have many tmux windows and panes open. One with git log, another with tests, another one with a man page, etc. Often, you need to get info from a tmux pane into vim. Usually, you have to use your mouse to copy it in but that is very ineffective. With this plugin you can just press ctrl+x ctrl+u in insert mode and complete words from any tmux windows/panes. It will offer a list of all words from all tmux windows/panes.

Traces

When substituting text with the :s/old/new command, you can't see the changes until you execute it. This plugin previews the old match as you type it as well as the substitution part new and you get a visual feedback that shows if you're doing it right.

Ultisnips

Ultisnips is a snippet engine. When you press the tab key, it looks at the last typed token and expands it to a snippet. To make it work, you need to create a language.snippets file and write your snippets there. For example, you can create php.snippets and put an if snippet there if ($1) { $0 } . Now when you're programming PHP and type if and press tab , it will expand to if (|) { } and your cursor will be where the | character is. If you press tab again, it will jump to $0 token between the curly braces if () { | } .

Undoquit

Often, you're just too quick and close a window that you didn't want to close. With this plugin, you can now hit ctrl+w+u and undo a closed window.

Unicode

This plugin lets you quickly search and insert Unicode characters. For example, if you want to insert a Unicode rabbit symbol, you can type rabbit and then press ctrl+x ctrl+z . The typed text rabbit will get substituted with a rabbit emoji.

Unimpaired

Many commands come in pairs. For example, :bn and :bp to go to the next/previous buffer, :cn and :cp that go to the next/previous quickfix list item, :ln and :lp that go to the next/previous location list item, etc. This plugin adds quick shortcuts for these commands. You can now ]b and [b to go to the next/previous buffer, ]q and [q to go to the next/previous quickfix entry, ]l and [l to o to the next/previous location list entry, etc.

Visual-split

Often, you need to keep a comment, a function definition, or a code fragment above the fold so that it's always visible. The usual approach is to split the window with ctrl+w+s and then resize it smaller with 10ctrl+w+- . This plugin merges these two actions. You can now visually select the area and press ctrl+w+gss . The plugin will split the window and resize it to exactly fit the selected lines.

Visual-star-search

Vim has two operators to search for the word under the cursor. They are * (search forward) and # (search backward). Unfortunately, they don't work in visual mode and you can't search for a word with special characters in it. For example, if the word is h#e#l#l#o , then these operators will pick and search one of the letters in this word and that's not what you want.

With this plugin, you can search the visually selected sequence and it can contain any special characters. Use the v command to make a selection and then press * or # to search.

Writeable-search

Writeable-search is similar to CtrlSF (above). It lets you quickly find results and immediately edit them in the results window. When you run the :WritableSearch pattern command, it will grep all files in the current directory for the pattern and open a new tab with the results. You can then edit the results and when you do a :w in the same results window, it will update files with changes. If you already have a list of things to fix in the quickfix window, then you can transfer them to this plugin for editing via the :WritableSearchFromQuickfix command.

See you next time!


以上所述就是小编给大家介绍的《Vim plugins that I use》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

计数组合学(卷2)

计数组合学(卷2)

斯坦利 / 机械工业出版社 / 2004-11-15 / 59.00元

本书介绍了生成函数组合、树、代数生成函数、D有限生成函数、非交换生成函数和对称函数。关于对称函数的论述只适用于研究生的入门课程并着重于组合学方面,尤其是Robinson-Schensted-Knuth算法,还讨论了对称函数与表示论之间的联系。附录(由Sergey Fomin编写)中更深入地讨论了对称函数理论,包括jeu de taquin和Littlewood-richardson规则。另外,书中......一起来看看 《计数组合学(卷2)》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具