Ray Shori
Ray Shori

Reputation: 21

Indentation of code while contributing to a github project

I am pretty new to "contributing to a github project" but excited to do so, I am wondering how do I get the indentation similar to the existing one while contributing to a github project. For example I use VIM and I have my own .vimrc file but when I fork and then clone a ruby project to contribute, how do I use the same indentation.

Upvotes: 2

Views: 503

Answers (4)

Ingo Karkat
Ingo Karkat

Reputation: 172510

There are several plugins that check for the indentation of an opened file and (if necessary) adapt the buffer's indent settings to it. My own plugin is called IndentConsistencyCop; the plugin page also contains links to alternatives. This is especially useful when submitting patches to many different projects, which may not even have consistent guidelines themselves.

If you're getting deeply involved in a few projects, I recommend some plugin that allows directory-local configuration. You just place your :setlocal expandtab tabstop=... into a .lvimrc file at the project's root. I recommend localrc.vim for this, because it also allows filetype-specific local configuration.

Upvotes: 2

echristopherson
echristopherson

Reputation: 7074

You can use smudge and clean filters (see this part of the Pro-Git book), and have the filters do whatever's necessary to change the tabs or spaces used to indent. That way you can work with whatever you're comfortable with and then convert it into the upstream version upon commit.

Upvotes: 2

Conner
Conner

Reputation: 31040

Many projects have :help modeline options in the comments at the bottom of the file. For example,

# vim: noet

These kind of options will override the options in your ~/.vimrc. Project maintainers often put these in for consistency across the code. Some projects don't have these but still conform to a set of rules. For example, they may use tabs instead of hard spaces. If you use hard spaces and are contributing to a project that uses tabs then it's best to keep it consistent. You can accomplish this by several means. One example would be to set an autocommand for that project in your vimrc like this

au BufRead,BufNewFile /path/to/project/** set noet

so that you don't forget to adhere to that projects wishes. Another way is to set it manually. You could also change the projects tabs to hard spaces and then change them back. For example you can do

:retab!

to change the tabs to your preferences. Then when you're done editing you can change the settings back to their preferences and do another:

:set noet
:retab!

Upvotes: 2

ronalchn
ronalchn

Reputation: 12335

I use this in my .vimrc file:

set softtabstop=2
set shiftwidth=2

This changes the indentation settings.

If you don't want to change your global vim settings, you might need to use an extension, eg. http://www.vim.org/scripts/script.php?script_id=1408

Upvotes: 0

Related Questions