Loading ...
Sorry, an error occurred while loading the content.

RE: Removing trailing spaces

Expand Messages
  • HALIM,SALMAN (HP-NewJersey,ex2)
    hmm.. i use the following: TODO: have this respect sigdashes and only do its work if not in insert mode au BufWritePre * silent! call StripTrailingSpaces()
    Message 1 of 6 , Jan 29, 2002
    • 0 Attachment
      hmm.. i use the following:

      " TODO: have this respect sigdashes and only do its work if not in insert
      mode
      au BufWritePre * silent! call StripTrailingSpaces()
      function! StripTrailingSpaces()
      let currPos=Mark()
      exec '%s:\s\+$::e'
      exe currPos
      endfunction

      where 'Mark()' is simply what i use to save and restore the cursor position
      without corrupting any of my actual marks. (it's a function by Benji Fisher
      -- you could just do a normal ma and a normal `a at the end instead.)

      basically, this will strip all trailing spaces from the current document
      every time you save the file.

      salman.

      -----Original Message-----
      From: Ali Akcaagac [mailto:ali.akcaagac@...-wilhelmshaven.de]
      Sent: Tuesday, January 29, 2002 2:29 PM
      To: Vim Developer
      Subject: Re: Removing trailing spaces


      On Tue, 2002-01-29 at 20:20, Tomas Ogren wrote:
      > > I while back, I believe someone posted a script or something that would
      > > remove trailing spaces from a line.
      >
      > :s/ *$//

      :%s/[ <TAB>]*$//g

      <TAB> = press tab button... removes either trailing spaces and tabs
      from all lines :)

      :%s/^ //g

      removes leading spaces e.g. if you have a sourcecode that has all lines
      starting with 1-x spaces. then you can recall this as often to move the
      lines back to 1st char.

      --
      Name....: Ali Akcaagac
      Status..: Student Of Computer & Economic Science
      E-Mail..: mailto:ali.akcaagac@...-wilhelmshaven.de
      WWW.....: http://www.fh-wilhelmshaven.de/~akcaagaa
    Your message has been successfully submitted and would be delivered to recipients shortly.