I need to use find new lines (\n) in a .txt file and replace them with a backspace (\b). Using this in the Find and Replace feature of Notepad++ successfully finds the new lines, (\n), but replaces them with the characters "\b" instead of applying a backspace. How can this be done correctly?
\r\n should work.
replace them with empty field and you will get your backspace(\b) equivalent
A simple way would be Ctrl + J or Edit->Line Operations->Join Lines
I was also trying to replace \n with backspace, but the above solutions seems neat. Maybe it helps someone.
(I tried the \r\n solution and it seems both works the same way :) )
In notepad++,
Go to Edit menu, line operations and then click on "Remove Empty Lines"
You get what you are trying with regular expression.
Removing empty lines
Use regular expressions, in Find what:, enter \r\n and in Replace with: leave that blank.
Related
I need to prepare test data having around 10K lines with many blank lines, same has to be removed. Earlier I was using editplus (Text editor) and could able to solve very easily by using Find (Find text: "\n\n" Regular expression) and Replace (empty) option.
Here in this project I am using Sakura editor and tried the below option to remove blank lines but its not working.
Need to remove line 6 and 7.
Find text
\n\n
\r\n\r\n
[\r\n]+[\r\n]
More information about using of regular expression in sakura editor
Click here
PS: I have some restriction in my current project to download and install any other software/tools.
Any help is appreciated.
Finally found solution. Like to share with others.
In sakura editor, we can remove the empty lines by using find and replace option.
Find ^\r\n 【Option:Regular expression】 and replace
Explanation
^ Beginning of the line
\r carriage-return character
\n newline (line feed) character
I am trying to run this command in vi
:s/href="\//href="http:\/\/website.com\/folder\/subfolder\//g
but got this error E486: Pattern not found: href="\/
What am i doing wrong?
That error means pretty much what it says. vi didn't find any pattern href="/ (ignoring escapes) in your file.
Sometimes it's easier to use something besides / for the search delimiter if your search has a lot of slashes, so you don't need to escape them all. Try replacing the / delimiter with # instead, like this:
s#href="/#href="http://website.com/folder/subfolder/#g
Then maybe you can more easily see what's wrong with your pattern:
becouse there are many '/' chars, try use another delimiter, ex ',':
:s,some/pattern/with/slashes,new/string,g
On another note. That substition worked for me. Just copied and pasted. Are you on the same line that you are trying to perform the substitution on? the 'g' is meant globally on the line you are on. If you need to perform the search and replace on the file the use :%s/
Let's say this is my text:
this is my text this
is my text this is my text
my text is this
I would like to highlight all text except pattern and delete the highlighted text.
p.e. text: this must be the result.
text
texttext
text
I've found the code how to select all text except pattern:
\%(\%(.{-}\)\#!text\zs\)*
however I don't know how to delete all highlighted text.
This doesn't work:
:%s/\%(\%(.{-}\)\#!bell\zs\)*//
Can anyone help me?
Try this:
:%s/\(^\|\(text\)\#<=\).\{-}\($\|text\)\#=//g
Explanation:
\(^\|\(text\)\#<=\) # means start of line, or some point preceded by “text”
.\{-} # as few characters as possible
\($\|text\)\#= # without globbing characters, checking that we reached either end of line or occurrence of “text”.
Another way to do it:
Create a function that count matches of a pattern in a string (see :help match() to help you design that)
Use: :%s/.*/\=repeat('text', matchcount('text', submatch(0)))
Forgive me, because I'm not a vim expert, but wouldn't prepending the search with v find the inverse so that you could do something like this?
:v/pattern/d
I've implemented Benoit's clever regular expression as a custom :DeleteExcept command in my PatternsOnText plugin. It offers other related commands like :SubstituteExcept or :SubstituteInSearch, too.
OP's example would be
:%DeleteExcept /text/
Comparing that with #Benoit's explicit command (:%s/\(^\|\(text\)\#<=\).\{-}\($\|text\)\#=//g), it's a lot simpler.
I want to substitute all cygdrive/e with cygdrive/d using vim. But I can't get the matching pattern correctly. Here is my command:
s/cygdrive\/e/cygdrive\/d/g
it doesn't work. Can anybody show me what is wrong?
Thanks,
vim allows you to specify the delimiter.. (First character after s is the delimiter)
s/cygdrive\/e/cygdrive\/d/g
using line range argument .. and # as delimiter
ESC:
:1,$ s#/cygdrive/e#/cygdrive/d#g
Your search pattern and replacement string look fine.
Make sure you are in ex mode when you try it.
So press ESC, then : and then
%s/cygdrive\/e/cygdrive\/d/g
But if you want all he replacements in just the current line you can do:
s/cygdrive\/e/cygdrive\/d/g
You have to escape the special character
like this
s/cygdrive\/e/cygdrive\/d/g
I know the thread.
I run
:%s/ /s/\n/g
I get
E488: Trailing characters
2nd example
I run
:%s/ /\n/g
I get
text^#text
I run the same codes also with the following settings separetaly
set fileformat=unix
and
set fileformat=dos
How can you replace with a new line in Vim?
:%s/ /Ctrl vReturn/g
Where Ctrl v is Control-key plus key v and Return is the return key (the one on the main keyboard, not the enter key on the numpad). The other characters are typed as usual.
If this is entered correctly, the sequence Ctrl vReturn will display as the characters ^M, typically in a different color, to indicate that they are special. Note that actually typing ^M will not work.
Also note that in Vim for windows, it's Control-q instead of Control-v (as that is paste).
Ctrl-v also allows entering other "special" keys via the keyboard. It is also useful for e.g. Tab or Backspace.
Try
%s/ /\r/g
Enter the following:
:s/ /
and now type Ctrl-V or Ctrl-Q (depends on your configuration) and hit the Enter key. You should now have:
:s/ /^M
Finish it off:
:s/ /^M/g
and you are good to go.
Specifically to answer your problem with trailing characters, this is the regex you specified:
:%s/ /s/\n/g
You have too many /. What happens is that you replace ' ' with s, and then you tag on this after the substitution: \n/g
I think you meant this:
:%s/ \s/\n/g
Note that your /s was changed to \s. Now the substitution will replace one space followed by one whitespace of any kind (space or tab) with \n. I doubt if this solve the problem or replacing space with a newline, but it should explain the error message.
Try either
For Unix:
:1,$s/\ /\n/g
For Windows:
:1,$s/\ /\r/g
This contains an escape character for the space.