For example, consider this block of code: Other useful features are the "Sexy Comment," triggered by Leader+cs, which creates a fancy comment block using the multi-line comment character.
NERD Commenter also understands counts, so you can provide a count n followed by the command to change n lines together. In Visual mode, you can select multiple lines and toggle their status at the same time. The standard Vim Leader key is the \ character. The easiest way to get started is by pressing Leader+Space to toggle the current line between commented and uncommented. NERD Commenter integrates with the standard Vim filetype plugin, so it understands several programming languages and uses the appropriate commenting characters for single or multi-line comments.
With this plugin installed, you can select one or several lines of code and change them to comments with the press of a button. The NERD Commenter plugin adds code-commenting functions to Vim, similar to the ones found in an integrated development environment (IDE). If you have automatic indentation on, Auto Pairs inserts the paired character in the proper indented position when you press Return/Enter, saving you from finding the correct position and typing the required spaces or tabs.Ĭonsider this Go code block for instance:Īuto Pairs offers many other options (which you can read about on GitHub), but even these basic features will save time. Conversely, if you use the Backspace key to delete the opening bracket, Auto Pairs deletes the corresponding closing bracket. In its most basic functionality, Auto Pairs inserts the corresponding closing character when you type an opening character. This is very useful for writing code, since most programming languages use pairs of characters in their syntax-such as parentheses for function calls or quotation marks for string definitions. The Auto Pairs plugin helps insert and delete pairs of characters, such as brackets, parentheses, or quotation marks. I tend to use Vim's robust native capabilities for most of what I do, but there are a number of plugins developed by the open source community that extend Vim's capabilities, improve your workflow, and make you even more productive.įollowing are five plugins that are useful when using Vim to write code in any programming language.
Vim has many great features and, once you get used to it, you become very productive. I use Vim to write code, configuration files, blog articles, and pretty much everything I can do in plaintext.
Open your Vim editor and run the command :PlugInstall to install the plugin. After adding the plugin names, save the file. In this case, we want to install NERDTree. I dont know who needs to hear this, but if you are. I have used Vim as a text editor for over 20 years, but about two years ago I decided to make it my primary text editor. call plug end () All plugins that you intend to install should be placed within the line call plugbegin () and call plugend (). Vimwiki, a vim plugin for making your own personal wiki for notes, project management, to-do lists, etc.