Replace blank lines with specific text in Notepad ++ - text

For example I have a text
Line1
Line3
Line5
Line6
And I need to replace the blank lines with a specific text, e.g. CoolText
so the result would be
Line1
CoolText
Line3
CoolText
Line5
CoolText
Line6
How to accomplish this?

You can use the extended replacement feature in NotePad++. Search for doubled carriage return/line feed pairs (\r\n\r\n), and replace them with a carriage return/line feed pair, the replacement text, and another CR/LF pair (\r\nCoolText\r\n).
Here's the text file with the dialog set up for the replacement, before clicking "Replace All":
Here are the results after clicking "Replace All":

Related

Switch cursor position in visual block insert mode

Is there a keystroke, similar to v_o, to switch cursor position in visual block insert mode?
Example: | cursor position
|line1
line2
line3
Hit Ctrl+v and go down to line 3
line1
line2
|line3
Hit I
|line1
line2
line3
Now the cursor is back at line 1.
I want to stay the cursor in line 3.
So, based on your comment:
The column insertion is done in a single step. Do your selection (c-v), go down, go in insert mode (I), add your x and leave the insert mode with either escape or ctrl-[. As you quit the insert mode, the inserted text will be added on all the lines.
In any case, your cursor will go back at the beginning. If you want to bring it at the end of what has been selected, you can do it by pressing: '> which marks the end of the last visual selection.
EDIT: After further discussion about the need, the point is to execute a column insert on a long range.
I would do 3 splits (with :sp), I would resize (by dragging the statusbar of a window) the 2 top ones to show each one line (the beginning of the selection for one, and the end for the other), they will be used as reference.
Then, use the third one to do the actual manipulation, and as you will type/indent (at the beginning of the selection), you will see it change in one of your small splits and you can compare with the other one to indent to where you want.
Here is a screenshot to illustrate it (I wanted to indent from line 1 to 43 and I use my first split as a reference to indent everything on where "blandit" is, line 44), I use the first split to see the beginning, the second to see the end and the 3rd to actually do the whole manipulation:

Text Editing in VI

How do I delete text probably multiple lines in vi(m)?
Tried the backspace button to delete. Works not!
Deleted lines of text.
By default, in Vi/Vim, backspace does not work as we are used to] (cf :help bs, in Vim).
If you are in Vim, you can set it to behave the way you want with:
:set bs=indent,eol,start
If you are in Vi only, I refer you to #user31264's answer.
Some most common delete commands:
Delete 123 lines from the current one: d123d or 123dd
Delete one line: dd
Delete 1 character: x
Delete 123 characters: 123x
Delete till the end of the current word (word is a sequence of alphanumeric characters, or one non-alphanumeric non-space character): dw or de
As above, word is a sequence of any characters except whitespace: dW or dE
As above, delete 123 words: 123dw, 123de, 123dW, or 123dE

Split long strings without spaces to multiple lines at a given length in a text file

I have a text file containing some very long lines with no spaces.
These lines contain no whitespace or other common delimiters.
I would like to split these long lines into seperate lines so that no line in the text file is longer than 80 characters. Is this possible inside vim or perhaps using some other tool?
Quick vim solution:
assume we have a long line of text:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
that we want to split into pieces of 10:
gg (for first line),
q[letter] (for recording a macro),
10l (for going right n times),
a return ESC (for entering a linebreak after current character and leaving insert mode),
q (to stop recording).
We should now be on line 2 with our cursor, looking like this:
aaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
A quick 100#[letter] formats the entire line:
aaaaaaaaaaa
aaaaaaaaaaa
aaaaaaaaaaa
aaaaaaaaaaa
aaaaaaaaaaa
aaaaaaaaaaa
aaaaaaaa

How to reformat "gq"ed text in one line per paragraph format in Vim

I have some text files previously formatted in vim using "gggqG". Now I need to convert them to one line per paragraph format. I saw a way(using :g command) to do that before, but I have forgot it. Anyone knows?
There are two approaches I know of:
Set textwidth to something big and reformat:
:set tw=1000000
gggqG
Use substitute (this is more appropriate if you want to do it in a mapping):
:%s/.\zs\n\ze./ /
Explanation of the latter:
:%s " Search and replace across the whole file
/ " Delimiter
.\zs\n\ze. " Look for a character either side of a new-line (so ignore blank lines).
" The \zs and \ze make the replacement only replace the new-line character.
/ / " Delimiters and replace the new-line with a space.
If your text paragraphs are separated by a blank line, this seems to work:
:g!/^\s*$/normal vipJ
:g global (multi-repeat)
!/^\s*$/ match all lines except blank lines and those containing only whitespace.
normal enters 'normal' mode
vip visually select inner paragraph
J join lines
Maybe you should set textwidth to very large value (like 99999999) (0 does not work for some reason) and use gggqG?
// I cannot tell you a way to reformat your paragraph with :g without knowing exactly what the paragraph is. Maybe somebody else can.

how to add lines to a vim register without overwriting it

I'd like to yank a line in a register: "{register}y but without overwriting what was previously in the register. I often need to copy non-contiguous lines in a register, and I'd like to use sometimes the registers like a stack.
Example:
line1
line2
line3
I want to copy line1, by putting the cursor on it and entering "ay, then going on line3 and do "ay. Then, when I will do "ap, BOTH line1 AND line3 will be pasted.
Is this possible without plugins ? with plugins?
If you want to append to a named register use it's corresponding upper case character.
i.e. In your example:
"ayy
"Ayy
"ap
Just to expand on MarkB's response, did you know you can also use markers to select a block of text for your yank?
Go to the first line of the block you want to yank and enter the mark command after selecting a letter as the marker, e.g.
ma (entered in command mode, i.e. no colon)
then go to the bottom of the block you want to yank and enter the command:
:'a,.ya A
this command means take the block of text from the line containing my marker called a up to the current line and yank it into buffer a. Same rules as MarkB mentioned apply, use lowercase buffer name to overwrite the buffer. Use uppercase buffer name to append to the buffer. So in this case this will append to the contents of buffer a.
N.B. The 'a' used for your marker has nothing to do with the 'a' used to select your register. (AFAIK but YMMV)
BTW 'a (apostrophe a) refers to the line containing the marker a. `a (backquote a) refers to the character under the cursor when you entered ma.
d`a (also entered in command mode)
is useful because it will delete the text between the character marked with marker a up to the character just before the character where you cursor is currently located.

Resources