Format Problem with vim

Hi, there. Everyone had a great Thanksgiving?

I have a slice format problem when I am using vim to edit c++ source code. I don't know how to discribe the problem exactly. You see, usually when I use the command "vi hello.cpp" to write a code, it will have the format like this:

#include <iostream>

using namespace std;

int main()
{
        cout << "hello, world!" << endl;
        
        cin.get();cin.get();
        return 0;
}

Recently, I don't know what I did, when I do the same thing, it becomes like this:

#include <iostream>

using namespace std;

int main()
{
cout << "hello, world!" << endl;

cin.get();cin.get();
return 0;
}

I mean I could use <tab> to move around the code, but it would be unconvnient. Besides, usually when I used an open parenthesis or bracket, it would remind me to close it. Now the warning is gone, too.

Could anyone help me change vim back to the original setting?

Take a look in your home directory for a hidden file .exrc This is the vi customization file. Did you by chance delete it? or unwittingly modify it?

Here is a link for more information on setting it up and for customizing your vi options.

in the .exrc file you may have a entry like

set tabstop=
or se ts=

which means set the tabstop. You may set it and then check.
also check if your vi is vi and not vim. sometimes vi is aliased to vim or soft linked to vim. in that case your configuration file will not be .exrc. it will be .vimrc

There are a couple of more things that set the tabs

  1. autoindent
  2. smartindent
  3. cindents

to know more of these you can simple type h cindents in the vi editor's command mode i.e. the : mode

hope this helps

I believe smartindent is what you need. Try to enter the command

set smartindent

and see if this is what you want.

Thank you, guys. I didn't find the .exrc file. I think I might delete or damage it by incident. I think I just install vi again to see what will happen. Thanx again.

HOUSCOUS