SLotreck
SLotreck

Reputation: 61

How to resolve tabs/spaces issue between Atom and Vim

I prefer to write my scripts in Atom on my local machine. However, I run a lot of them on my university's cluster, and when I need to change something small, I like to just open it in vim and make the change, rather than editing in Atom on my local machine and pushing/pulling from GitHub.

However, when I open my script in vim, using the tab button, the cursor moves in 8 spaces. This is particularly annoying because I have to do all new indents with spaces.

In Atom, my tab length is set to 4 spaces, and the tab type is set to auto. I haven't done anything to change vim from the defaults.

Should I be changing my tab length in Atom, or is there some better solution?

Upvotes: 0

Views: 312

Answers (1)

bk2204
bk2204

Reputation: 76459

There are several settings you can use to control this in Vim. They are as follows:

  • tabstop, shiftwidth, and softtabstop control the width of indents. There are differences between them and you should read the documentation for each to understand what they do, but roughly, if you always want to insert only tabs or only spaces, then they should all be set to the width of your indent (e.g., 4 for 4 spaces or a 4-space tab).
  • expandtab controls whether to insert spaces (expandtab) or tabs (noexpandtab).

You can set these options in your .vimrc to have some defaults and you can also be explicit about particular file types if you prefer. For example, if you know that Python prefers 4-space indents and Ruby prefers 2-spaces indents, but Go prefers 8-space tabs, you can write this:

  au FileType go            setl ts=8 sw=8 sts=8 noet
  au FileType python        setl ts=4 sw=4 sts=4 et
  au FileType ruby          setl ts=2 sw=2 sts=2 et

Upvotes: 0

Related Questions