eabates
eabates

Reputation: 898

Vim, indentation not saving

I just looked closely at some of the files I wrote in Vim and pushed up to Github from a local Git repo. Much of the indentation that appears in Vim is not transferring to Github. Is there a setting I need to change in .vimrc to make sure that my indentation from Vim is saved?

Upvotes: 2

Views: 1731

Answers (1)

mikey
mikey

Reputation: 1313

It sounds like you are possibly using tab characters. Tab characters can be interpreted differently depending on what editor you use, although it does seem strange they don't show up at all in the Github view.

I'd recommend changing tab characters to spaces. Within Vim you can specify settings with ':'.

To have them persist between sessions you'll need to store it in a file called .vimrc (just you use 'set' instead of ':').

To insert space characters whenever the tab key is pressed, set the 'expandtab' option:

:set expandtab

You can then designate how many white space characters a tab inserts:

To control the number of space characters that will be inserted when the tab key is pressed, set the 'tabstop' option. For example, to insert 4 spaces for a tab, use:

:set tabstop=4

I personally use tabstop=2.

If that doesn't work, are you able to post your .vimrc containing whatever plugins/configuration you have, as well as a link to the file on github so we can see :)?

Let us know how you go!

Also re; using cat on the file - try:

cat -A [filename]

This should list hidden characters that perhaps weren't expected.

Upvotes: 2

Related Questions