As I posted previously, I have been using Vim for a long time. I did briefly try out neovim, but although I applaud their attempts to modernise the code base, until there is a feature I want which isn’t available in Vim there is just no reason for me to switch. In particular, one of neovim’s main reasons for forking was to have asynchronous processes supported, and now Vim has this too. I continue to find new features and new plugins for Vim which make my life easier.

One of these plugins is ALE. ALE (which stands for Asynchronous Lint Engine; lint being the classic C language checker) is a plugin for providing linting in NeoVim and Vim 8 while you edit your text files. Linting in this context means pointing out errors (specifically coding errors) as you type. This is one of the features making Vim closer to an IDE, but with the obvious benefit to me of Vim commands when editing and navigating. I do from time to time use Qt’s qtcreator, and although it is an excellent IDE (I really like the ability to jump to locations which use a variable or method), the vim-style editing built into qtcreator just isn’t good enough for me (in particular, the esc to exit edit mode is sometimes consumed by a dialog which means I am in edit mode when I don’t mean to be).

Anyway, back to ALE. Installing ALE is easy: I am using Vim 8 on Linux so I just needed to

  • mkdir -p ~/.vim/pack/git-plugins/start
  • git clone https://github.com/w0rp/ale.git ~/.vim/pack/git-plugins/start/ale

For use in the office, I want ALE to find a variety of include directories and to include some defines so my vimrc file has some lines to faciliate this.

Firstly, ensure the correct lint tool is being used

let g:ale_linters = "{'cpp': ['g++'],
'c': ['gcc']
}

Then make sure that C++11 features are on:

let g:ale_cpp_cpplint_options = '-std=c++11'
let g:ale_cpp_cppcheck_options = '-std=c++11'

Set some defines with -D (I’ve only left one in as an illustration) and set some include paths with -I (I’ve left in a couple for illustration):

let g:ale_cpp_gcc_options = '-std=c++11 -D_PLATFORM_LINUXRHEL7_ -Wall -Wextra -I/usr/local/packages/boost-1.60.0/include -I/usr/local/packages/zeromq/3.2.4/include'

I want the executable to be the appropriate (for me) RedHat Software Collection one:

let g:ale_cpp_gcc_executable = '/opt/rh/devtoolset-3/root/usr/bin/gcc'

With these changes in place I get in-place highlighting of errors as I type, like in the screen sho blowt, which highlights that the boost::trim_left function has been typed incorrectly. It is worth noting that this is being reported even though I have not yet saved the change: ALE writes temporary files to run the lint tool on.

Showing Vim using ALE plugin

Showing Vim using ALE plugin


Loading Conversation