Linked Questions

52 votes
7 answers

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 ...
Andrew Ferrier's user avatar
28 votes
3 answers

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 &...
Christopher Bottoms's user avatar
7 votes
3 answers

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.
Neil G's user avatar
  • 193
5 votes
3 answers

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 ...
Patrick B.'s user avatar
2 votes
3 answers

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 ...
stdcall's user avatar
  • 1,029
2 votes
2 answers

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 ...
Kolayn's user avatar
  • 133
8 votes
1 answer

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 ...
guido's user avatar
  • 1,757
3 votes
1 answer

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 ...
TheLazyChap's user avatar
2 votes
1 answer

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 ...
john c. j.'s user avatar
2 votes
1 answer

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 ...
JHiant's user avatar
  • 123