I have XML entries that span two or more lines sometimes, and so I can look for something like this:
something on one line
But if I try the vim command /something on one line
and the line is like this:
something on one
line
then it doesn't find it, because the second text block is actually seen as
something on one^J line
Which might have something to do with the fact that I'm using a DOS formatted file.
How can I get vim search to ignore whitespace and newlines?
One way to make sure to remove all trailing whitespace in a file is to set an autocmd in your . vimrc file. Every time the user issues a :w command, Vim will automatically remove all trailing whitespace before saving.
The correct command line key for diff should be -w , to ignore all whitespace changes.
Use backslash \ before space in search string.
In vim search, _s
means a new line, a space or a tab. So you can try something such as:
/something on one\_s*line
to match the example string you used as example.
Replacing the spaces with
\_s\+
manually is cumbersome. The Search for visually selected text topic on the Vim Tips Wiki has a mapping that does this for you for the current visual selection. You can use it like the built-in *
mapping, to search (ignoring spaces) for the current selection. Very handy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With