Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 09-20-2004, 07:54 PM   #1
Registered: Jul 2004
Posts: 73

Rep: Reputation: 15
vim: mark end-of-line? trim blank lines?

I'm wondering if I can convince vim to do either of the following:
  • Display a marker for the end of line. Similar to what :set list does, but without displaying tabs and such.
  • I like the auto-indenting feature of vim, but I wonder if I can get it to trim lines to /^$/ if they match /^\s*$/?

Does anyone know?

Thanks for taking the time to read!
Old 09-20-2004, 08:59 PM   #2
Registered: Sep 2003
Location: Dallas
Distribution: Suse 9.1 pro
Posts: 37

Rep: Reputation: 15
Here is a quick reference link to vim, maybe it will be helpful.
Old 09-20-2004, 09:06 PM   #3
Registered: Jul 2004
Posts: 73

Original Poster
Rep: Reputation: 15
I did some searching around once I realized that what I really wanted was a global replace, and I just knew that vim must have macros with bindings for different states of the application, and with much persistence I was proven correct! Check it out:

autocmd BufWritePre * :%s/\s*$//
I put that in my ~/.vimrc file, and it makes me happy. It does a global replace before writing the buffer. Notice that it will do this for every file you write. If you want to only have it alter C files, for example, change the line to look like this:

autocmd BufWritePre *.c :%s/\s*$//
From what I've read, that should work fine.
Old 09-21-2004, 12:04 AM   #4
Registered: Jul 2004
Posts: 73

Original Poster
Rep: Reputation: 15
Does anyone know, off the top of their head, how to make this restore the cursor position after completion? I know vi commands to do that but I don't know that I could include them in one line, or perhaps as an addendum to that regex or something.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 10:42 AM
trim a line schneidz Programming 2 10-07-2005 07:47 PM
printer printing vertical lines at beginning and end of lines makhand Linux - Hardware 0 09-02-2005 03:03 PM
vim remove LF at the end michal017 Linux - Software 4 11-19-2004 01:26 AM
Replace blank/almost blank lines in file Wynd Linux - General 3 01-27-2004 05:49 PM

All times are GMT -5. The time now is 08:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration