Why don't I see the difference between two different files in insert mode in vim?
Let's create two files:
$ echo -n 'test' > test.txt
$ wc test.txt
0 1 4 test.txt
The file test.txt doesn't contain the trailing newline.
$ echo 'test' > test_n.txt
$ wc test_n.txt
1 1 5 test_n.txt
The file test_n.txt contains the trailing newline.
The above two files are obviously different, but the preview of both files in vim in insert mode does not contain any differences:
$ vim test.txt

$ vim test_n.txt

Why is there no difference (new line or some special distinction)?
And what can I do to add or remove such an additional character in vim in insert mode?
vim newlines vi-mode
|
show 1 more comment
Let's create two files:
$ echo -n 'test' > test.txt
$ wc test.txt
0 1 4 test.txt
The file test.txt doesn't contain the trailing newline.
$ echo 'test' > test_n.txt
$ wc test_n.txt
1 1 5 test_n.txt
The file test_n.txt contains the trailing newline.
The above two files are obviously different, but the preview of both files in vim in insert mode does not contain any differences:
$ vim test.txt

$ vim test_n.txt

Why is there no difference (new line or some special distinction)?
And what can I do to add or remove such an additional character in vim in insert mode?
vim newlines vi-mode
4
":set list" would show the difference, and there's a mode which you can inspect. Both are in the help-files.
– Thomas Dickey
9 hours ago
Thank you @ThomasDickey I didn't know this option before.
– simhumileco
9 hours ago
1
@ThomasDickey if you want to add an answer it will be probably the accepted answer. Thank you.
– simhumileco
9 hours ago
1
@filbranden please don't post answers in comments. Answers in comments cannot be voted on by the community and don't mark the question as answered.
– terdon♦
8 hours ago
1
@ThomasDickey see above. Please post that as an answer.
– terdon♦
8 hours ago
|
show 1 more comment
Let's create two files:
$ echo -n 'test' > test.txt
$ wc test.txt
0 1 4 test.txt
The file test.txt doesn't contain the trailing newline.
$ echo 'test' > test_n.txt
$ wc test_n.txt
1 1 5 test_n.txt
The file test_n.txt contains the trailing newline.
The above two files are obviously different, but the preview of both files in vim in insert mode does not contain any differences:
$ vim test.txt

$ vim test_n.txt

Why is there no difference (new line or some special distinction)?
And what can I do to add or remove such an additional character in vim in insert mode?
vim newlines vi-mode
Let's create two files:
$ echo -n 'test' > test.txt
$ wc test.txt
0 1 4 test.txt
The file test.txt doesn't contain the trailing newline.
$ echo 'test' > test_n.txt
$ wc test_n.txt
1 1 5 test_n.txt
The file test_n.txt contains the trailing newline.
The above two files are obviously different, but the preview of both files in vim in insert mode does not contain any differences:
$ vim test.txt

$ vim test_n.txt

Why is there no difference (new line or some special distinction)?
And what can I do to add or remove such an additional character in vim in insert mode?
vim newlines vi-mode
vim newlines vi-mode
edited 9 hours ago
simhumileco
asked 9 hours ago
simhumilecosimhumileco
20719
20719
4
":set list" would show the difference, and there's a mode which you can inspect. Both are in the help-files.
– Thomas Dickey
9 hours ago
Thank you @ThomasDickey I didn't know this option before.
– simhumileco
9 hours ago
1
@ThomasDickey if you want to add an answer it will be probably the accepted answer. Thank you.
– simhumileco
9 hours ago
1
@filbranden please don't post answers in comments. Answers in comments cannot be voted on by the community and don't mark the question as answered.
– terdon♦
8 hours ago
1
@ThomasDickey see above. Please post that as an answer.
– terdon♦
8 hours ago
|
show 1 more comment
4
":set list" would show the difference, and there's a mode which you can inspect. Both are in the help-files.
– Thomas Dickey
9 hours ago
Thank you @ThomasDickey I didn't know this option before.
– simhumileco
9 hours ago
1
@ThomasDickey if you want to add an answer it will be probably the accepted answer. Thank you.
– simhumileco
9 hours ago
1
@filbranden please don't post answers in comments. Answers in comments cannot be voted on by the community and don't mark the question as answered.
– terdon♦
8 hours ago
1
@ThomasDickey see above. Please post that as an answer.
– terdon♦
8 hours ago
4
4
":set list" would show the difference, and there's a mode which you can inspect. Both are in the help-files.
– Thomas Dickey
9 hours ago
":set list" would show the difference, and there's a mode which you can inspect. Both are in the help-files.
– Thomas Dickey
9 hours ago
Thank you @ThomasDickey I didn't know this option before.
– simhumileco
9 hours ago
Thank you @ThomasDickey I didn't know this option before.
– simhumileco
9 hours ago
1
1
@ThomasDickey if you want to add an answer it will be probably the accepted answer. Thank you.
– simhumileco
9 hours ago
@ThomasDickey if you want to add an answer it will be probably the accepted answer. Thank you.
– simhumileco
9 hours ago
1
1
@filbranden please don't post answers in comments. Answers in comments cannot be voted on by the community and don't mark the question as answered.
– terdon♦
8 hours ago
@filbranden please don't post answers in comments. Answers in comments cannot be voted on by the community and don't mark the question as answered.
– terdon♦
8 hours ago
1
1
@ThomasDickey see above. Please post that as an answer.
– terdon♦
8 hours ago
@ThomasDickey see above. Please post that as an answer.
– terdon♦
8 hours ago
|
show 1 more comment
1 Answer
1
active
oldest
votes
vim has a mode "eol" (for end-of-line) to tell what to if the last line in the file lacks a newline character. You can see all of the mode settings in vim (or any program like vi) by
:set all
POSIX vi does not have a feature for this: files are either zero-length, or have a trailing newline. That's because POSIX vi only deals with text files, which by definition are lines that end with newlines. In a quick check, nvi and elvis do not have modes for this. In my comment, I had forgotten a detail of vim: unlike vile, a ":set list" does not readily show the missing newline. Here's what I see in vim:
ssss$
test$
~
~
while in vile:
ssss^J
test
~
~
For either editor, you can read the file in, change the mode, e.g.,
:set noeol
and write the file out, to get a newline on the updated file. Rather than showing it directly, you can modify the status line of vim to show this information. By default, it does not appear to do this, but some packagers have customized this, e.g.,
"foo" [noeol] 2L, 9C 1,1 All
One of the comments suggests using the "?" modifier of the set command, e.g.,
:set eol?
which might show something like this:
noendofline 2,1 All
but in insert-mode, that is replaced by
-- INSERT -- 2,1 All
so the status line seems the right place to maintain this information.
The features have been there a while:
The
eolfeature first appeared in vim 2.4 (July 1994), according to a comment in its source code.vile's
newlinemode appeared in July 1993.
(nvi, elvis, vim and vile all handle binary files in addition to the POSIX vi's text files).
1
almost 20 years using vim, and I still learn new things about it. and I'm still scared of emacs. :D
– Tim Kennedy
8 hours ago
1
In vim, you can also do:set eol?to see whether eol is on or off, so you don't have to look through all the output of:set all.
– Kevin
4 hours ago
A less confusing way of saying "files are either zero-length, or have a trailing newline" is "all lines end with a newline, and a text file is a sequence of zero or more lines".
– R..
13 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503961%2fwhy-dont-i-see-the-difference-between-two-different-files-in-insert-mode-in-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
vim has a mode "eol" (for end-of-line) to tell what to if the last line in the file lacks a newline character. You can see all of the mode settings in vim (or any program like vi) by
:set all
POSIX vi does not have a feature for this: files are either zero-length, or have a trailing newline. That's because POSIX vi only deals with text files, which by definition are lines that end with newlines. In a quick check, nvi and elvis do not have modes for this. In my comment, I had forgotten a detail of vim: unlike vile, a ":set list" does not readily show the missing newline. Here's what I see in vim:
ssss$
test$
~
~
while in vile:
ssss^J
test
~
~
For either editor, you can read the file in, change the mode, e.g.,
:set noeol
and write the file out, to get a newline on the updated file. Rather than showing it directly, you can modify the status line of vim to show this information. By default, it does not appear to do this, but some packagers have customized this, e.g.,
"foo" [noeol] 2L, 9C 1,1 All
One of the comments suggests using the "?" modifier of the set command, e.g.,
:set eol?
which might show something like this:
noendofline 2,1 All
but in insert-mode, that is replaced by
-- INSERT -- 2,1 All
so the status line seems the right place to maintain this information.
The features have been there a while:
The
eolfeature first appeared in vim 2.4 (July 1994), according to a comment in its source code.vile's
newlinemode appeared in July 1993.
(nvi, elvis, vim and vile all handle binary files in addition to the POSIX vi's text files).
1
almost 20 years using vim, and I still learn new things about it. and I'm still scared of emacs. :D
– Tim Kennedy
8 hours ago
1
In vim, you can also do:set eol?to see whether eol is on or off, so you don't have to look through all the output of:set all.
– Kevin
4 hours ago
A less confusing way of saying "files are either zero-length, or have a trailing newline" is "all lines end with a newline, and a text file is a sequence of zero or more lines".
– R..
13 mins ago
add a comment |
vim has a mode "eol" (for end-of-line) to tell what to if the last line in the file lacks a newline character. You can see all of the mode settings in vim (or any program like vi) by
:set all
POSIX vi does not have a feature for this: files are either zero-length, or have a trailing newline. That's because POSIX vi only deals with text files, which by definition are lines that end with newlines. In a quick check, nvi and elvis do not have modes for this. In my comment, I had forgotten a detail of vim: unlike vile, a ":set list" does not readily show the missing newline. Here's what I see in vim:
ssss$
test$
~
~
while in vile:
ssss^J
test
~
~
For either editor, you can read the file in, change the mode, e.g.,
:set noeol
and write the file out, to get a newline on the updated file. Rather than showing it directly, you can modify the status line of vim to show this information. By default, it does not appear to do this, but some packagers have customized this, e.g.,
"foo" [noeol] 2L, 9C 1,1 All
One of the comments suggests using the "?" modifier of the set command, e.g.,
:set eol?
which might show something like this:
noendofline 2,1 All
but in insert-mode, that is replaced by
-- INSERT -- 2,1 All
so the status line seems the right place to maintain this information.
The features have been there a while:
The
eolfeature first appeared in vim 2.4 (July 1994), according to a comment in its source code.vile's
newlinemode appeared in July 1993.
(nvi, elvis, vim and vile all handle binary files in addition to the POSIX vi's text files).
1
almost 20 years using vim, and I still learn new things about it. and I'm still scared of emacs. :D
– Tim Kennedy
8 hours ago
1
In vim, you can also do:set eol?to see whether eol is on or off, so you don't have to look through all the output of:set all.
– Kevin
4 hours ago
A less confusing way of saying "files are either zero-length, or have a trailing newline" is "all lines end with a newline, and a text file is a sequence of zero or more lines".
– R..
13 mins ago
add a comment |
vim has a mode "eol" (for end-of-line) to tell what to if the last line in the file lacks a newline character. You can see all of the mode settings in vim (or any program like vi) by
:set all
POSIX vi does not have a feature for this: files are either zero-length, or have a trailing newline. That's because POSIX vi only deals with text files, which by definition are lines that end with newlines. In a quick check, nvi and elvis do not have modes for this. In my comment, I had forgotten a detail of vim: unlike vile, a ":set list" does not readily show the missing newline. Here's what I see in vim:
ssss$
test$
~
~
while in vile:
ssss^J
test
~
~
For either editor, you can read the file in, change the mode, e.g.,
:set noeol
and write the file out, to get a newline on the updated file. Rather than showing it directly, you can modify the status line of vim to show this information. By default, it does not appear to do this, but some packagers have customized this, e.g.,
"foo" [noeol] 2L, 9C 1,1 All
One of the comments suggests using the "?" modifier of the set command, e.g.,
:set eol?
which might show something like this:
noendofline 2,1 All
but in insert-mode, that is replaced by
-- INSERT -- 2,1 All
so the status line seems the right place to maintain this information.
The features have been there a while:
The
eolfeature first appeared in vim 2.4 (July 1994), according to a comment in its source code.vile's
newlinemode appeared in July 1993.
(nvi, elvis, vim and vile all handle binary files in addition to the POSIX vi's text files).
vim has a mode "eol" (for end-of-line) to tell what to if the last line in the file lacks a newline character. You can see all of the mode settings in vim (or any program like vi) by
:set all
POSIX vi does not have a feature for this: files are either zero-length, or have a trailing newline. That's because POSIX vi only deals with text files, which by definition are lines that end with newlines. In a quick check, nvi and elvis do not have modes for this. In my comment, I had forgotten a detail of vim: unlike vile, a ":set list" does not readily show the missing newline. Here's what I see in vim:
ssss$
test$
~
~
while in vile:
ssss^J
test
~
~
For either editor, you can read the file in, change the mode, e.g.,
:set noeol
and write the file out, to get a newline on the updated file. Rather than showing it directly, you can modify the status line of vim to show this information. By default, it does not appear to do this, but some packagers have customized this, e.g.,
"foo" [noeol] 2L, 9C 1,1 All
One of the comments suggests using the "?" modifier of the set command, e.g.,
:set eol?
which might show something like this:
noendofline 2,1 All
but in insert-mode, that is replaced by
-- INSERT -- 2,1 All
so the status line seems the right place to maintain this information.
The features have been there a while:
The
eolfeature first appeared in vim 2.4 (July 1994), according to a comment in its source code.vile's
newlinemode appeared in July 1993.
(nvi, elvis, vim and vile all handle binary files in addition to the POSIX vi's text files).
edited 3 hours ago
answered 8 hours ago
Thomas DickeyThomas Dickey
53.6k5101175
53.6k5101175
1
almost 20 years using vim, and I still learn new things about it. and I'm still scared of emacs. :D
– Tim Kennedy
8 hours ago
1
In vim, you can also do:set eol?to see whether eol is on or off, so you don't have to look through all the output of:set all.
– Kevin
4 hours ago
A less confusing way of saying "files are either zero-length, or have a trailing newline" is "all lines end with a newline, and a text file is a sequence of zero or more lines".
– R..
13 mins ago
add a comment |
1
almost 20 years using vim, and I still learn new things about it. and I'm still scared of emacs. :D
– Tim Kennedy
8 hours ago
1
In vim, you can also do:set eol?to see whether eol is on or off, so you don't have to look through all the output of:set all.
– Kevin
4 hours ago
A less confusing way of saying "files are either zero-length, or have a trailing newline" is "all lines end with a newline, and a text file is a sequence of zero or more lines".
– R..
13 mins ago
1
1
almost 20 years using vim, and I still learn new things about it. and I'm still scared of emacs. :D
– Tim Kennedy
8 hours ago
almost 20 years using vim, and I still learn new things about it. and I'm still scared of emacs. :D
– Tim Kennedy
8 hours ago
1
1
In vim, you can also do
:set eol? to see whether eol is on or off, so you don't have to look through all the output of :set all.– Kevin
4 hours ago
In vim, you can also do
:set eol? to see whether eol is on or off, so you don't have to look through all the output of :set all.– Kevin
4 hours ago
A less confusing way of saying "files are either zero-length, or have a trailing newline" is "all lines end with a newline, and a text file is a sequence of zero or more lines".
– R..
13 mins ago
A less confusing way of saying "files are either zero-length, or have a trailing newline" is "all lines end with a newline, and a text file is a sequence of zero or more lines".
– R..
13 mins ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503961%2fwhy-dont-i-see-the-difference-between-two-different-files-in-insert-mode-in-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
":set list" would show the difference, and there's a mode which you can inspect. Both are in the help-files.
– Thomas Dickey
9 hours ago
Thank you @ThomasDickey I didn't know this option before.
– simhumileco
9 hours ago
1
@ThomasDickey if you want to add an answer it will be probably the accepted answer. Thank you.
– simhumileco
9 hours ago
1
@filbranden please don't post answers in comments. Answers in comments cannot be voted on by the community and don't mark the question as answered.
– terdon♦
8 hours ago
1
@ThomasDickey see above. Please post that as an answer.
– terdon♦
8 hours ago