Using tabs instead of spaces in IDLE?

Courageous jkraska at san.rr.com
Wed Feb 13 22:35:07 EST 2002


>to go when coding in Python.  Further, since Emacs (and I've heard, vim)
>support treating groups of spaces as a single tab (tab inserts n number of
>spaces, backspace takes you back n spaces), there really isn't much
>functional difference between the two when editing.

While I'm sure you know what you mean, other readers might not realize
that the genuinely useful capability of vim (and I suspect Emacs, if you
mean what I think you mean) is to not insert some constant 'n' spaces,
but rather to:

"insert just enough spaces to get you to the next tabstop".

And while vim indeed does just what I said, when you backspace over
these runs of spaces while in insert mode, it knows how those spaces
where generated and so:

"deletes any such spaces inserted through a tab, just as if
it were deleting a single tab."

This is a very useful capability. As for how to get it, one might
insert the following into their .vimrc:

set tabstop=8
set softtabstop=4 
set shiftwidth=4 
set et
"ascii-183==·
"ascii-187==»
set lcs=tab:»\ 
set list

The above configuration has the following properties:

1. "set tabstop=8". This leaves *hard* tabs at 8, so that whenever
you open a file with "real" tabs in it, they will have the same
indentation level as more, cat, lpr, and so forth are likely to.

2. "set softtabstop=4". This governs the behavior of the normal
tab key in vim.

3. "set shiftwidth=4". This sets autoindent to use a indentation
level of 4 after code blocks are begun.

4. "set et". This tells vim to never insert tabs. Use runs of
spaces instead.

5. "set lcs=tab:»\ ". This tells vim to use ascii-187 (the single
'>>' char) as a visible marker of all *real* tabs in your file.
This makes physical tabs as plain as day in your file: helpful
for seeing what's wrong with makefiles. Similar to the "Show-P"
feature in Word.

6. "set list". Turns #5 on.

Two notes. You can't type ascii 187 with an ordinary character.
In vim, you get it buy typing '<ctrl>V187'. The two lines before
the "set lcs" line are just vim comments that I have so that I
don't forget the numeric codes.

One last note. You're going to forget this eventually.

What if you want to type a *real* tab?

<ctrl>V<tab>

Or you can "set noet" to temporarily turn of tab expansion.

C//






More information about the Python-list mailing list