Operating System - HP-UX
1830729 Members
2183 Online
110015 Solutions
New Discussion

How to remap the <TAB> key in vi ?

 
Graham Cameron_1
Honored Contributor

How to remap the <TAB> key in vi ?

How do I disable (or remap to 4 spaces) the tab key in vi insert mode?

I've tried various combinations in .exrc, like

map! " "

None of them work.
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
10 REPLIES 10
Carlos Fernandez Riera
Honored Contributor

Re: How to remap the <TAB> key in vi ?

I think you need
tab 4.


See man vi and ex
unsupported
Andreas Voss
Honored Contributor

Re: How to remap the <TAB> key in vi ?

Hi,

tab key can be manipulated with the tabstop setting:

in .exrc add entry:
set tabstop=#

where # is the new value (default is 8)

OR

in vi type ie:

:set tabstop=4

Regards
Carlos Fernandez Riera
Honored Contributor

Re: How to remap the <TAB> key in vi ?

vi
:set all


noautoindent mesg noslowopen
autoprint nomodelines tabstop=8
noautowrite nonumber taglength=0
nobeautify nonovice tags=tags /usr/lib/tags
directory=/var/tmp nooptimize tagstack
nodoubleescape paragraphs=IPLPPPQPP LIpplpipnpbp term=ansi
noedcompatible prompt noterse
noerrorbells noreadonly timeout
noexrc redraw timeoutlen=500
flash remap ttytype=ansi
hardtabs=8 report=5 warn
noignorecase scroll=16 window=32
keyboardedit sections=NHSHH HUuhsh+c wrapscan
keyboardedit! shell=/sbin/sh wrapmargin=0
nolisp shiftwidth=8 nowriteany
nolist noshowmatch
magic noshowmode
See man ex for

set hardtabs, tags, b
unsupported
Graham Cameron_1
Honored Contributor

Re: How to remap the <TAB> key in vi ?

Thanks guys but that doesn't fix my problem, probably my explanation was poor.
I want to prevent TAB (ie control-I) characters getting into my files in the first place.
All that "set tabstop" does is to set how many spaces are used to display each TAB.
"set hardtabs" seems to do the same, and I
can find no "tab 4" in any man page.

To see what I mean, run up vi and say
:set list
Go into insert mode and hit the TAB character a few times. What you will see is ^I^I^I...
What I want is spaces, not tabs.

Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Wodisch
Honored Contributor

Re: How to remap the <TAB> key in vi ?

Hello Graham,

I am pretty certain that you cannot do that with good old vi! Since Bill Joy has used "white space" as delimiter for the definition of mappings, and TAB and SPACE are, the only chance would be a "post-processing" of your file after saveing it. Then you would use some script for this (none does exist - you will have to it in perl or awk or such).

Sorry,
Wodisch
Eugen Cocalea
Respected Contributor

Re: How to remap the <TAB> key in vi ?

Hi,

I'm not a master of vi, but have you tried to map TAB to somethink like 4 * insert space? If I remember right, you can do:

: command

that repeats the command times.

E.
To Live Is To Learn
Graham Cameron_1
Honored Contributor

Re: How to remap the <TAB> key in vi ?

Thanks for all your help.

Wodisch came closest in confirming it cannot be done.

I guess I will have to continue, as before, with, in my .exrc file:

set shiftwidth=4 tabstop=4
map ^T :1,$ s/ / /g

(Where the first string is the tab character and the second is 4 spaces)
and then get all my users to remember to type ^T before exit.
Or write a wrapper.

Thanks again.
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Carlos Fernandez Riera
Honored Contributor

Re: How to remap the <TAB> key in vi ?

Do you know cb command?
unsupported
Suhas_3
Advisor

Re: How to remap the <TAB> key in vi ?

You need not worry about tabs while editing. After you finish eidting and come out of vi, you can use unix command "expand" to expand the tabs to spaces. see man expand
hope this helps.
Nathan Coulter
New Member

Re: How to remap the <TAB> key in vi ?

If you are using vim, you coud:

:set expandtab