FUN FACT: vim: newlines appear like spaces at end of lines in visual mode but not otherwise (and related relations and discrepancies)
If in vim you were to do (in command mode) a search for spaces at end of lines
'/\s$' any line ending with
'\n' (newline char) will not be included.
Also if you were to use
'$' to go to the end of the line you would be under the
last character (e.g. if the line ended with a full stop the cursor would be at
the full stop). However if you select it in visual mode you will see that
there's a space: exactly where the newline is!
Incidentally in C dialect
isspace('\n') == 1;
'\n' is known as a newline. But
then if you look at regex(7) you will see that character class
'[[:space:]]' corresponds to wctype(3)
classes. If you then were to check that manpage you'd see:
"space" - realizes the isspace(3) classification function
Then if you check
isspace(3) you'll see what I said:
isspace() checks for white-space characters. In the "C" and "POSIX" locales, these are: space, form-feed (
'\f'), newline (
'\n'), carriage return (
'\r'), horizontal tab (
'\t'), and vertical tab (
But yet doing:
grep -E '[[:space:]]'
On a file will not show blank lines (but see bottom line)! If you do
grep '^$' it will (unless of course there are actually spaces there
because that's not an empty line!).
BOTTOM LINE: Although newlines can be considered spaces it's not necessarily what you will see all the time; in some contexts it will be but in other contexts it will not be. Looks certainly are deceiving and here even things you cannot see are deceiving! You see what looks like an empty line but if there is a single space there it's not technically empty - but you won't know that unless you search for spaces or otherwise search for empty lines!
This incidentally can be seen when you do a diff of two files where a space was added or deleted from a line but with no other change (coloured diff output will make it easier to see obviously).