Code

Vim: Autocomplete, .vimrc Again, Neovim – Part 5 of the Free Online Course

Vim: Autocomplete, .vimrc Again, Neovim – Part 5 of the Free Online Course

Free Course: "Quick Start in Python"

Learn More

We provide video tutorials and text transcripts so you can choose between watching videos or reading the theoretical material.

The author of the course is a qualified specialist in his field. He has significant experience and deep knowledge, which he shares with his students. The training is conducted in an accessible and understandable form, which allows each participant to easily assimilate the material. The course covers key aspects of the topic, ensuring the practical application of the knowledge gained. The author's unique approach allows students to develop their skills and confidence in their chosen field.

Team lead at Purple Magic, video producer at Red Magic, co-host of the IT Way podcast, and author of programming courses. Specializes in Ruby.

In the previous parts, we covered the main aspects of the topic, including key points and important details that will help you better understand the issue under discussion. We analyzed the main factors influencing the situation and highlighted the main findings that can be useful for further study. Now we will move on to a more in-depth review and analysis.

  • 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
  • Lessons 11-13. Plugins, .vimrc, NerdTree

We've reached the final three lessons. In this section, we'll take a closer look at the autocomplete feature, delve into the .vimrc file settings, and discuss the features of the Neovim editor.

Configuring autocomplete

Autocomplete is a function of automatic completion of words as you type. This useful option greatly simplifies the process of programming and writing texts. Despite its usefulness, not all users prefer to use it. Autocomplete helps speed up typing and minimize errors, making it an essential tool for both developers and casual users.

One of the most effective code completion tools is the YouCompleteMe plugin. However, the author experienced difficulties using it: he once managed to set up the plugin for Ruby, but it subsequently stopped working, and no attempt was made to restore it. Nevertheless, YouCompleteMe demonstrates excellent results for other programming languages, remaining a useful tool for developers.

The standard autocomplete in Vim is a powerful tool that significantly speeds up the process of programming and text editing. It allows automatic completion of words and commands, which is especially useful when writing code. Autocomplete in Vim can be customized to suit your needs, making it universal for various programming languages. Using this feature not only saves time but also reduces typos, increasing overall productivity. To activate autocomplete, simply use a key combination, and Vim will suggest possible completion options depending on the context. Effective use of the default autocomplete in Vim can significantly improve your experience and make it more comfortable.

Screenshot: Skillbox Media

Let's learn methods for setting up autocomplete. To display available autocomplete options while typing, press Ctrl + n and use the arrow keys to navigate the list of suggestions.

Screenshot: Skillbox Media

To select Use the Enter key to select the desired option. The Esc key closes autocomplete.

You can update Vim's autocomplete dictionary as needed. To do this, create a directory named complete in your ~/.vim directory. In this directory, create a file named skillbox.vim. This file will be used to store custom words and phrases that will help improve Vim's autocomplete, making your editing experience more efficient and convenient. Regularly updating the dictionary will allow you to adapt the development environment to your needs, which is especially important for programmers and developers working with different programming languages ​​and projects.

Screenshot: Skillbox Media

Skillbox is a platform offering high-quality education in IT and digital technologies. It offers a variety of courses, including training for the Vim editor. Vim is a powerful tool for programmers that significantly speeds up the process of writing and editing code. Many users note its efficiency and flexibility. By mastering Vim, you can increase your productivity and improve your programming skills. Skillbox's Vim training program helps both beginners and experienced developers master this editor and make their work more comfortable and faster. As a result, by learning Vim through Skillbox courses, you will gain not only theoretical knowledge but also practical skills that will help you become a more competitive IT specialist. Don't miss the opportunity to improve your skills with Skillbox and Vim.

Screenshot: Skillbox Media

Open the vimrc file and add the following code:

Screenshot: Skillbox Media

This code loads the dictionary for autocomplete from a new file if the file is of type Ruby. Open a Ruby file and start typing "sk", then press Ctrl + n to see word completion suggestions. This will speed up your coding process and improve its quality by automatically suggesting options. Autocomplete makes the work of developers much easier, allowing you to quickly find the necessary commands and reduce the time spent typing.

Screenshot: Skillbox Media

The editor provides auto-completion for skillbox, which significantly simplifies the workflow. Similarly, the autocompletion feature is available for vim_da_best, which allows you to speed up coding and increase user productivity.

If you prefer not to install autocompletion plugins in Vim, you can download suitable dictionaries for various programming languages. It is also possible to create your own dictionary, adapted to a specific project. As with everything related to Vim, you have complete freedom.

By default, autocompletion suggests matching words from the buffer, which is updated while you work in the editor, unless special dictionaries are specified. For more effective autocompletion, we recommend using the YouCompleteMe or DeoComplete plugins. Please note that DeoComplete will be replaced by the new DCC plugin. We recommend carefully reading the documentation to get the most out of autocompletion.

This guide provides basic information about how autocompletion works in Ruby. Like all features in Vim, autocompletion can be customized to suit your needs. Properly setting up autocomplete can significantly speed up the development process and increase productivity. Using autocomplete, Ruby developers can minimize errors and speed up coding. Setting up autocomplete in Vim opens up new opportunities for working more efficiently with Ruby, allowing you to focus on application logic rather than syntax.

More about .vimrc

Let's take another look at the .vimrc file. Most of the commands and settings presented in this file we have already discussed earlier. Now let's look at specific examples of how these settings can be used and their implications for working with text. The file can be found at the location shown in the image. Let's analyze it line by line to understand how each command affects the functionality of the Vim editor and improves the user experience.

Screenshot: Skillbox Media

The set nu command in The Vim editor displays line numbers. This feature is useful for navigating and working with code, as it allows you to quickly navigate large amounts of text. Line numbers make it easier to correct errors and simplify collaboration with other users, as you can refer to specific lines. Enabling this command is a standard practice for developers and helps increase productivity when editing files.

The set expandtab setting is a useful tool that allows you to insert a specified number of spaces when pressing the Tab key. This is important for maintaining consistency in your code, especially in light of the well-known issues demonstrated in the TV series "Silicon Valley," which discusses difficulties arising from different tab settings. Often, spaces require multiple presses, while tabs only require a single press. However, if your colleagues use different settings, this can lead to incorrect code display. The expandtab setting solves this problem: when you press Tab, you get two spaces, which ensures consistency and improves the readability of your code. Using this setting promotes better collaboration within the team and reduces the likelihood of formatting errors.

Screenshot: Skillbox Media

No tab stop setting will change the way the code is displayed. This is a remarkable property that highlights the importance of code structure for its proper perception. Proper formatting and use of tabs play a key role in creating readable and understandable code, but do not affect its functionality. Therefore, developers should pay attention not only to the logic but also to the aesthetics of the code to ensure its ease of understanding and maintenance.

Setting the set sw=2 parameter determines the number of spaces that will be used instead of tabs in the text editor. This value is typically used to adjust code formatting to ensure consistency and ease of reading. Setting the tab width to 2 spaces is a common practice in programming, as it helps avoid excessive indentation and improves the visual perception of the code. Proper indentation promotes better collaboration within a team and makes the process of reading and maintaining code easier.

Setting set sts=2 is designed to simplify text alignment. It allows you to remove two spaces with a single press of the Backspace key, which significantly speeds up the editing process. This feature is especially useful when working with indentation and text formatting, as it provides a cleaner and neater appearance to the document.

Setting the 'set nocompatible' option in the Vim editor disables Vi compatibility mode. This allows you to use advanced Vim features that are not available in native Vi. By disabling compatibility, users gain access to more modern editing capabilities, improved commands, and settings, significantly increasing the efficiency of working with text. It is recommended to include this option in the configuration files to optimize your workflow in Vim.

Setting filetype off can be useful in certain situations, and we have already discussed the reasons for disabling it. Disabling this feature allows for more flexible file access control and improves interaction with content. This can be especially relevant for web developers and SEO specialists who are looking to optimize their resources for search engines and improve the user experience.

To optimize vim-plug on the Linux operating system, it is recommended to use the following four lines. These settings will help improve performance and simplify plugin management in Vim. Properly configuring vim-plug will ensure more stable and faster operation of the editor, which is especially important for developers and users who need to effectively manage a large number of plugins. Make sure you add these lines to your Vim config file for best results.

Screenshot: Skillbox Media

We present you with a list of plugins that we We've already discussed these tools. These tools will help improve your website's functionality and optimize its performance. Using the appropriate plugins can significantly improve performance and provide a better user experience.

Screenshot: Skillbox Media
  • syntax enable — enable syntax highlighting;
  • filetype plugin indent on — enable working with file types from Plugins;
  • Save file on F2;
  • Exit without saving on F3;
  • Save and exit on F4;
  • F5 — remove search results highlighting. A useful feature: first look at all occurrences of a word in the file, and then turn off the highlighting;
  • On F7, we set up a complex replacement of the old hashing type in Ruby with a new one;
  • On F8 — turn column highlighting on and off. Very helpful when you need to find a missing closing bracket or end. Please note that if you add ! to the end of some settings by set, they will be turned on if disabled, and off if enabled;
  • F9 — calls the utility for converting HTML code to Haml;
  • set relativenumber — we discussed why this is necessary;
  • map : NERDTreeToggle — assign Ctrl + p to open NERD Tree.

This section presents keyboard shortcuts for quickly switching between windows. Using keyboard shortcuts can significantly speed up your work and increase your productivity. Knowing these combinations, you can quickly move between open applications and windows, which will make your work more efficient. Basic keyboard shortcuts include combinations such as Alt + Tab to switch between the most recently used windows and other specific combinations for different operating systems. Check them out to optimize your workflow and save time.

The next block is a fascinating piece of content. It attracts attention with its unique features and offers the reader new knowledge. This section can cover various aspects that will be useful for understanding the topic. Well-structured text in this block helps users easily digest the information and find answers to their questions. By focusing on keywords and phrases, we can increase the visibility of this block in search engines, making it more accessible to a wider audience.

Screenshot: Skillbox Media

By default, many plugins don't enable syntax highlighting for certain file extensions, even if the code in these files is written in the same languages. The author added the missing extensions and configured Vim to automatically enable syntax highlighting for each language. This improves code readability and increases developer productivity. Configuring syntax highlighting in Vim helps avoid errors and simplifies the editing process, which is especially important for programmers working with different programming languages ​​and their extensions.

Configuring syntax for .thor files in Vim is done using a command that enables Ruby syntax highlighting. This is done by adding the following line to the Vim configuration file: «au BufRead,BufNewFile *.thor set syntax=ruby». This command ensures that syntax highlighting is automatically applied when opening or creating a .thor file, significantly simplifying working with Ruby code and increasing readability. Proper editor configuration allows developers to write and edit code effectively, which is an important aspect of programming.

Configuring your editor to work with .simplecov files allows you to automatically set Ruby syntax when opening or creating such files. This configuration helps improve code readability and makes it easier to edit, which is especially important for developers working with tests and code coverage in Ruby. Make sure you add the appropriate line to your editor's configuration file to ensure the correct syntax for .simplecov files.

For files with the .es6 extension, you must configure the file type to be detected as JavaScript. This can be done with a command in the editor configuration, which will be automatically applied when opening or creating new files with this extension. Use the following line: au BufRead,BufNewFile *.es6 set filetype=javascript. This setting will ensure correct syntax highlighting and support for JavaScript features when editing .es6 files.

Configuring the editor to work with Vue files involves changing the file type to JavaScript. To do this, you need to use a command that will be used when opening or creating files with the .vue extension. Enter the following line in your editor's configuration file: au BufRead,BufNewFile *.vue set filetype=javascript. This command will ensure correct syntax highlighting and improve your work with Vue components, which will positively impact your development workflow.

Configuring the syntax of Vue files in editors such as Vim is accomplished with a command that specifies that files with the .vue extension should be processed as JavaScript. To do this, use the following command: au BufRead,BufNewFile *.vue set syntax=javascript. This command ensures correct syntax highlighting and improves the code workflow, allowing developers to edit and write Vue.js code more efficiently. Proper syntax configuration is important for improving productivity and usability in the development environment.

Configuring your editor to work with Go files is an important step towards improving code quality. To change the tab stops for files with the .go extension, use the following command in your configuration file: au BufRead,BufNewFile *.go set tabstop=2. This command sets the tab stop size to 2 spaces, which is a common practice in the Go community. Optimizing your editor settings helps improve code readability and promotes standard formatting, which is important for both individual developers and teamwork.

When opening or creating a Makefile, the editor automatically sets the tab stop size to 2 spaces. This makes the Makefile easier to read and edit, which is especially important for maintaining coding standards and ensuring compatibility with different build tools. Setting formatting options for the Makefile helps developers maintain consistency across the project and improves code comprehension. A properly configured development environment improves efficiency and reduces the likelihood of errors during the build process.

To configure Dockerfile syntax in your editor, use the following command: au BufRead,BufNewFile Dockerfile* set syntax=dockerfile. This command automatically recognizes and applies Dockerfile syntax when opening new or existing files, significantly facilitating working with containers and increasing developer productivity. Optimizing syntax helps avoid errors and improves code readability, which is especially important when working on Docker-related projects.

For files with the .eslintrc extension, it is recommended to set the syntax to JSON. This can be done by adding the command au BufRead,BufNewFile .eslintrc set syntax=json to your text editor configuration. This will ensure correct syntax highlighting and improve code readability, which is especially useful when working with ESLint settings. Proper formatting and syntax highlighting will help avoid errors and simplify the process of editing configuration files.

For files with the .tsx extension, set the syntax to TypeScript. This can be done by adding the following command to your configuration file: au BufRead,BufNewFile *.tsx set syntax=typescript. This approach will ensure correct display and syntax highlighting of TypeScript in editors that support this setting, which will help improve the readability and usability of your code.

For convenient formatting of Vue files containing HTML code, you can use the following command in your editor configuration: autocmd FileType vue noremap :%! vue-formatter. This setting automatically applies formatting to Vue documents, improving the readability and maintainability of your code.

Search highlighting in the text editor is enabled with the set hlsearch command. This command highlights all occurrences of a searched word or phrase, greatly simplifying the process of searching and editing text. Highlighting helps you quickly find the elements you need, improving the efficiency of working with documents. Customizing search parameters, such as highlighting, can significantly improve the usability and speed of editing, especially when working with large amounts of text.

The Molokai color scheme is designed to create a visually appealing and comfortable programming environment. It is designed with optimal contrast and color harmony in mind, allowing developers to focus on their code without distractions. Molokai provides a comfortable perception of information, reducing eye strain during long working sessions. Using this scheme helps improve code readability and increase developer productivity.

These lines of code are designed to add a custom autocomplete dictionary to Ruby. This allows developers to enhance the editor's functionality by adding specific terms and constructs that are frequently used in their projects. As a result, autocomplete becomes more accurate and useful, significantly increasing your productivity while coding. Setting up your own dictionary helps avoid errors and speeds up the coding process, which is an important aspect of effective Ruby development.

Rework the text, maintaining the main topic, and optimize it for SEO. Make sure the content remains relevant and informative. Avoid using emojis and unnecessary characters, and do not add structured sections. Focus on clarity and accessibility of the text.

To improve work with Ruby files in the Vim editor, you need to add the path to a custom autocompletion file. To do this, use the following command: autocmd FileType ruby ​​set complete+=k/home/pavel/.vim/complete/custom.vim. This command will allow you to expand the capabilities of code autocompletion, which will increase your productivity when developing in Ruby. Make sure the path to the custom.vim file is specified correctly to avoid errors during development. Configuring autocompletion in Vim is an important step for streamlining your workflow and improving code quality.

Refactored text:

endif » has(«autocmd») is an important part of configuring the development environment used in Vim. This command checks for the autocommand feature, which allows you to optimize the editing process and improve interaction with text. Using autocommands in Vim helps automate certain actions when changing files or switching between buffers. This significantly increases the efficiency of developers and reduces the time spent on routine tasks. Configuring autocommands is a key aspect for Vim users, helping to create a more convenient and customized environment.

A little about Neovim

Neovim, also known as Nvim, is one of the most promising forks of the popular text editor Vim. It has already carved out a niche for itself thanks to its improved functionality and modern features, making it an excellent tool for developers. Neovim offers advanced customization options, plugin support, and integration with modern development tools, making it an ideal choice for programming and code editing.

The new version of the editor is free from many of the previous shortcomings. In this text, we will briefly cover the main improvements and changes.

The codebase of the original Vim is highly complex, which makes it difficult to maintain and hinders the editor's development. In contrast, Neovim offers a simpler and cleaner architecture, which attracts many developers to improve and support it. This makes Neovim a more modern tool for programmers, providing better performance and extensibility.

When visiting the Vim and Neovim repositories, you can see that Vim development continues under the leadership of its creator, Bram Molenaar. At the same time, Neovim is actively supported by a wide community of developers. This demonstrates that both platforms continue to evolve, but their approaches to support and updates differ.

Neovim supports the Lua programming language, making plugin development more convenient and flexible. In contrast, Vim requires the use of Vimscript, a less popular and complex language, which creates additional challenges for programmers. Learning Vimscript requires time and effort, which limits the ability to develop and implement new plugins. As a result, Neovim's transition to Lua opens new horizons for developers, enabling the creation of more powerful and efficient tools to improve their workflow.

Lua is used by tens of thousands of people daily for various tasks, making Neovim a more promising choice. Although Vim plugins have been developed in Python in recent years, its runtime sometimes slows down plugin performance, which is not an optimal solution. Therefore, using Lua in Neovim can provide faster and more efficient work, which is important for developers and users striving for high productivity.

Tree-sitter is a powerful parser designed to build syntax trees from code. This technology significantly improves the functionality of the Neovim text editor, providing faster and more accurate syntax highlighting, autocompletion, and efficient execution of helper functions of various plugins that use data from Tree-sitter. Thanks to integration with Tree-sitter, developers are able to work with code more productively, making Neovim one of the most popular programming tools.

Most of the features and capabilities covered in this course are also available in Neovim. We recommend starting your acquaintance with Vim through Neovim, as it has significant potential for development. Neovim has the potential to become a modern interpretation of the editor, what Vim once was for Vi.

Choosing a code editor is a matter of personal preference. Choose tools that inspire you and make programming more engaging. Enjoying your work contributes to your professional growth and skill development. The best professionals possess skills that can change the world for the better. Don't forget the importance of practice and continuous learning in this field. Finish your work correctly: Esc :qa! Enter.

Reading is an essential part of personal growth and development. It opens new horizons, broadens your horizons, and deepens your knowledge. Books, articles, and other literary works allow you to delve into various topics and gain comprehensive information. It's important to choose quality resources that will help you improve your skills and advance your education. Read regularly, and you will notice how your perception of the world and your level of understanding of various processes changes.

  • Turning Vim into a full-fledged Python IDE
  • Test: How well do you understand the front-end?
  • PHP: What is this programming language and why is it popular?