home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10700 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.9 KB  |  51 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!menudo.uh.edu!buster!uhura1!bryan
  3. From: bryan@uhura1.uucp (Bryan Curnutt)
  4. Subject: Re: Dear vi guru,
  5. Message-ID: <1992Sep3.163059.10935@uhura1.uucp>
  6. Reply-To: bryan%uhura1@uunet.uu.net
  7. Organization: Stoner Associates, Inc./DREM Incorporated, Houston Texas
  8. References: <1992Sep2.224136.24163@nsisrv.gsfc.nasa.gov> <1992Sep2.233330.18751@ncar.ucar.edu>
  9. Distribution: na
  10. Date: Thu, 3 Sep 1992 16:30:59 GMT
  11. Lines: 38
  12.  
  13. In article <1992Sep2.233330.18751@ncar.ucar.edu> tparker@music.scd.ucar.edu (Tom Parker) writes:
  14. >In article <1992Sep2.224136.24163@nsisrv.gsfc.nasa.gov> schieb@shark.gsfc.nasa.gov (Brian D. Schieber) writes:
  15. >>Dear vi guru,
  16. >> 
  17. >> I like to use tabs alot in just about every session of vi I
  18. >>work with, It would be great if I had a macro or whatever that
  19. >>could replace the tabs with the appropriate number of spaces
  20. >>in a file WHILE in vi. Do you have such a macro?
  21. >
  22. >Check if your system has the 'expand' command.  This command converts
  23. >tabs to spaces, and vice versa.
  24.  
  25. ... but is not what Brian asked for.
  26.  
  27. Assuming your tabs are for indentation at the beginning of the line
  28. only, i.e. that you don't have text characters followed by tabs,
  29. something simple like
  30.  
  31.     :map g :%s/^I/    /g^M
  32. [tab character]^^       ^^[carriage return]
  33.  
  34. will do what you want.
  35.  
  36. If your system does have the 'expand' command, then something like
  37.  
  38.     :map g :%!expand -4^M
  39.  
  40. will do the trick, and do it correctly (unlike the %s above, which
  41. only works if the tabs are all at the beginning or coincidentally
  42. aligned so they start at a tabstop).
  43.  
  44. There may be a simple way to correctly expand tabs from within vi
  45. without resorting to external programs, but I'm not really a guru,
  46. just a Joe Random User.
  47. -- 
  48. Any opinions above are mine, and do not necessarily reflect the views of SAI.
  49. Bryan Curnutt
  50. bryan%uhura1@uunet.uu.net
  51.