Mapping <Tab> key in vi or vim

Mapping <Tab> key in vi or vim

Post by Steve D. Perkin » Sun, 31 Dec 1899 09:00:00



I'm trying to find a line I can add to .exrc or .vimrc (for vi on HP-UX
at work and vim on Linux at home) that will map the <Tab> key to insert
three spaces instead of a tab character... this being a requirement of
the coding standards for the project I'm currently working on.  I've
been using vi for years, but have never really found the need to map
characters or tinker too much with .exrc or .vimrc (other than turning
line-numbering on by default)... can anyone give me a hand with the
line that needs to be added for this mapping?

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Mapping <Tab> key in vi or vim

Post by Peter T. Breue » Sun, 31 Dec 1899 09:00:00



Quote:> at work and vim on Linux at home) that will map the <Tab> key to insert
> three spaces instead of a tab character... this being a requirement of

It'll be something like

:imap <tab> <   >

In your vimrc. I had to put angle brackets here to show what I meant.
Mind you .. I don't see how that would parse! DOn't you just want
something like:

:set expandtab

  In Insert mode: Use the appropriate number of spaces to insert a
  <Tab>.  Spaces are used in indents with the '>' and '<' commands and
  when 'autoindent' is on.  To insert a real tab when 'expandtab' is on,
  use CTRL-V<Tab>.  See also |:retab| and |ins-expandtab|.

:set tabstop=3

Quote:> the coding standards for the project I'm currently working on.  I've
> been using vi for years, but have never really found the need to map
> characters or tinker too much with .exrc or .vimrc (other than turning
> line-numbering on by default)... can anyone give me a hand with the
> line that needs to be added for this mapping?

vim has a help command. That's where I'm reading this info from.

Peter

 
 
 

Mapping <Tab> key in vi or vim

Post by Lori Holder-Web » Sun, 31 Dec 1899 09:00:00



> :set tabstop=3

> > the coding standards for the project I'm currently working on.  I've
> > been using vi for years, but have never really found the need to map
> > characters or tinker too much with .exrc or .vimrc (other than turning
> > line-numbering on by default)... can anyone give me a hand with the
> > line that needs to be added for this mapping?

The O'Reilly vi book notes that when you change the tabstop like this,
the tabs will still get expanded using an 8 character tab stop in every
other UNIX program.  Don't know if this makes a difference for your
prog, but thought it worth a mention.
Quote:

> vim has a help command. That's where I'm reading this info from.

> Peter

 
 
 

Mapping <Tab> key in vi or vim

Post by Steve D. Perkin » Sun, 31 Dec 1899 09:00:00


Quote:> The O'Reilly vi book notes that when you change the tabstop like this,
> the tabs will still get expanded using an 8 character tab stop in
every
> other UNIX program.  Don't know if this makes a difference for your
> prog, but thought it worth a mention.

Well, the idea is that by literally using spaces instead of tabstop
characters (mapped as if you had hit the space bar three times instead
of the Tab key once)... then the indentation would be the same no
matter which editor you're using or which platform you're using it
under.

It turns out that the 'expandtab' option did exactly what I was looking
for... I just wish I could find a workaround that could also be used on
plain vi (that's a vim-only extention).

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Mapping <Tab> key in vi or vim

Post by friedhelm.mehn.. » Sun, 31 Dec 1899 09:00:00



: It turns out that the 'expandtab' option did exactly what I was looking
: for... I just wish I could find a workaround that could also be used on
: plain vi (that's a vim-only extention).

Well, you could use vi's search and replace function to simply replace
all tabs with tree spaces. Something like:

   :1,$s/<TAB>/   /g

Regards,
Friedhelm

--
Microsoft is NOT the answer. Microsoft is the Question.
The answer is: "NO!"
-------------------------------------------------------------------
Friedhelm Mehnert,  Berliner Allee 42,  22850 Norderstedt,  Germany

-------------------------------------------------------------------

 
 
 

1. How to map <tab> to <sp><sp><sp>?

   The subject pretty much says it all.  How do I map a tab to three
spaces?  On SunOS 4.1.3, vi says "Too dangerous to map that" when I do a
':map tab "   "'.
--
Russell Mosemann     Concordia College      Voice: (402) 643-7445
Computing Center     Seward, NE 68434       Fax:   (402) 643-4073
"We ARE the majority.  It's just that you out-number us!"

2. Sparc 10 Memory Question

3. <Alt>+<key> = <Esc><key> ?

4. LDAP scan on ports 389 & 636, (IP Spoof???)

5. Konsole and <ins> <del> keys

6. SKB allocation failed

7. VI, replace <TAB> with <SPACE>

8. Help sending COOKIES/Apache

9. replacing <ESC>= by the <tab> key in ksh ?

10. How do you map a <Tab> in vi ?

11. <><><> MOUNTING EXTENDED PARTITION <><><>

12. Wanted: <><><> Unix Specialist <><><>

13. LILO help <><><><><><>