Remove empty lines from a fileDuplicating line content by substitutionRun global substitute for each match of a regex, with incrementHow do I remove lines where its content already occured in the previous line?In a regex, why aren't the multi + and 1, always parsed exactly the same way?How to move multiple IPs to different linesHow can I make two substitution command in one lineCan vim perform all substitutions simultaneously?How to remove lines which have lower numbers than before, and keep only the sequential?substituting /* in vimscript
In Cura, can I make my top and bottom layer be all perimiters?
Should I do a regression analysis even if the variables do not seem to be associated at all?
Novel in which space traders train a spearman army for a decaying medieval empire
Why did the people of Zion never find evidence of the previous cycles?
Proof that if covariance is zero then there is no linear relationship
Homogeneous vector bundles with zero chern classes
What game(s) does Michael play in Mind Field S2E4?
How much caffeine would there be if I reuse tea leaves in a second brewing?
Can a trainer send me a gift every day without opening my gift?
network cable - why T-568A and B standard
Starting a fire in a cold planet that has full of flammable gas
What is this second smaller runway next to London City Airport?
What is more proper notation in piano sheet music to denote that the left hand should be louder?
Create a program that prints the amount of characters it has, in words
Alias to open a graphical Program (nautilus) opens it in Terminal too
Number of possible polynomials
Is the ''yoi'' meaning ''ready'' when doing karate the same as the ''yoi'' which means nice/good?
Scrum Team and Product Owner working against each other
For a command to increase something, should instructions refer to the "+" key or the "=" key?
Router model and/or firmware version identifiable in network traffic?
Noise reduction using multiple recordings of the same signal
How to capture a possible figure of speech with "E se io fossi vago" in translation?
Regular sized fonts in oubraces package
Command which removes data left side of ";" (semicolon) on each row
Remove empty lines from a file
Duplicating line content by substitutionRun global substitute for each match of a regex, with incrementHow do I remove lines where its content already occured in the previous line?In a regex, why aren't the multi + and 1, always parsed exactly the same way?How to move multiple IPs to different linesHow can I make two substitution command in one lineCan vim perform all substitutions simultaneously?How to remove lines which have lower numbers than before, and keep only the sequential?substituting /* in vimscript
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I'm able to find empty lines with /^$
, but when I go to remove them using :%s/^$//
, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines
where XX
is the number of empty lines in the file.
Questions:
- What substitutions are being made, as indicated by the status line?
- How do I accomplish what I want to do (eliminate empty lines from a file)?
substitute
add a comment
|
I'm able to find empty lines with /^$
, but when I go to remove them using :%s/^$//
, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines
where XX
is the number of empty lines in the file.
Questions:
- What substitutions are being made, as indicated by the status line?
- How do I accomplish what I want to do (eliminate empty lines from a file)?
substitute
One answer to #2 is:g/^$/d
– chb
Jun 1 at 1:46
A solution would be to replace an actual character::%s/^n//
but that depends on file format.
– aragaer
Jun 1 at 10:26
add a comment
|
I'm able to find empty lines with /^$
, but when I go to remove them using :%s/^$//
, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines
where XX
is the number of empty lines in the file.
Questions:
- What substitutions are being made, as indicated by the status line?
- How do I accomplish what I want to do (eliminate empty lines from a file)?
substitute
I'm able to find empty lines with /^$
, but when I go to remove them using :%s/^$//
, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines
where XX
is the number of empty lines in the file.
Questions:
- What substitutions are being made, as indicated by the status line?
- How do I accomplish what I want to do (eliminate empty lines from a file)?
substitute
substitute
asked Jun 1 at 1:24
chbchb
1154 bronze badges
1154 bronze badges
One answer to #2 is:g/^$/d
– chb
Jun 1 at 1:46
A solution would be to replace an actual character::%s/^n//
but that depends on file format.
– aragaer
Jun 1 at 10:26
add a comment
|
One answer to #2 is:g/^$/d
– chb
Jun 1 at 1:46
A solution would be to replace an actual character::%s/^n//
but that depends on file format.
– aragaer
Jun 1 at 10:26
One answer to #2 is
:g/^$/d
– chb
Jun 1 at 1:46
One answer to #2 is
:g/^$/d
– chb
Jun 1 at 1:46
A solution would be to replace an actual character:
:%s/^n//
but that depends on file format.– aragaer
Jun 1 at 10:26
A solution would be to replace an actual character:
:%s/^n//
but that depends on file format.– aragaer
Jun 1 at 10:26
add a comment
|
1 Answer
1
active
oldest
votes
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "599"
;
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/4.0/"u003ecc by-sa 4.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%2fvi.stackexchange.com%2fquestions%2f20182%2fremove-empty-lines-from-a-file%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
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
add a comment
|
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
add a comment
|
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
edited Jun 2 at 12:46
answered Jun 1 at 3:23
D. Ben KnobleD. Ben Knoble
4,9011 gold badge7 silver badges27 bronze badges
4,9011 gold badge7 silver badges27 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Vi and Vim 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%2fvi.stackexchange.com%2fquestions%2f20182%2fremove-empty-lines-from-a-file%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
One answer to #2 is
:g/^$/d
– chb
Jun 1 at 1:46
A solution would be to replace an actual character:
:%s/^n//
but that depends on file format.– aragaer
Jun 1 at 10:26