Category Archives: Vim

Disable expandtab in Vim

I like to use spaces instead of tabs so I have this line in my .vimrc file:

set expandtab

This line will write spaces instead of tabs every time I hit the tab key.

Lately I’ve been working a little with Go. The standard in Go is to use tabs instead of spaces so I needed to change this preference for Go projects. The only thing that I needed to do is to add this line to my project .vimrc file:

set expandtab!

Adjusting the width of Nerdtree navigator

Nerdtree is one of my VIM essentials, but I was always annoyed that it took so much space in the screen. Since I use a vertical monitor, I barely get 80 characters to work on. I recently found that this is easily fixed by adding a configuration to .vimrc:

let g:NERDTreeWinSize = 20

Sometimes, when I was browsing through the folders I actually wanted to be able to make it larger so I could see the complete file names. This is also easy to achieve. Move your cursor to Nerdtree and toggle it using:

shift + a

Temporarily disable Syntastic on Vim

Every now and then I have to dig into other people’s code that doesn’t comply to my coding standards. When I make a change on these files, Syntastic lights up like a Christmas tree. Since this is not my code and I can’t really fix it, I prefer to temporarily disable Syntastic:

:set SyntasticToggleMode

Quick Vim setup

Once again I changed computers and had to install and configure Vim so it works the way I like it. This time I was a little smarter and created a script that I can use in the future to install it and configure it with one command.

It will install the latest version of vim(from github), download and install the most useful plugins and create a .vimrc file. Just clone the get-vim github project and run:


And you are set. Hope it is useful.

Sharing IDE configuration with EditorConfig

It has happened multiple times that I am doing a code review and I find issues like trailing white space or tabs instead of spaces. This annoys me because it is something that your editor should do for you for free. It annoys me even more when I ask the developer to configure their editor to remove trailing white space and they tell me they don’t know how to do it. In most scenarios they are using Eclipse or some other fancy IDE that I am not familiar with, so I can’t help them much. EditorConfig will help me with that problem.

From now on I plan to add an .editorconfig file to all my projects and simply ask my colleagues to install the plugin on their IDE.

Lets see how to install the plugin for VIM. Assuming you have pathogen installed you should only need this:

Read more »

Change syntastic default syntax checker

I have recently moved away from JSHint in favor of ESLint and it became annoying that syntastic uses JSHint to check my syntax. Luckily, this is easily configurable. To have syntastic use ESLint instead of JSHint I just added this to my .vimrc file:

let g:syntastic_javascript_checkers = ['eslint']

You can do this for any language that syntastic supports. The general format is:

let g:syntastic_<filetype>_checkers = ['<checker-name>']

You could even have more than one syntax checker per language if you wanted:

let g:syntastic_javascript_checkers = ['eslint', 'jshint']

Make vim Command-T ignore certain files

Since I have been working with Java I found annoying every time I used Command-T to look for a file it showed me not only the source code file, but also the .class file. Looking at the documentation I found that there is a way to have Command-T ignore certain files. Just add this to your .vimrc

set wildignore+=*.class

Configure syntastic to work fine with Android projects

Synstastic is a syntax checker for many programming languages, including Java. The problem that I was having is that for my Android project it wasn’t helping me at all because it couldn’t find any of the Android libraries and almost every line showed as an error.

The reason for this is that syntastic uses javac in the background to look at the file and find out if there are any errors. It does a good job for classes in the java standard library, but it doesn’t know where to find the Android SDK so it throws errors for every line that makes use of it. To fix this we need to add the java SDK to our path.

There are two ways of doing this. The first one will only last for the length of the vim session and will go away when you quit. Use this vim command:


Read more »

Increase number of files Command-T will search

I was having a problem with Vim’s Command-T plugin, where it didn’t find some files. Searching through the documentation I found the problem was that Command-T will search a maximum of 10,000 files by default. This can be changed by adding this to your .vimrc:

" Increase the number for files Command-T will search "
let g:CommandTMaxFiles=50000

Different settings for different language in vim

Recently I have been mostly working in JavaScript and per my project standards, all my tabs are replaced by 2 spaces. The problem with this is that for other projects in other programming languages the standard tab width is 4 spaces, so it becomes annoying to have to hit tab twice to indent a line correctly. To fix this you can declare settings specific for a language if you place them on ~/.vim/ftplugin/LANGUAGE.vim.

Since currently I am working on an Android app and I want a tab width of 4, I created the file ~/.vim/ftplugin/java.vim and added this content:

" Make tabs 4 spaces wide "
set tabstop=4
set shiftwidth=4