How do I delete all blank lines in a buffer? [duplicate]












5
















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









share|improve this 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 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


















5
















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









share|improve this 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 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
















5












5








5


1







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









share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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
















  • 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










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












1 Answer
1






active

oldest

votes


















7














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 (type C-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.







share|improve this answer
























  • This help me: M-x flush-lines ^$

    – Alexei
    Mar 23 at 16:49


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














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 (type C-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.







share|improve this answer
























  • This help me: M-x flush-lines ^$

    – Alexei
    Mar 23 at 16:49
















7














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 (type C-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.







share|improve this answer
























  • This help me: M-x flush-lines ^$

    – Alexei
    Mar 23 at 16:49














7












7








7







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 (type C-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.







share|improve this answer













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 (type C-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.








share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 22 at 18:57









manandearthmanandearth

1,2351419




1,2351419













  • 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





This help me: M-x flush-lines ^$

– Alexei
Mar 23 at 16:49



Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]