Using notepad++ to change format of textline - text

I have a text file like this:
text something#mail.com
text2 something2#mail.com
i have multiple lines in this format and i want to replace it like this:
something#mail.com:text
something2#mail.com:text2
I've been trying everything,but it looks like i cant get it work.

Search > Replace...
Search Mode: Regular expression
Find What: ^ *([^ ]+) +([^ ]+)$
Replace With: \2:\1

Related

How do you replace a line with forward slashes in it in EX?

I'm running a script for vim EX mode I've tried every escape character and word identifier I can find.
it needs to find the string "/etc/walker" and replace it with "/etc/runner"
% s/\</etc/walker\>/\</etc/runner\>/g
wq
same issue with a script to append at the end of the file. It doesn't do anything. I'm trying to append "/etc/walker"
$
a
\</etc/walker\>
.
wq
what I've tried on regex editors seems to work there but not in EX
Thanks for your help
Try this:
:s#/etc/walker#/etc/runner#
Notice the use of # as a delimiter, that way you don't have to add back slashes.
You could also use:
:s#/etc/walker#/etc/runner#
For appending at the end of the line:
:s#$#/etc/walker#
In EX mode just remove the : at the beginning.

Function to search recursively for patterns in vim

I have a text file with simple text lines. I want to create a function for vim (and gvim) text editor which
can be sent a variable number of patterns and
it should find lines will all patterns (in any order)
and keep only these lines
while deleting the rest.
I searched the net and found some useful links but none that could do all above:
Following will find and delete all lines not containing the pattern:
:v/pattern/d
Multiple searching and highlighting can be done with scripts as MultipleSearch http://www.vim.org/scripts/script.php?script_id=479 . Boolean logic searching can be done with LogiPat script https://vim.sourceforge.io/scripts/script.php?script_id=1290 . A filtering package is also available but I could not make it work: http://www.vim.org/scripts/script.php?script_id=2759
To search and keep lines with multiple patterns with AND :
":v/.*pattern1\&.*pattern2/d"
but I have enter the code everytime.
How can I create a function that recursively runs :v/pattern/d to find only lines that contain all the patterns? I expect the function can be run as:
:Myfn pattern1 pattern2 pattern3
Edit: I have tried to write following code for this function, trying to use Linux grep command from within vim:
:function Myfn (Title, ...)
: let outstr=""
: for s in a:000
: outstr=!echo outstr | grep s
: endfor
: return outstr
: endfunction
But I get following error:
Not an editor command: : outstr=!echo outstr | grep s
with OR
:v/pattern1\|pattern2\|pattern3/d
with AND
:v/pattern1\&.*pattern2\&.*pattern/d
any order
:v/.*pattern1\&.*pattern2\&.*pattern3/d
(sorry looks like you already had this in of your solutions)
You can create a command Keepword:
com! -nargs=* Keepword v/\v<args>/d
and call it like:
Keepword word1|word2|word3
After using the command all lines (except those with the words provided) will be deleted.

LInux vi editor,how to replace special character?

I wrote some text in vi editor,such as
xxx
xxx.g/gasd/ga
gasdj\gqweg/fsda
fg-cgdohd
now I want to replace the "/g" to "abc"
how to escape it
I wrote
:%s/'/g'/abc/g
in command line,it's no working,how to do it?
You can use any character, not just a slash, in your search & replace:
%s:/g:abc:g

find and replace a String in vi editor on linux?

i am trying to replace String with new String in Linux vi editor
:s/totel_email_count/total_email_count/g
but getting following error.
E486: Pattern not found: totel_email_count
I'd guess the reason you're getting that error message is because you intend to replace the string on all lines, not just the current one. In order to search all lines, add a % to your command:
:%s/totel_email_count/total_email_count/g
To find and replace with vi editor type following:-
Type : (colon) followed by %s/foo/bar/ and hit [Enter] key.
:%s/foo/bar/
for example:-
:%s/old_string/new_string/

Vim copy and concatenate the lines

I got a file that looks like this:
G:\some_folder
file1.avi
file2.wav
E:\some_folder2
fileABC.avi
fileDEF.wav
I would like to transfer the file into:
G:\some_folder
G:\some_folder file1.avi
G:\some_folder file2.wav
E:\some_folder2
E:\some_folder2 fileABC.avi
E:\some_folder2 fileDEF.wav
So in other words this might work like this:
look for ^[A-Z]: copy whole line and add it at the beginning to next lines till you find ^[A-Z]:
is it possible to do that in VIM? If yes, how.
thank you
Radek
I would iterate over all lines with :global; Vim will position the cursor on the beginning of each line. Depending on which kind of line it is, I'd either yank the folder path, or paste it in front:
:%g/^/execute 'normal!' getline('.') =~ '^\S' ? 'y$' : 'P'

Resources