LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   vim: mark end-of-line? trim blank lines? (https://www.linuxquestions.org/questions/linux-software-2/vim-mark-end-of-line-trim-blank-lines-233111/)

prell 09-20-2004 06:54 PM

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!

dylbyrt45 09-20-2004 07:59 PM

Here is a quick reference link to vim, maybe it will be helpful.

http://www.vim.org/htmldoc/quickref.html

prell 09-20-2004 08:06 PM

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:

Code:

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:

Code:

autocmd BufWritePre *.c :%s/\s*$//
From what I've read, that should work fine.

prell 09-20-2004 11:04 PM

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.


All times are GMT -5. The time now is 06:13 PM.