Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using .vimrc for Project-Specific Settings

DZone's Guide to

Using .vimrc for Project-Specific Settings

Let's take a look at this brief article that explains how to change your settings so that you can use tabs instead of spaces for a specific project.

· Integration Zone ·
Free Resource

How to Transform Your Business in the Digital Age: Learn how organizations are re-architecting their integration strategy with data-driven app integration for true digital transformation.

I'm more of a spaces person than a tabs person when it comes to source code, and in Vim, I like to see the tab characters, so I have this setting:

This places a handy ⇥ character so that I can see the tabs:

I'm currently working on a codebase where the coding style is to use tabs, so I need to change my settings. One option is to use EditorConfig, for the formatting changes, but it doesn't help with the Vim-specific display setting.

To solve this, I'm using a .vimrc file at the root of my project with this setting:

" ~/projects/work/client_name/project_name/.vimrc
set listchars=tab:\ \ ,trail:·,extends:>,precedes:<,nbsp:+

By default, Vim doesn't read .vimrc files in the current directory, so we need to enable this feature in our main .vim/vimrc file:

" ~/.vim/vimrc
set exrc
set secure

The exrc setting adds searching of the current directory for the .vimrc file and loads it.

Enabling the secure setting ensures that shell, autocmd and write commands are not allowed in the .vimrc file that was found in the current directory as there's no need to take risks.

Now, I can have tabs displayed in all my other projects, but in this specific one, they aren't!

Make your mark on the industry’s leading annual report. Fill out the State of API Integration 2019 Survey and receive $25 to the Cloud Elements store.

Topics:
integration ,tutorial ,code snippets ,vim

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}