未加星标

Useful Vim editor plugins for software developers - part 2: Syntastic

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

There's no doubt that Vim is a capable programming editor out-of-the-box, but it's the editor's plugins that help you make the most out of it. In thefirst partof this article series, we discussed a couple of programing-related Vim plugins (Tagbar and delimitMate). Continuing on the same path, in this article, we will discuss anotheruseful Vim plugin aimed at software developers - Syntastic .

Please note that all the examples, commands, and instructions mentioned in this tutorial have been tested on Ubuntu 16.04, and the Vim version we've used is 7.4.

Syntastic

If your software development work involves working with languages like C and C++, it's needless to say that resolving compile time errors would bepart of your daily work. Many a times, compilation errors arise due to incorrect syntax used in source code, asdevelopers fail to observe them while just looking at the code.

What if I tell you there exists a Vim plugin that provides information about syntax errors without you having to compile your code? Yes, such a plugin exists, and it's name is Syntastic.

" Syntastic is a syntax checking plugin for Vim that runs files through external syntax checkers and displays any resulting errors to the user. This can be done on demand, or automatically as files are saved," the official documentation of the plugin says. "If syntax errors are detected, the user is notified and is happy because they didn't have to compile their code or execute their script to find them."

Installation of this plugin is similar to the way we installedthe ones that werediscussed in the first part - all you need to do is to run the following commands:

cd ~/.vim/bundle/

git clone https://github.com/scrooloose/syntastic.git

Once the plugin is installed successfully (meaning the above commands are successful), you don't have to do anything else - it loads automatically when the Vim editor is launched.

Now, to use the plugin, open a source code file and save it using the :w Vim command. After a very brief pause, you'll observe that syntax errors - if any - in your code will be highlighted. For example, the following screenshot should give you an idea about how the plugin highlights the errors:


Useful Vim editor plugins for software developers - part 2: Syntastic

The '>>' sign in the beginning of a line indicates that there's some problem with the code written in thatline. To know what exactly the error is, or at-least get a rough idea about it, bring the cursor to that line - the error description will be displayed at the bottom of the Vim window.


Useful Vim editor plugins for software developers - part 2: Syntastic

So this way, you can resolve most of the syntax-related errors without even compiling the code.

Moving on, i f you run the :Errors command, description of all the syntax-related errors in the current source file will be displayed. For example, running the :Errors command in my case brought up the following information:


Useful Vim editor plugins for software developers - part 2: Syntastic

Keep in mind that the information the :Errors command displays isn't auto-refreshed, meaningeven after an error is resolved, it's description will be there at the bottom area until you run the :Errors command again.

It's worth mentioning that there are many configuration options that make Syntastic even more user-friendly. For example, you can put the following line in your .vimrc file if you want the :Errors command to automatically update its output each time an error is resolved:

let g:syntastic_always_populate_loc_list = 1

Another major limitation that the default Syntastic behaviour has is that you have to run the :w command in order to get the plugin to indicate erroneous lines - this is ok while editing a file, but gets a bit weird when you've just opened a source file.

To make sure that Syntastic highlights the errors automatically when a file is opened, add the following line to your .vimrc file:

let g:syntastic_check_on_open = 1

Similarly,if you want the cursor to jump to the first detected issue when saving or opening a file, then put the following line in your .vimrc file:

let g:syntastic_auto_jump = 1

There are two other values that you can assign to the aforementioned variable: 2 and 3. Here is what the official documentation says about these two values:

"When set to 2 the cursor will jump to the first issue detected, but only if this issue is an error," and "when set to 3 the cursor will jump to the first error detected, if any. If all issues detected are warnings, the cursor won't jump."

The following information should also be useful to you:

"Use :SyntasticCheck to manually check" for errors. "Use :Errors to open the location-list window, and :lclose to close it. You can clear the error list with :SyntasticReset , and you can use :SyntasticToggleMode to switch between active (checking on writing the buffer) and passive (manual) checking."

Note: Syntastic isn't just limited to code written in C and C++. It supports a huge list of other programming languages as well - head here to learn more about it.

Conclusion

Undoubtedly, Syntastic is a very useful Vim plugin as it saves you from the hassle of frequent compilation at-least when it comes to syntax-related errors. And not to mention that a lot of your time gets saved as well.

As you would have observed, Syntastic becomes even more useful once you've configured some of its main options. To help you get started with this, the official documentation contains a 'Recommended settings' section - do go through that. There is a nice little FAQ section as well in case you face some errors or have some doubts or queries.

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: C++Ubuntu
分页:12
转载请注明
本文标题:Useful Vim editor plugins for software developers - part 2: Syntastic
本站链接:http://www.codesec.net/view/484291.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(33)