How do I delete all blank lines in a buffer? [duplicate]
This question already has an answer here:
how do I quickly remove lines from emacs buffer
1 answer
Emacs 26.1
In buffer
1
2
3
4
I use command "delete-blank-lines
". But it NOT delete ALL BLANK LINES. It's delete ONLY ONE BLANK LINE.
Why?
I need to delete ALL BLANK LINES.
The result must be like this:
1
2
3
4
text-editing
marked as duplicate by Drew, DoMiNeLa10♦ Mar 23 at 1:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
how do I quickly remove lines from emacs buffer
1 answer
Emacs 26.1
In buffer
1
2
3
4
I use command "delete-blank-lines
". But it NOT delete ALL BLANK LINES. It's delete ONLY ONE BLANK LINE.
Why?
I need to delete ALL BLANK LINES.
The result must be like this:
1
2
3
4
text-editing
marked as duplicate by Drew, DoMiNeLa10♦ Mar 23 at 1:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Are you saying you useddelete-blank-lines
once? If you look at the help for the function, it will tell you it deletes the surrounding blank lines, that is the blank lines around point, not all blank lines in the buffer.
– Willy Lee
Mar 22 at 18:10
What @WillyLee said.
– Drew
Mar 22 at 20:43
See also: emacs.stackexchange.com/q/41636/105. The question has been asked more than once, expressed in different ways.
– Drew
Mar 22 at 20:45
add a comment |
This question already has an answer here:
how do I quickly remove lines from emacs buffer
1 answer
Emacs 26.1
In buffer
1
2
3
4
I use command "delete-blank-lines
". But it NOT delete ALL BLANK LINES. It's delete ONLY ONE BLANK LINE.
Why?
I need to delete ALL BLANK LINES.
The result must be like this:
1
2
3
4
text-editing
This question already has an answer here:
how do I quickly remove lines from emacs buffer
1 answer
Emacs 26.1
In buffer
1
2
3
4
I use command "delete-blank-lines
". But it NOT delete ALL BLANK LINES. It's delete ONLY ONE BLANK LINE.
Why?
I need to delete ALL BLANK LINES.
The result must be like this:
1
2
3
4
This question already has an answer here:
how do I quickly remove lines from emacs buffer
1 answer
text-editing
text-editing
edited Mar 22 at 19:31
Tyler
12.3k12355
12.3k12355
asked Mar 22 at 17:01
AlexeiAlexei
774212
774212
marked as duplicate by Drew, DoMiNeLa10♦ Mar 23 at 1:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Drew, DoMiNeLa10♦ Mar 23 at 1:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Are you saying you useddelete-blank-lines
once? If you look at the help for the function, it will tell you it deletes the surrounding blank lines, that is the blank lines around point, not all blank lines in the buffer.
– Willy Lee
Mar 22 at 18:10
What @WillyLee said.
– Drew
Mar 22 at 20:43
See also: emacs.stackexchange.com/q/41636/105. The question has been asked more than once, expressed in different ways.
– Drew
Mar 22 at 20:45
add a comment |
1
Are you saying you useddelete-blank-lines
once? If you look at the help for the function, it will tell you it deletes the surrounding blank lines, that is the blank lines around point, not all blank lines in the buffer.
– Willy Lee
Mar 22 at 18:10
What @WillyLee said.
– Drew
Mar 22 at 20:43
See also: emacs.stackexchange.com/q/41636/105. The question has been asked more than once, expressed in different ways.
– Drew
Mar 22 at 20:45
1
1
Are you saying you used
delete-blank-lines
once? If you look at the help for the function, it will tell you it deletes the surrounding blank lines, that is the blank lines around point, not all blank lines in the buffer.– Willy Lee
Mar 22 at 18:10
Are you saying you used
delete-blank-lines
once? If you look at the help for the function, it will tell you it deletes the surrounding blank lines, that is the blank lines around point, not all blank lines in the buffer.– Willy Lee
Mar 22 at 18:10
What @WillyLee said.
– Drew
Mar 22 at 20:43
What @WillyLee said.
– Drew
Mar 22 at 20:43
See also: emacs.stackexchange.com/q/41636/105. The question has been asked more than once, expressed in different ways.
– Drew
Mar 22 at 20:45
See also: emacs.stackexchange.com/q/41636/105. The question has been asked more than once, expressed in different ways.
– Drew
Mar 22 at 20:45
add a comment |
1 Answer
1
active
oldest
votes
From MasteringEmacs.com By Mickey Petersen:
This is a frequent question so I figured I’d mention the solution here:
You want to remove all empty (blank) lines from a buffer. How do you do it? Well, it’s super easy.
Mark what you want to change (or use
C-x h
to mark the whole buffer) and run this:
M-x flush-lines RET ^$ RET
And you’re done. So what does that mean? Well,
M-x flush-lines
will flush (remove) lines that match a regular expression, and ^$ contain the meta-characters ^ for beginning of string and $ for end of string. Ergo, if the two meta-characters are next to eachother, it must be a blank line.
We can also generalize it further and remove lines that may have whitespace (only!) characters:
M-x flush-lines RET ^s-*$ RET
In this case
s-
is the syntax class (typeC-h s
to see your buffer’s syntax table) for whitespace characters. The*
meta-character, in case you are not a regexp person, means zero or more of the preceding character.
This help me: M-x flush-lines ^$
– Alexei
Mar 23 at 16:49
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
From MasteringEmacs.com By Mickey Petersen:
This is a frequent question so I figured I’d mention the solution here:
You want to remove all empty (blank) lines from a buffer. How do you do it? Well, it’s super easy.
Mark what you want to change (or use
C-x h
to mark the whole buffer) and run this:
M-x flush-lines RET ^$ RET
And you’re done. So what does that mean? Well,
M-x flush-lines
will flush (remove) lines that match a regular expression, and ^$ contain the meta-characters ^ for beginning of string and $ for end of string. Ergo, if the two meta-characters are next to eachother, it must be a blank line.
We can also generalize it further and remove lines that may have whitespace (only!) characters:
M-x flush-lines RET ^s-*$ RET
In this case
s-
is the syntax class (typeC-h s
to see your buffer’s syntax table) for whitespace characters. The*
meta-character, in case you are not a regexp person, means zero or more of the preceding character.
This help me: M-x flush-lines ^$
– Alexei
Mar 23 at 16:49
add a comment |
From MasteringEmacs.com By Mickey Petersen:
This is a frequent question so I figured I’d mention the solution here:
You want to remove all empty (blank) lines from a buffer. How do you do it? Well, it’s super easy.
Mark what you want to change (or use
C-x h
to mark the whole buffer) and run this:
M-x flush-lines RET ^$ RET
And you’re done. So what does that mean? Well,
M-x flush-lines
will flush (remove) lines that match a regular expression, and ^$ contain the meta-characters ^ for beginning of string and $ for end of string. Ergo, if the two meta-characters are next to eachother, it must be a blank line.
We can also generalize it further and remove lines that may have whitespace (only!) characters:
M-x flush-lines RET ^s-*$ RET
In this case
s-
is the syntax class (typeC-h s
to see your buffer’s syntax table) for whitespace characters. The*
meta-character, in case you are not a regexp person, means zero or more of the preceding character.
This help me: M-x flush-lines ^$
– Alexei
Mar 23 at 16:49
add a comment |
From MasteringEmacs.com By Mickey Petersen:
This is a frequent question so I figured I’d mention the solution here:
You want to remove all empty (blank) lines from a buffer. How do you do it? Well, it’s super easy.
Mark what you want to change (or use
C-x h
to mark the whole buffer) and run this:
M-x flush-lines RET ^$ RET
And you’re done. So what does that mean? Well,
M-x flush-lines
will flush (remove) lines that match a regular expression, and ^$ contain the meta-characters ^ for beginning of string and $ for end of string. Ergo, if the two meta-characters are next to eachother, it must be a blank line.
We can also generalize it further and remove lines that may have whitespace (only!) characters:
M-x flush-lines RET ^s-*$ RET
In this case
s-
is the syntax class (typeC-h s
to see your buffer’s syntax table) for whitespace characters. The*
meta-character, in case you are not a regexp person, means zero or more of the preceding character.
From MasteringEmacs.com By Mickey Petersen:
This is a frequent question so I figured I’d mention the solution here:
You want to remove all empty (blank) lines from a buffer. How do you do it? Well, it’s super easy.
Mark what you want to change (or use
C-x h
to mark the whole buffer) and run this:
M-x flush-lines RET ^$ RET
And you’re done. So what does that mean? Well,
M-x flush-lines
will flush (remove) lines that match a regular expression, and ^$ contain the meta-characters ^ for beginning of string and $ for end of string. Ergo, if the two meta-characters are next to eachother, it must be a blank line.
We can also generalize it further and remove lines that may have whitespace (only!) characters:
M-x flush-lines RET ^s-*$ RET
In this case
s-
is the syntax class (typeC-h s
to see your buffer’s syntax table) for whitespace characters. The*
meta-character, in case you are not a regexp person, means zero or more of the preceding character.
answered Mar 22 at 18:57
manandearthmanandearth
1,2351419
1,2351419
This help me: M-x flush-lines ^$
– Alexei
Mar 23 at 16:49
add a comment |
This help me: M-x flush-lines ^$
– Alexei
Mar 23 at 16:49
This help me: M-x flush-lines ^$
– Alexei
Mar 23 at 16:49
This help me: M-x flush-lines ^$
– Alexei
Mar 23 at 16:49
add a comment |
1
Are you saying you used
delete-blank-lines
once? If you look at the help for the function, it will tell you it deletes the surrounding blank lines, that is the blank lines around point, not all blank lines in the buffer.– Willy Lee
Mar 22 at 18:10
What @WillyLee said.
– Drew
Mar 22 at 20:43
See also: emacs.stackexchange.com/q/41636/105. The question has been asked more than once, expressed in different ways.
– Drew
Mar 22 at 20:45