Due to a new coding style that I've been having to use I'm required to use tabs in the beginning of lines but spaces everywhere else to align things.
Is there a way to customize notepad++ to only replace tabs with spaces if it's not at the beginning of a new line?
Just as an example of what I mean I'll use this bit of 'code':
function someFunction():
while(true):
veryLongCodeStuff() // Some comment
shortCode() // Aligned comment
Which I would have to write like this (where \t = tab and a "." represents a space):
function someFunction():
\twhile(true):
\t\tveryLongCodeStuff()..// Some comment
\t\tshortCode()..........// Aligned comment
To convert existing files, I would suggest a two step approach:
replace all tabs with spaces (this can be done with Edit -> Blank operations -> TAB to Space )
replace spaces at the beginning of lines: do a regular expression find/replace like this:
Open Replace Dialog
Find What: ^([\t]?)( ){4} instead of 4 use the number of spaces you have configured as tab width
Replace With: \1\t
check regular expression
click Replace All: as each Replace All replaces only one indent level for all lines: repeat until the status bar of the find dialog tells you, that no more replacements were done (just keep Alt-A pressed for a second or two)
Related
I have csv file where each record is one line. Problem is that sometimes one cell have few lines. For example:
first;second;third;something something something something;four
first;second;third;something
something
something something;four
I opened this in Notepad++ and i see that end of record has LF white tag and new lines in cell has CR white tag.
How can I remove this CR white tags? I would like to have after convert:
first;second;third;something something something something;four
first;second;third;something something something something;four
Answer 1: Provided you can uniquely identify where you want to remove the newline
Find: “(Pattern 1 at end of line)\r\n” - Replace with “\1”
Or Find: “(Pattern 1 at end of line)\r\n(Pattern 2 at start of next line)\” - Replace with “\1\2”
Answer 2: Instead if you can identify where you want to keep the newlines
Find: “(Pattern 1 at end of line)” – Replace with “\1QAZ” where “QAZ” is not anywhere in the file. Continue until "QAZ" is everywhere you require
Remove all new lines by Find “\r\n” – Replace with nothing.
Restore required new lines by Find “QAZ” – replace with “\n” – windows Notepad++ does not need the \r
My problem is that I have a csv-file with alot of new line. How can I remove the newlines with select and replace? My other stuff should stay how it is.
Here the example:
101080;101080;101080;104;
101098;101098;101098;105;
101099;101099;101099;106;"RING 750GG 1BRI TW VS 0,0300ct 1 RUBIN WEITE58.0
BREITE 4.5mm
72-91872-0-0 045-71-0-58-3
704.- VP1000.-
";
1011;1011;1011;106;
101093;101093;101093;123;
I have all over the csv file these new lines. I need to make that in 1 line.
thank you for the help
If I understand the question correctly, you only wish to remove the newlines for any lines that do not end in a semicolon character. You can do that below with this Find and Replace in Notepad ++ using the Regular Expression Search Mode.
Find: ([^;]$)(\r\n)
Replace: \1
Explanation of the find is that it is looking for the end of line and newline character that isn't preceded by a semicolon character. The parenthesis tell the find to group the results, which allows us in the replace to just keep the first grouping of find results and to discard the newline characters for these lines that don't end in a semicolon, which will then end up making it all line up on the previous line.
Here is a simple solution:
Activate the ShowAll Icon (¶) in the toolbar of Notepad++
Mark a ; and NewLine-Sequence (CR LF) in your file
Use the shortcut Ctrl + F
Select the Replace tab in the appeared search window
Insert ; in the Replace with text box
Press Replace All
Now all items ending with a ; are in single rows.
To remove all new lines: Just replace "\r\n" (windows) or "\n" (unix) with nothing! Using Extended or Regex options.
To just remove some:
First add unique data where you want to keep the new line - I use "QAZ".
Then remove all new lines as above.
Then replace "QAZ" with "\n".
It happens many times when we need to remove line end and unnecessary space between the HTML element. So this could be proven as a time-saving technique.
open Search and replace (CTRL+H)
enable "Regular Expression" (circled in red)
enter \n\s+ in the search field, clear the replace field
press "Replace all"
This will remove all newlines (\n+) followed by all whitespace (\s+) in the next line.
In your Sublime Text user settings, you can specify the following to trim trailing white space.
"trim_trailing_white_space_on_save": true
You might want to have a look at the Trimmer that has a couple of options to trim whitespace.
you can also use \n+ to remove all the unwanted space , if you want to use a single line then replace with \n online
Notepad ++ (REGEX); Invert Selection,
The following 2 different codes, it works very nicely. :)
now I want to combine these two different code!
\bhttps?:[^)''"\s]+.(?:jpg|jpeg|gif|png)
https://codereview.stackexchange.com/questions/20126/regex-to-get-all-image-links
^((?!hello).)*$
notepad++ Inverse Regex replace (all but string)
So you want to find and remove all rows not containing an image URL specified by the regular expression \bhttps?:[^)''"\s]+.(?:jpg|jpeg|gif|png)?
You can combine the two regular expressions like this:
^((?!\bhttps?:[^)''"\s]+.(?:jpg|jpeg|gif|png)).)*$
If you replace the lines with an empty string, you can then use the menu option "Edit - Line Operations - Remove Empty Lines" to remove the empty lines.
Another option is to use bookmarks:
Select the "Mark" tab from the replace dialog and enter your first regular expression (the one that finds the image URL's). Check "Bookmark lines" and click "Mark all". From the menu, first select "Search - Bookmark - Inverse Bookmark", and then "Search - Bookmark - Remove Bookmarked lines" to remove the lines.
I am making a small online database that is accessible through the form of checkboxes for download. I was wondering if there was some way to list all of the filenames available for download in Sublime Text 2 and insert the same code around each filename?
Everything is functional, it would just save me a lot of repetitive copy and pasting if there is a faster way to do this.
Use SublimeText Find & Replace. Click the Regex button (it looks like a * to the left of the search box)
In the Find box, insert: (^.*$)
In the replace box: [yourcode]$1[yourcode]
Where [yourcode] is what you want to insert into the box.
So, if you want to make them all <li> then your replace box would be:
<li>$1</li>
Remember to use escape \ characters where they are needed, in case you need to insert restricted characters.
^ - beginning of a new line.
. - wildcard
* - any number of the previous character in the sequence (in this case a wildcard, so any text)
$ - the end of a line
() - denotes a block, it's how the $1 knows what text to put in it's place.
Sublime Text Search and Replace
Use search/replace on a text editor with regular expressions.
^ and $ represent the beginning and end of a line - thus allowing you to easily surround each line with the appropriate text.
Sometimes you can copy the newline character (as in copy the end of one line to the beginning of the next line), and replace that with whatever text you need.
You could always use the regular expression search / replace feature in Notepad++.