Contents:

Free Python Course ➞ Mini-course for beginners and for Experienced coders. 4 cool projects in the portfolio, live communication with the speaker. Click and find out what you can learn in the course.
Learn moreOver the course of 16 lessons, we'll cover in detail all the essential aspects needed to successfully get started with Vim. You will gain practical skills and knowledge that will help you effectively use this powerful text editor.
- the history of text editors;
- working in insert mode, command mode, command line mode, visual mode;
- using regular expressions and creating macros;
- plugins, plugin package managers;
- Vim configuration, working with the .vimrc file (in particular, using the author's .vimrc file as an example);
- working with Neovim;
- setting up autocompletion.
Today we will conduct three video lessons in which we will take a detailed look at plugins, .vimrc settings, and working with NERDTree. These topics are key to optimizing your work in the Vim editor and will help you increase your productivity when programming. Be sure to join us to deepen your knowledge and skills in using Vim.
How the course is structured
We offer video tutorials and text transcripts, allowing you to study the theory in both video and text formats.

The course author is an experienced professional in his field, possessing deep knowledge and practical experience. His approach to teaching is based on modern methods and current trends, allowing students to gain not only theoretical knowledge but also practical skills. The author actively shares his experience, offering course participants unique resources and tools to help them achieve success. His mission is to inspire and motivate students so they can realize their potential and achieve their goals.
Team lead at Purple Magic, video producer at Red Magic, co-host of the IT Way podcast, and author of programming courses. Specializes in the Ruby language.
In the previous parts, we discussed key aspects that help understand the essence of the topic. We reviewed the basic concepts and principles, and also highlighted important points that are important for further study. In this article, we will delve into the details and analyze specific examples to strengthen understanding and provide practical recommendations. We strive not only to provide information, but also to help the reader apply the acquired knowledge in practice.
- Lessons 1–2. The history of text editors and the evolution of Vim
- Lessons 3–7. All about Vim modes
- Lessons 8–10. Regular expressions, working with windows, macros
Plugins and plugin package managers
In this article, we will look at the Vim infrastructure, including plugins and package managers. We'll discuss how to properly configure plugins, as well as how to use ready-made builds for various programming languages. We'll also cover Neovim, a modern Vim-based editor that offers advanced features and improved performance. Understanding these aspects will significantly simplify your work with Vim and increase your programming efficiency.
Plugins are key tools that allow Vim to remain competitive among modern integrated development environments (IDEs) while maintaining its unique style. We recommend using vimawesome.com to find plugins. This site organizes plugins by programming language, technology, and functionality, making it much easier to select and install the right add-ons for your workflow.
After this lesson, you'll be able to visit the site and test plugins in your environment. We'll start with the basic principles of how they work, focusing on several key aspects.
Package managers are an essential tool for installing, updating, and removing software. If you're an experienced user of Unix-like systems, you're probably familiar with their capabilities. In the context of the Vim editor, package managers function as plugins that simplify the process of installing and uninstalling other plugins. This significantly simplifies managing the editor's functionality, providing more flexible and efficient work with code. Using package managers in Vim not only speeds up the process of setting up a development environment but also helps keep the tools you use up-to-date.
Most Vim package managers download plugins directly from GitHub and run built-in installation scripts. Version control is not their strong point in this context, as version conflicts among Vim plugins are quite rare. This makes the process of installing and updating plugins simpler and more reliable, allowing users to focus on improving their working environment without worrying about version compatibility.
Vim-plug is a modern and popular package manager for Vim that offers a number of advantages over Vundle. First of all, vim-plug offers better compatibility with Neovim, making it an ideal choice for users of that editor. Secondly, vim-plug provides a more user-friendly interface, including detailed error messages for plugin installations. This helps quickly identify and resolve issues. Let's look at an example of using it to install a plugin.
First, you need to install vim-plug. Detailed installation instructions for various operating systems are available in the Readme on GitHub. By following these guidelines, you can quickly and effectively integrate vim-plug into your development environment, significantly simplifying the management of plugins for the Vim editor.

Installing the software The software may be accompanied by various issues. If you encounter any difficulties, we recommend visiting the Issues section of the repository. There you can find descriptions of errors and situations similar to yours, as well as possible solutions.

Such situations happen quite often, and in most cases they find their Solution.
Open the .vimrc file to configure the Vim editor. This file allows you to customize the editor's behavior and appearance, making it more user-friendly. In .vimrc, you can set preferences such as color scheme, indentation settings, and other important options. Properly configuring .vimrc can improve productivity and make editing code easier. Customize your Vim to get the most out of it.

On Linux systems, the file is located in the user's home directory by default. To find out its location on your operating system, search the Internet. This won't take long and will allow you to quickly obtain the information you need.
In the file, you need to enter the line call plug#begin(). This command is used to initialize plugins in Vim. Make sure you add it to the correct location in your configuration file. Proper initialization of plugins can improve the editing functionality and customization of your text editor.

This command initiates a block that will be executed by the vim-plug plugin. We're going to install the vim-sensible plugin. To do this, enter its name in the search bar on vimawesome.com. Follow the provided GitHub link. Extract the GitHub username and repository name from the URL.

In the .vimrc file, call the Plug method and specify it in quotation marks via A slash is the username and repository name. This allows you to integrate plugins into Vim, improving the editor's functionality. Make sure you specify the repository path correctly to avoid installation errors. Using the Plug method simplifies the process of managing plugins and makes it more convenient.

To install plugins in the text editor, use the PlugInstall command. After executing this command, you will receive information about the installation status. Make sure all the necessary plugins are installed correctly to optimize your working environment.

The plugin has been successfully installed. Now you can take advantage of all its features and capabilities. Make sure you read the settings and user manual for optimal use. The plugin will help improve the functionality of your site and increase its efficiency.
Almost all Vim plugins are installed in a similar way. However, there are those that do not support installation via vim-plug, Vundle, or other package managers. Over time, such plugins are becoming fewer in number, as users are increasingly reluctant to choose those that are difficult to install. The ease of installation via package managers significantly simplifies the process of working with plugins and contributes to their popularity.
Let's consider the most popular plugins that can be useful for every specialist, regardless of the technology used. These tools allow you to improve the functionality and performance of projects, and simplify workflows.
The vim-sensible plugin offers a set of generally accepted settings for the Vim editor, making it an ideal choice for users working on servers. It ensures the convenience of using Vim, especially in collaborative environments. If the settings provided by this plugin do not meet your requirements, you can always remove it. Using vim-sensible simplifies Vim customization and improves the user experience.
The vim-surround plugin greatly simplifies working with paired characters, such as brackets and quotes. For example, when you need to replace one type of quote with another, vim-surround makes the process quick and convenient. In the Ruby programming language, strings without interpolation are typically surrounded by single quotes, while strings with interpolation are surrounded by double quotes. Using vim-surround, you can be inside a code block and simply press the cs ' '' key combination to replace single quotes with double quotes. This feature significantly speeds up code editing and improves readability. Using vim-surround effectively will help you improve your productivity when working with Ruby and other programming languages.

Quote replacement is complete, allowing you to easily apply Interpolation in code. This improvement significantly simplifies the process of working with text data and makes code more readable. Developers can now effectively use variables within strings, increasing the flexibility and functionality of their programs. Using interpolation leads to cleaner code and reduces the likelihood of errors when processing string values.

NERDTree is a powerful plugin for Vim that provides a convenient interface for working with the file tree. In the following lessons, we'll discuss in detail its functionality and capabilities that will help you effectively organize and manage files in your project.
Vim-commentary is a powerful plugin for the Vim editor that simplifies the process of commenting code in various programming languages. With it, developers can quickly add or remove comments to lines and blocks of code, significantly speeding up the workflow and improving code readability. The plugin supports many languages, making it a universal tool for programmers. Installing vim-commentary is simple and requires minimal effort, allowing you to quickly integrate it into your workflow. Using this plugin will help you increase your productivity and organization of your code, and also facilitate team collaboration during development.
FZF is a powerful fuzzy search plugin that allows you to effectively find information in your project. It searches not only code and files but also commits and buffers, greatly simplifying the work of developers. With FZF, you can quickly find the elements you need, increasing productivity and facilitating the development process.
Vim-airline is a status bar located at the bottom of the Vim editor screen. This plugin improves visual perception and functionality by providing users with up-to-date information about the file status and other aspects of working in the editor. With vim-airline, file navigation becomes more convenient and efficient, which is especially valuable for developers working on large projects. Using this status bar in combination with other plugins significantly expands the capabilities of Vim and helps you focus on the code itself.
In subsequent lessons, we will take a closer look at other plugins and ready-made builds for various programming languages.
Working with the .vimrc File
The .vimrc file is the main configuration file of the Vim editor, where all settings are stored. This file typically specifies Vim commands that can be executed from the command line. Configuring Vim through .vimrc is a sequence of commands defined in this file. Exceptions are commands related to specific plugins, such as vim-plug. Properly configuring .vimrc can significantly improve the user experience and increase the efficiency of working in Vim.
In this text, we will look at the basic settings that can be made to the .vimrc file to optimize your work in the Vim editor. Properly configuring .vimrc can improve performance and make the editing process more convenient. Settings can include changing the appearance of the editor, adjusting indentation, automatic saving, and many other parameters. Learning these options will help you get the most out of Vim.
The set hlsearch command enables highlighting of search results in the Vim editor. After entering this command, all found results will be highlighted until you close the editor. To make this setting permanent, add the command to the .vimrc file. This way, search highlighting will be enabled automatically every time you launch the editor.

Let's check the functionality. Close the editor and open it again, then perform a search. The function works correctly.

In previous lessons, we noted that switching between windows in Vim can be difficult. To simplify this process, we'll remap the navigation key to the Ctrl and directional arrow keys. We'll also create a new key set for convenient navigation between windows. Let's look at how to implement this customization.
The Vim editor's command line includes the wincmd command, which allows you to switch between windows. This command takes the navigation direction as an argument. We can use it to customize our .vimrc file.

Vim uses the map command to map keys. It takes two parameters: the key combination to press and the action to perform. Using this command, you can set up your own hotkeys to simplify working in the editor. Customizing your hotkeys can improve productivity and make text editing more convenient. It is important to use the map command correctly to avoid conflicts with existing combinations and ensure efficient work in Vim.

You can set unique keyboard shortcuts for each mode. This will allow you to tailor the controls to your preferences and improve your work efficiency. Customizing the keys will ensure ease of use and improve interaction with the software. Choose the optimal combinations for each mode to make the process more intuitive and productive.
- nmap (normal mode) is assigned only to command mode;
- imap (insert mode) - for input mode;
- vmap (visual mode) - for visual mode;
- smap (select mode) - for selection mode;
- cmap (command-line mode) - for command-line mode.
We plan to establish switching between windows exclusively in command mode. For this, we will use the nmap command with the assignment wincmd k. Here nmap denotes the destination for command mode, and the keyboard shortcut Ctrl + k will be used to activate this transition.

The command called with the keyboard shortcut wincmd k, By default, it corresponds to the Enter key. It's used to confirm a command, after which you must press Enter. Let's try this out. Restart the editor and open two windows. Then press Ctrl + k. It worked!

The wincmd k command appears at the bottom of the screen, but it is not necessary, as the constant reminder to switch between windows can be distracting. To remove this notification, go back to your .vimrc file and add the appropriate argument. This will configure Vim to not display unnecessary messages when switching between windows, making your work more comfortable and efficient. Customizing Vim to your preferences is an important step to increasing productivity.

This argument disables the display of command execution results in the editor. Let's try using it.

The transition works, but the command is not displayed. You need to repeat this setting for transitions in opposite directions.
Now let's set the keyboard shortcut for saving. Enter: map : w. This command will allow you to efficiently save changes to your document, improving your workflow and increasing productivity. Properly setting up hotkeys will significantly simplify interaction with the text editor and speed up the execution of tasks.

Pressing the Esc key switches to command mode by default. After this, enter the command :w and press Enter to save the changes. To close the file without saving, use the command :q!. This will allow you to exit the editor without saving your changes.

To save and close, use the appropriate function in your application or system. Make sure all changes are saved before closing. This ensures your work isn't lost and all data will be available the next time you open it. If necessary, create a backup copy of important information to avoid loss. Saving data correctly is a key aspect of effective information management.

In Vim, you can activate the display of line numbers with the set nu or set number commands. Both options have the same effect and allow the user to see line numbers in the editor. This significantly simplifies code navigation and improves the editing process, especially when working with large files. To disable line numbers, use the set nonu or set nonumber commands. Using these commands is an important part of setting up your Vim workflow to be more productive.

The set nocompatible setting disables Vim's compatibility mode with Vi. This allows you to use all the advanced features and capabilities Vim offers without the limitations of compatibility with older editors. Disabling compatibility gives the user access to more modern editing features, improving productivity and usability. Enabling this setting is an important step to optimizing your Vim workflow, especially for users who want to take advantage of the editor's full potential.

Modern plugins often require certain settings to work correctly. Lack of compatibility with the Vi editor can lead to various unpredictable issues. Currently, Vi compatibility support remains rarely requested, and many developers neglect it. We recommend making the necessary adjustments to your settings if you're not a dedicated Vi user. This will help avoid potential errors and improve the experience with plugins.
The "filetype on" and "syntax on" settings in the Vim editor control code syntax highlighting. Enabling "filetype" allows the editor to automatically detect the file type and apply the appropriate formatting rules. Enabling "syntax" highlights keywords, comments, and other code elements, significantly improving readability and usability. These settings are important for developers, as they help them quickly navigate code and identify errors. Proper Vim setup increases productivity and makes programming more efficient.

Most plugins work effectively even without initial setup, including functions for working with file extensions. Some of them may require disabling it; For example, Vim's filetype settings are set to off. We recommend leaving filetype on unless needed. This will ensure optimal plugin performance and improve the overall performance of the development environment.
You can customize the highlighting of the line and column containing the cursor using the set cursorline and set cursorcolumn commands. This will allow you to easily track the current cursor position in the document, improving navigation and making it easier to work with text. Adjusting these settings can help improve productivity, especially when editing large files.


In this case, the settings were not added, since extra lines can distract from the main process. However, the set cursor column function can be assigned to the F8 key, which will allow you to periodically check the alignment and formatting of the code. This is especially useful in situations where you need to find a missing closing bracket. We'll discuss how to enable and disable settings using keyboard shortcuts in future lessons.
The set nowrap command prevents long lines of text from wrapping. This helps preserve formatting and readability, especially in tables and code where structure is important. This command can be useful in various situations where you need to avoid automatic line wrapping and keep text on a single line. Optimal use of set nowrap improves the visual perception of data and makes it more accessible to users.

The set history=1000 command configures the number of command line commands saved in the history to the value you specify. This allows users to save and manage a large number of previously entered commands, simplifying the command line process. Increasing the command history can be useful for those who frequently use repetitive commands or want to access previously performed actions. Optimizing your command history helps you work more efficiently and get things done more easily.

By default, the number of items is 20.
The next step is to set the color scheme for Vim. We recommend downloading one of the most popular color schemes, Molokai. This scheme is known for its high-contrast, eye-pleasing design, making text more comfortable to work with. Installing Molokai will improve the visual perception of code and increase productivity.

Color schemes for Vim are located in the ~/.vim/colors directory. This directory contains files that define the editor's visual design. You can add new color schemes by downloading them from the internet and placing them in this directory. To activate a selected scheme, use the command `:colorscheme scheme_name` in Vim's command mode. Choosing the right color scheme can improve the readability of your code and make your work more comfortable. Don't forget that many color schemes can be customized to achieve optimal contrast and eye comfort.

Download the color scheme file and place it in the specified folder. On Linux, you can do this using the curl command. Use the following command: curl -o molokai.vim https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim . This will download the Molokai file, which you can then use to customize the color scheme in your text editor. Make sure the file is placed in the correct directory so the color scheme is available for use.

Open the .vimrc file and set the desired color scheme. Save your changes, then close and reopen Vim. You'll see the new color scheme successfully applied. This will significantly improve the visual perception of the editor.

You can not only download ready-made color schemes, but also make changes to them, as well as create your own. Let's open the file we downloaded.

The initial lines of code are mainly devoted to the compatibility of the scheme with the editor. The description of the color scheme itself begins at line 47. Here you'll find familiar symbols for every programmer, such as Boolean, Character, Constant, and others. These elements play an important role in visually understanding the code and help developers quickly navigate the program's structure. A proper color scheme improves the readability of code, which promotes more efficient work and reduces the likelihood of errors.

Change the color of Boolean values to white. Since we're working with a 256-color terminal, we need to make changes to the module responsible for its support. This will improve the visual perception of the data and simplify its analysis. Updating the color will make the information more visible and readable, which is especially important for users working with large amounts of data.

Close the Vim editor and reopen the Ruby file. We enter the logical values true and false. These values are displayed in white.

You can change the entire color scheme to your taste. Customizing colors allows for creative expression and can be time-consuming. Now let's customize the status bar. We can use the vim-airline plugin to quickly add a variety of features, but to better understand the customization process, let's try it out ourselves first. To get started, enter the command :help statusline:. This will familiarize you with the basics of customizing the status bar in Vim, which will help you use the plugin more effectively and adapt it to your needs. The status bar is an important interface element that helps you monitor current editor settings, file status, and other useful data.

Let's look at the main functions that have already been implemented in vim-airline. This Vim plugin enhances the user interface by providing a visually appealing and informative status bar. With a lightweight, minimalist design, vim-airline allows users to focus on coding without distractions. The plugin supports various themes and settings, allowing for customization to suit individual preferences. Furthermore, vim-airline integrates with various tools, such as Git, allowing you to track code changes directly in the status bar. These features make vim-airline an indispensable tool for developers looking to improve their productivity and usability in Vim.
Open the .vimrc file. The first step is to clear the status bar. To do this, add the following line of code: set statusline=:

Now on the next line, add the command set statusline += \ %F\ %R. This command allows you to customize the status bar, displaying the full path to the current file and its mode. Properly customizing the status bar is important for ease of use, as it allows you to quickly navigate open files and their status. Please note that using the correct syntax and spaces is critical to displaying the information correctly.

The F parameter in this context means outputting the full file address, while the R parameter indicates read-only status if the file is write-protected. Now let's add display of the current Git branch. To do this, we need to get the name of the current branch. We'll create the corresponding variable in the .vimrc file with the following command: let gitBranch=system(«git rev-parse —abbrev-ref HEAD»). This will automatically display the name of the current branch when working with Git in the Vim editor.

This command allows you to get information about the current branch in the Git repository. Since the .vimrc file doesn't have a built-in interpolation function, we'll use a useful trick. This lifehack allows you to perform necessary actions even if your editor lacks important features like interpolation.
To customize the status line in your editor, run the command execute "set statusline +=". This will add information about your current Git branch to the status line. Make sure you set the gitBranch variable correctly to display up-to-date information about the branch you're on. This will improve your productivity and simplify working with code versions.

Checking: the gitBranch variable value has been successfully added to the status bar.

Add data to the right side of the status bar using the following command: set statusline+=\ Row:\ %l\ Col:\ %c\ Percent:\ %p%%. This will display the current row, column, and scroll percentage in the editor. This approach will improve the user experience by providing important information about the cursor position and the document scroll level.

In this context, %l denotes the row number, %c denotes the column number, and %p specifies the cursor position as a percentage of the total file size. These parameters help the user accurately navigate the document, ensuring ease of editing and text navigation. Using such metrics significantly improves the interaction with text editors and code programs.
For a better experience with Vim, we recommend installing the vim-airline plugin. This plugin significantly improves the editor's interface and provides useful features. To install vim-airline, add the following line to your Vim configuration file: Plug ‘vim-airline/vim-airline’. Then run the :PlugInstall command to complete the installation. Using vim-airline will make your work in Vim more convenient and efficient.

A beautiful status bar has been created that attracts attention. This interface element not only improves visual perception but also facilitates user interaction with the application. The status bar provides information about the current system status, making the interface more intuitive and user-friendly. This design improves the user experience and increases the overall quality of the application.

In this tutorial, we covered the basic settings you need to know. However, there are many more options. You can save your settings, transfer them to different computers, and reinstall them after upgrading your operating system. Simply place the necessary files in the appropriate directories and restart the editor. Please note that not all modern IDEs offer such flexibility in managing settings.
We recommend creating your own repository for customizing your working environment. Such repositories, known as dotfiles, make it easy to set up all the necessary settings on a new operating system with a single command. For example, the author of this course developed his own dotfiles repository, which stores all the settings for Vim. These settings are located in the .vimrc file. Creating and using your own repository will help simplify the process of setting up the environment and ensure consistency in your work.
We recommend adding the .swp and .swn extensions to the global .gitignore file. These files are created by the Vim text editor while editing other files. To prevent accidental committing of these temporary files to the repository, it is best to set up global ignore rules at the system level. This measure will help keep your repository clean and avoid unnecessary conflicts.
Adding configuration files to repository-specific settings may be inappropriate, as not all participants in your project use Vim. It is recommended that such settings be configured individually for each developer. This will avoid conflicts and provide a more flexible working environment.
NERDTree Plugin
NERDTree is one of the most popular plugins for visualizing and managing the file tree in your projects. In this article, we'll look at how to effectively use NERDTree to simplify working with files and directories.
With NERDTree, you can quickly navigate your project structure, opening, creating, and deleting files and folders. This tool significantly speeds up the development process, allowing you to focus on your code rather than searching for the files you need.
To start using NERDTree, you need to install the plugin and become familiar with its basic commands. Once NERDTree is activated, you can open it with a command that allows you to see the file hierarchy. This will make it easier to find the resources you need and keep your work more organized.
Using NERDTree, you can not only view files but also edit them, making this tool indispensable for developers. This plugin is suitable for projects of any size and complexity, making it the perfect solution for working with files in Vim.
Installing the plugin using vim-plug takes just a few seconds.

Restarting the editor is an important process that allows you to update its functionality and fix any errors. Regular restarts help improve performance, optimize content management, and ensure system stability. If you need to restart the editor, it's important to save all unsaved changes to avoid data loss. You should also ensure all necessary updates are installed to ensure full compatibility and security. This will allow users to work effectively with the editor and get the most out of its capabilities.

To open a window with a file tree, enter the command: NERDTree. This command allows you to quickly view the directory and file structure of your project, simplifying file navigation and management. NERDTree is a powerful tool for developers, allowing you to effectively organize and edit files within a text editor. Use the NERDTree command to streamline your project workflow and improve your productivity.

You can assign any keyboard shortcut to control NERDTree. To do this, use the NERDTreeToggle command, which will automatically open NERDTree if it is closed, and close it if it is already open. In our setup, this command is bound to the keyboard shortcut Ctrl + f.

By default, NERDTree sets the root directory to the one from which Vim is launched. To open folders and files, press the o key. Files open in the right window, and folders expand to view their contents. To open a file in a new window, use the i key. NERDTree is a powerful tool for managing the file system inside Vim, allowing you to quickly navigate between projects and simplify working with files.

Pressing the S key causes Vertical split of windows. To show hidden files, use the combination Shift + I.

To hide elements, click again to hide them again. To add a file or folder, follow these steps: navigate to the desired directory where you plan to create the elements and press the ma key combination. Enter the file name. If you add a slash at the end of the name, the system will create a folder.

To create a file in a non-existent folder, specify the full path to the file. In this case, the folders will be created automatically.
To change the name or path of the file, you must enter the mm command, and then specify a new name.

To copy the file, use the mc command, specifying a new name file.

To delete a file, enter the md command and confirm the action by pressing Enter or the y key.

The main difference between NERDTree and traditional file trees is that it doesn't update automatically. If you add, delete, or change a file's name, you need to manually refresh the tree by pressing Shift + r. This allows the user to control exactly when the data is updated, which can be useful for maintaining order in the project.

The main functions of this plugin are now discussed. In the next lesson, we'll focus on plugins for various programming languages.
Be sure to check out the additional materials:
- How to write code quickly and efficiently: Emacs, Vim, and other editors for Haskellists
- "I thought that writing code was like building spaceships"
- What is an API and how does it help in creating software systems?

