Linked Questions

52 votes
7 answers
11k views

Can I delete an entire line, except the line break?

A fairly common operation for me in Vim, since I am compulsive-obsessive and like to keep my files free of whitespace, is to delete the contents of an entire line, but not the line itself (i.e. not ...
7 votes
3 answers
2k views

How do I trim whitespace automatically?

I've been doing this: au BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif The problem is that it moves the cursor sometimes when I save the file.
28 votes
3 answers
10k views

What does `<Bar>` mean?

In answering a question just now, I mentioned using a normal mode key mapping that can be found at the Vim Tips Wiki. In the middle of explaining the key mapping, I realized that I had no idea what &...
2 votes
1 answer
201 views

Keep cursor position while removing control characters

Here is an attempt to write a function which will remove trashy characters (^F, ^S, ^Z, zero-width space, etc) on save, and keep cursor position. colorscheme desert set guifont=Consolas:h10 set ...
2 votes
1 answer
2k views

How do I remove newlines inside arbitrary xml tags matching a pattern?

I'm working with large xml files that have tags, and some are spread across multiple lines, and some are on a single line. I'd like them to all be on a single line. There are other tags in the files ...
5 votes
3 answers
4k views

How to remove trailing white-spaces automatically while typing?

I'm often editing code where others didn't care about trailing white-spaces. I'm using the TrimWhiteSpace()-function from this answer to remove white-spaces when saving the file. However that leaves ...
2 votes
2 answers
1k views

Removing redundant whitespaces on save/write

I want all redundant whitespaces to be removed on write/save. How can I do that? By redundant I mean ones that exists after the last character or if there's an empty line and it contains a few ...
3 votes
1 answer
945 views

Is there a nice way to remove semicolon in files using Vim?

Background: My development team decided to move to typescript and one of the style guidelines was to remove all semi-colons and they will probably do so in newer JavaScript files (I know its a bit ...
2 votes
3 answers
7k views

How can I remove additional whitespace in the middle of line?

I know how to remove trailing white spaces at the end of lines. Does anyone know how to remove white spaces in the middle of a line? The white space I mean is before tab and after tab characters. For ...
8 votes
1 answer
205 views

Running cleanup commands only for edited lines possible?

Referring to clean-up tasks like (but not limited to) the ones detailed in these questions: Re-indenting badly indented code What's the simplest way to strip trailing whitespace from all lines in ...