46

Using .vimrc for project specific settings

 5 years ago
source link: https://www.tuicool.com/articles/hit/zAJZ32e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:

set listchars=tab:\⇥\ ,trail:·,extends:>,precedes:<,nbsp:+

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

YjaAbyr.png!web

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 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, so we need to enable this feature in our main .vim/vimrc file:

" ~/.vim/vimrc
set exrc
set secure

The exrc setting adds searchin 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!

eqAvyya.png!web


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK