Remove empty lines from code
Hello. I can't find action in PHPStorm to remove empty lines from code.
I get project that have many empty lines that are unused.
If I run reformat code action this empty lines are not removed.
How to remove them from file ?
Please sign in to leave a comment.
Hi, anther developer was working on the project and he used FileZilla to download and upload files. when i connected remove host i found some files were having empty line like above.
i solved this with a trick
The other options didn't work for me. This removed empty lines using replace :
1. start replace ( command R )
2. select Regex replace
3. search for: ^\s*^
4. replace with: ( leave it empty )
5. click replace all.
explanation
^ ( carrot / shift 6 in regex == start of line )
\s* ( back slash s asterisk == any number of white space )
^\s*^ == start of line followed by any number of white space followed by start of line
^$ ( carrot followed by dollar sign ) == line with nothing
Hi,
maybe you can search for \n\n and Replace it by \n
cu
Hi
what mean STRG-R with regex in sentences "replace \n\n by \n (STRG-R with regex)" ?
a keyboard shortcut : Remove a single annotation element http://ami.dfki.de/amigram/shortcuts.htm
STRG-R mean Ctrl-R and make appear the gui for search and replace ?
which is the syntax of the regex expression to use ?
regard's
Attachment(s):
phpstorm_regex.png
Another, more general regex that work in most other editors (RegEx engine dependent) is
It depends what kind of empty lines they are. Single empty line inside the code (function body etc) will most likely will never be removed as it is very often used to visually separate the code a bit, but things like double empty line, or multiple empty lines between methods etc can be removed if configured to do so -- make sure that you configured it at "Settings | Code Style | PHP | Blank Lines".
Also make sure that "Settings | Code Style | PHP | Wrapping and braces | Keep when reformatting | Line breaks" is unchecked -- it may affect other settings as well.
Other than that -- Replace \n\n by \n as suggested above (this will remove all empty lines).
After download code from server I get something like this below.
After everyline of code is one empty line. Code is mixed with css, html and PHP.
I am terribly annoyed with it and I can not imagine manually delete these empty rows:
<!-- Tabelle, die die linken,rechten Boxen und den Inhalt tr�gt --> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td class="boxen_links" style="vertical-align:top"><style type="text/css"> <!-- /* Kategorie-Box */ a {color: #464646; text-decoration: none;} h2.cat-header{ width: 191px; height: 50px; background-image: url(http://intymnosc.pl/images/d_kategorie.png); text-indent:-9999px; margin:20px 0 0 0;} #mainmenu ul.lev1 {width:191px; border-bottom:1px #d3d3ba solid;} #mainmenu ul.lev1 li:first-child a, #mainmenu ul.lev1 li ul.lev2 li:first-child a, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li:first-child a, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li:first-child a {border-top:none;} #mainmenu ul.lev1, ul.lev2, ul.lev3, ul.lev4 {margin:0; padding:0; font-family: Trebuchet MS, sans-serif; font-size:12px; list-style:none; text-transform:uppercase;} #mainmenu ul.lev1 li a:hover, #mainmenu ul.lev1 li a.parent:hover, #mainmenu ul.lev1 li ul.lev2 li a:hover, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a:hover, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a:hover {text-decoration:none; background: #386961; background: -moz-linear-gradient(top, #4f8e94 0%, #386961 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4f8e94), color-stop(100%,#386961)); background: -webkit-linear-gradient(top, #4f8e94 0%,#386961 100%); background: -o-linear-gradient(top, #4f8e94 0%,#386961 100%); background: -ms-linear-gradient(top, #4f8e94 0%,#386961 100%); background: linear-gradient(top, #4f8e94 0%,#386961 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4f8e94', endColorstr='#386961',GradientType=0 ); color:#fff; text-shadow:-1px -1px #31635c; border:none; } /* lvl1 */ #mainmenu ul.lev1 li a {display:block; width:184px; border:1px #d3d3ba solid; border-bottom:none; padding:8px 0 8px 5px; background:#fff; line-height:19px;} #mainmenu ul.lev1 li a.parent {color:#d32474;} #mainmenu ul.lev1 li a:hover {padding:9px 1px 8px 6px;} #mainmenu ul.lev1 li:first-child a:hover, #mainmenu ul.lev1 li a.active {padding:8px 1px 8px 6px;} /* lvl2 */ #mainmenu ul.lev1 li ul.lev2 {border-top:1px #d3d3ba solid;} #mainmenu ul.lev1 li ul.lev2 li a {width:179px; margin-left:5px; background:#f3f3ef; border:1px #d3d3ba solid; border-bottom:none; font-size:10px; padding:5px 0 5px 5px; text-shadow:1px 1px #fff;} #mainmenu ul.lev1 li ul.lev2 li a:hover, #mainmenu ul.lev1 li ul.lev2 li a.active, #mainmenu ul.lev1 li ul.lev2 li:first-child a.active:hover {padding:6px 1px 5px 6px;} #mainmenu ul.lev1 li ul.lev2 li:first-child a:hover {padding:5px 1px 5px 6px; border-top:none;} /* lvl3 */ #mainmenu ul.lev1 li ul.lev2 li ul.lev3 {width:186px; margin-left:5px; border-top:1px #d3d3ba solid;} #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a {width:174px; margin-left:5px; background:#e8e8e2; border:1px #d3d3ba solid; border-bottom:none; font-size:10px; padding:5px 0 5px 5px; text-shadow:1px 1px #f3f3ef;} #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a:hover, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a.active, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li:first-child a.active:hover {padding:6px 1px 5px 6px;} #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li:first-child a:hover {padding:5px 1px 5px 6px;} /* lvl4 */ #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 {width:181px; margin-left:5px; border-top:1px #d3d3ba solid;} #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a {width:169px; margin-left:5px; background:#ccccc1; border:1px #a3a399 solid; border-bottom:none; padding:4px 0 4px 5px; text-shadow:1px 1px #e8e8e2;} #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a:hover, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a.active, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li:first-child a.active:hover {padding:5px 1px 4px 6px;} #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li:first-child a:hover {padding:4px 1px 4px 6px;} #mainmenu ul.lev1 li a.active, #mainmenu ul.lev1 li a.active:hover, #mainmenu ul.lev1 li ul.lev2 li a.active, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a.active , #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a.active {color:#fff; text-shadow:-1px -1px #c11362; background: #c81667; background: -moz-linear-gradient(top, #ed4369 0%, #c81667 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ed4369), color-stop(100%,#c81667)); background: -webkit-linear-gradient(top, #ed4369 0%,#c81667 100%); background: -o-linear-gradient(top, #ed4369 0%,#c81667 100%); background: -ms-linear-gradient(top, #ed4369 0%,#c81667 100%); background: linear-gradient(top, #ed4369 0%,#c81667 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ed4369', endColorstr='#c81667',GradientType=0 ); border:none;} span.showcatnum {color:#adac99; font-size:10px;} ul.lev4 li a span.showcatnum {color:#89897b;} a:hover span.showcatnum, ul.lev4 li a:hover span.showcatnum {color:#afd2d5;} li a.active span.showcatnum, ul.lev4 li a.active span.showcatnum {color:#f1a3c6;} --> </style>
I see. That's a bit different storry -- see this ticket: http://youtrack.jetbrains.com/issue/WI-9103
It seems that these empy lines are added by PhpStorm during file transfer (most likely when uploading to remote host).
Hi,
after doing
i got this:
<!-- Tabelle, die die linken,rechten Boxen und den Inhalt tr�gt -->
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td >
<style type="text/css">
<!--
/* Kategorie-Box */
a {
color: #464646;
text-decoration: none;
}
h2.cat-header {
width: 191px;
height: 50px;
background-image: url(http://intymnosc.pl/images/d_kategorie.png);
text-indent: -9999px;
margin: 20px 0 0 0;
}
#mainmenu ul.lev1 {
width: 191px;
border-bottom: 1px #d3d3ba solid;
}
#mainmenu ul.lev1 li:first-child a,
#mainmenu ul.lev1 li ul.lev2 li:first-child a,
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li:first-child a,
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li:first-child a {
border-top: none;
}
#mainmenu ul.lev1, ul.lev2, ul.lev3, ul.lev4 {
margin: 0;
padding: 0;
font-family: Trebuchet MS, sans-serif;
font-size: 12px;
list-style: none;
text-transform: uppercase;
}
#mainmenu ul.lev1 li a:hover, #mainmenu ul.lev1 li a.parent:hover,
#mainmenu ul.lev1 li ul.lev2 li a:hover,
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a:hover,
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a:hover {
text-decoration: none;
background: #386961;
background: -moz-linear-gradient(top, #4f8e94 0%, #386961 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #4f8e94), color-stop(100%, #386961));
background: -webkit-linear-gradient(top, #4f8e94 0%, #386961 100%);
background: -o-linear-gradient(top, #4f8e94 0%, #386961 100%);
background: -ms-linear-gradient(top, #4f8e94 0%, #386961 100%);
background: linear-gradient(top, #4f8e94 0%, #386961 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#4f8e94', endColorstr = '#386961', GradientType = 0);
color: #fff;
text-shadow: -1px -1px #31635c;
border: none;
}
/* lvl1 */
#mainmenu ul.lev1 li a {
display: block;
width: 184px;
border: 1px #d3d3ba solid;
border-bottom: none;
padding: 8px 0 8px 5px;
background: #fff;
line-height: 19px;
}
#mainmenu ul.lev1 li a.parent {
color: #d32474;
}
#mainmenu ul.lev1 li a:hover {
padding: 9px 1px 8px 6px;
}
#mainmenu ul.lev1 li:first-child a:hover, #mainmenu ul.lev1 li a.active {
padding: 8px 1px 8px 6px;
}
/* lvl2 */
#mainmenu ul.lev1 li ul.lev2 {
border-top: 1px #d3d3ba solid;
}
#mainmenu ul.lev1 li ul.lev2 li a {
width: 179px;
margin-left: 5px;
background: #f3f3ef;
border: 1px #d3d3ba solid;
border-bottom: none;
font-size: 10px;
padding: 5px 0 5px 5px;
text-shadow: 1px 1px #fff;
}
#mainmenu ul.lev1 li ul.lev2 li a:hover, #mainmenu ul.lev1 li ul.lev2 li a.active, #mainmenu ul.lev1 li ul.lev2 li:first-child a.active:hover {
padding: 6px 1px 5px 6px;
}
#mainmenu ul.lev1 li ul.lev2 li:first-child a:hover {
padding: 5px 1px 5px 6px;
border-top: none;
}
/* lvl3 */
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 {
width: 186px;
margin-left: 5px;
border-top: 1px #d3d3ba solid;
}
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a {
width: 174px;
margin-left: 5px;
background: #e8e8e2;
border: 1px #d3d3ba solid;
border-bottom: none;
font-size: 10px;
padding: 5px 0 5px 5px;
text-shadow: 1px 1px #f3f3ef;
}
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a:hover, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a.active, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li:first-child a.active:hover {
padding: 6px 1px 5px 6px;
}
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li:first-child a:hover {
padding: 5px 1px 5px 6px;
}
/* lvl4 */
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 {
width: 181px;
margin-left: 5px;
border-top: 1px #d3d3ba solid;
}
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a {
width: 169px;
margin-left: 5px;
background: #ccccc1;
border: 1px #a3a399 solid;
border-bottom: none;
padding: 4px 0 4px 5px;
text-shadow: 1px 1px #e8e8e2;
}
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a:hover, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a.active, #mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li:first-child a.active:hover {
padding: 5px 1px 4px 6px;
}
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li:first-child a:hover {
padding: 4px 1px 4px 6px;
}
#mainmenu ul.lev1 li a.active, #mainmenu ul.lev1 li a.active:hover,
#mainmenu ul.lev1 li ul.lev2 li a.active,
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li a.active,
#mainmenu ul.lev1 li ul.lev2 li ul.lev3 li ul.lev4 li a.active {
color: #fff;
text-shadow: -1px -1px #c11362;
background: #c81667;
background: -moz-linear-gradient(top, #ed4369 0%, #c81667 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ed4369), color-stop(100%, #c81667));
background: -webkit-linear-gradient(top, #ed4369 0%, #c81667 100%);
background: -o-linear-gradient(top, #ed4369 0%, #c81667 100%);
background: -ms-linear-gradient(top, #ed4369 0%, #c81667 100%);
background: linear-gradient(top, #ed4369 0%, #c81667 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#ed4369', endColorstr = '#c81667', GradientType = 0);
border: none;
}
span.showcatnum {
color: #adac99;
font-size: 10px;
}
ul.lev4 li a span.showcatnum {
color: #89897b;
}
a:hover span.showcatnum, ul.lev4 li a:hover span.showcatnum {
color: #afd2d5;
}
li a.active span.showcatnum, ul.lev4 li a.active span.showcatnum {
color: #f1a3c6;
}
-->
</style>