chris@mimsy.UUCP (Chris Torek) (02/04/88)
In article <5135@well.UUCP> daniels@well.UUCP (Dan Smith, Social Mammal...) writes: > Here's an area I don't know a lot about, so bear with me... what >about having a termcap entry invoked when you want to solve this >"tabs-to-spaces" problem? The termcap entry (ta <str>) would be just like >the one you usually use, except it would inform vi that your terminal really >handles tabs as spaces. I would object very much to an editor that sometimes but not always quietly changes the TABs I type to spaces (some versions of the Rand Editor did this, but at least it always did it). The `ta=<str>' termcap entry is provided for terminals which can move the cursor to the next tabstop (a column such that (column mod 8) = 1, if you start counting from `col 1' as most terminals do), but not via the ASCII code 1/1 (octal), or 9 decimal, or '\t'. If the sequence control-A 8 RETURN moves the cursor to a tabstop, you can put `ta=^A8\r' into the termcap. (Actually, the tabstop concept is modified by another termcap entry which tells how far apart tabs are on the terminal. Or if not, it should be.) Back to the original question (which was `how can I tell vi that when I type TAB I want the appropriate number of spaces inserted instead'), the answer is that, purely within vi, you cannot. The following will work, but painfully slowly: :map! ^V^V^I ^V^V^V^V^I^V^[:.!expand^V^MA (the ^Vs shown are those you type, not those that are echoed; only half as many are echoed, and the ^Is are echoed as some number of spaces). This also moves you from wherever you were in the line to the end of the line. (Use the appropriate `pr' command if you do not have `expand'.) The sixty-four dollar question: Why do you want your tabs changed to spaces? Perhaps you can invoke `expand' (or `pr') on files just before you need them expanded. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
dhesi@bsu-cs.UUCP (Rahul Dhesi) (02/04/88)
[big discussion on tabs in vi] To all editor designers: There is much confusion about tabs. Here is a quick analysis and a specific suggestion. There is a conceptual difference between (a) typing the tab key, (b) inserting a tab character in a file. When you type a tab character, you're saying "please move the cursor to the next tab stop on my screen". When you insert a tab character in a file, you inserting an ASCII 0x09 (or equivalent in your favorite character set) in the file. The two are not equivalent. If the user has set tabs on the screen to be every 3 spaces, then when the user types a tab, move the cursor to the next tab stop. DON'T insert a tab character in the file when this happens! Instead, insert any combination of tabs and spaces that will cause the file, when typed to the screen with tabs set at every 8 spaces, to look correct. In other words, tabs in a file should always be 8-space tabs. Tabs on the screen should be whatever the user wants them to be. Similarly, if the user deletes a single character, delete only a single character as things appear on the screen. If that single character happened to be a tab character in the original file, replace it with enough spaces such that the net effect is to move text back by only one space. Follow-ups to comp.editors, assuming such a newsgroup exists. -- Rahul Dhesi UUCP: <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi