How to replace all newlines with paragraph marks in LibreOffice Write - replace

I've used LibreOffice for years. However, I do not tend to need to replace a newline with a paragraph very often. Every time I do, I go to the LibreOffice page with the regular expressions and work through it and take quite a bit of time to get it right.
Today, as I did a general search I find an idea on Webrosis that makes it easy. Since I come to stackoverflow first when I do a search, I decide to pull together the Webrosis idea and the solution for this particular issue together here.

Turn on Formatting Marks (ctrl-F10)
Press Enter and then copy the paragraph mark
Open search and replace (ctrl-H)
In the search box enter \n
Under other options turn on regular expressions
Press Find All
Close the search box and all the newlines will be selected
Press ctrl-v and the paragraph mark you copied will replace all the newlines

Related

RegEx for underlining text

How can I match one line of text with a regex and follow it up with a line of dashes exactly as many as characters in the initial match to achieve text-only underlining. I intend to use this with the search and replace function (likely in the scope of a macro) inside an editor. Probably, but not necessarily, Visual Studio Code.
This is a heading
should turn into
This is a heading
-----------------
I believe I have read an example for that years ago but can't find it; neither do I seem to be able to formulate a search query to get anything useful out of Google (including variations of the question's title). If you are I'd be interested in that, too.
The best I can come up with is this:
^(.)(?=(.*\n?))|.
Substitution
$1$2-
syntax
note
^(.)
match the first character of a line, capture it in group 1
(?=(.*\n?))
then look ahead for the rest of this line and capture it in group 2, including a line break if there's any
|.
or a normal character
But the text must has a line break after it, or the underline only stays on the same line.
Not sure if it is any useful but here are the test cases.

Replace line breaks

I am using visual studio code for several things. Everything is working fine, but I cannot get one specific thing to work.
I need the ability to remove line breaks from the text.
Example:
first line
second line
Should become:
first linesecondline
Since a recent update it is possible to search for line breaks with using ^$.
It is described here: https://github.com/Microsoft/vscode/pull/314
The problem I have is that when I use this for replacing, it does actually "add" to the line break and does not "replace" it.
The latest version of VS Code has a shortcut to join lines (some may say remove breaks) from selection: CTRL + J.
I found that (at least on Windows) the solution was to use search and replace with a regular expression. Search for $\n and replace with nothing to get rid of the newlines. Note that the newline character that we want to replace is placed after the end of line matcher ($).
#tripleonard hint did not work for me (no shortcut key assigned), so what I did was first ctrl+shift+p to list all commands and then just type Join lines
I'm able to manage this with the search and replace tool and "Use Regular Expression" enabled. Search for the pattern \n$ and replace with $
In my case shorcut in VS Code was not set. It took me a while to find out what command in VS Code am I looking for. For other with same problem it is: "Join lines".
Turn on regex mode and find and replace.
Search for \n and replace with nothing.
Select the new line, and press ctrl+D (and hold it).
Then press ctrl+h, you will be able to replace it with whatever you need.
On Mac, use cmd+a to select all lines. Then, use cmd+shift+p to open commands and type Join Line and click on it.
You can use \n to search for new lines
but while finding/searching,
the Use Regular Expression option should be enabled
Press ctrl+f or ctrl + h
Copy and past this ^(\s)*$\n expression into top input field
after click on the * icon, then you can see all white lines break.
Past bottom input field = \n //one line break
That means what you want to replate in white line break
After click on the Replace or Replace All Icon button
https://bitcoden.com/answers/visual-studio-code-delete-all-blank-lines-regex

use notepad++ to format data

I have a dataset that looks like this:
1 -0.151714363660730E+03 0.681572558518519E+02
-0.147787110884357E+03 0.702453634941157E+02
-0.147765104000000E+03 0.702198060000000E+02
-0.147681722000000E+03 0.701999540000000E+02
-0.147648000000000E+03 0.702032990000000E+02
-0.147585678000000E+03 0.702033980000000E+02
-0.147505270000000E+03 0.702003840000000E+02
-0.147431532000000E+03 0.701888260000000E+02
-0.147402283000000E+03 0.701852730000000E+02
how can I use find and replace in notepad++ to put all the data on one line
The general algorithm:
Switch to advanced search mode
Replace all \r\n to space
Replace all \n to space
Switch to RegExp search mode
Replace \s+ to space
*HINTS:
depending on encoding of the endline symbol point 2 or 3 can be excluded.
I don't have English version of notepad++, and my translation of search modes could be incorrect.
Hey, and now where is the part about single space delimiter?
If you do not need it, just remove steps 4-5.
Press ctrl+h
Select 'extended'
Replace all \r\n with `` (CR+LF line endings)
Replace all \n with `` (LF line endings)
My first idea would be only a simple search and replace with this params:
from: " "
to: " "
But it's trivial, and I assume it wouldn't work, just because you asked this question. I don't know anything about your files, but there is another way to complete tasks like this using Notepad++.
You can use "Macros" very simply. You have to click to the "Recording Macros" button (Macros menu), and show a repeatable solution only for 1 line. After that you can stop the recording, and with Ctrl+Shift+P you can repeat it very quickly. It's a very useful and general solution, since i've found it I use it all the time to solve this kind of problems.

How to replace line-breaks with commas using grep in TextWrangler?

I have a text-file container a number of lines, which I need to turn into a csv. What is the easiest way to replace all the line-breaks with ", ". I have TextWrangler and read that it would do so by using grep and regular expressions, but have very little experience using regular expressions and don't know how grep works. Anyone who can help me get started?
Choose Find from the Search menu. TextWrangler opens the Find window.
Select the "Grep" checkbox
Type the string you are looking for ("\n" or "\r\n" or "\r") in the Find textfield.
Type the replace string (", ") in the Replace text field.
Click "Replace All"
See chapters 7 and 8 of the TextWrangler User Manual if you have problems.
Alternatively, and with only two pieces of software (Excel and Notepad++, which is also free and AWESOME).
Take your list (I assume it's one per line, in a column, for example):
Remove any empty cells
Copy the addresses, and Paste Special>Transpose (this put them into cells going from A-->).
Copy list into notepad++ - you'll note that it shoves them in as one long list, losing that irritating table structure.
Find the shortest clear space (but use the entire space) between two email addresses, and replace all with a ","
Then find all remaining spaces (i go with one space at a time), and replace with nothing (i.e. the 'replace with' box is empty).
Et voila!
and you know you can also save stuff as comma-separated values, right?

Interactive search/replace regex in Vim?

I know the regex for doing a global replace,
%s/old/new/g
How do you go about doing an interactive search-replace in Vim?
Add the flag c (in the vim command prompt):
:%s/old/new/gc
will give you a yes/no prompt at each occurrence of 'old'.
Vim's built-in help offers useful info on the options available once substitution with confirmation has been selected. Use:
:h :s
Then scroll to section on confirm options. Screenshot below:
For instance, to substitute this and all remaining matches, use a.
Mark Biek pointed out using:
%s/old/new/gc
for a global search replace with confirmation for each substitution. But, I also enjoy interactively verifying that the old text will match correctly. I first do a search with a regex, then I reuse that pattern:
/old.pattern.to.match
%s//replacement/gc
The s// will use the last search pattern.
I think you're looking for c, eg s/abc/123/gc, this will cause VIM to confirm the replacements. See :help :substitute for more information.
I usually use the find/substitute/next/repeat command :-)
/old<CR>3snew<ESC>n.n.n.n.n.n.n.
That's find "old", substitute 3 characters for "new", find next, repeat substitute, and so on.
It's a pain for massive substitutions but it lets you selectively ignore some occurrences of old (by just pressing n again to find the next one instead of . to repeat a substitution).
If you just want to count the number of occurrences of 'abc' then you can do %s/abc//gn. This doesn't replace anything but just reports the number of occurrences of 'abc'.
If your replacement text needs to change for each matched occurrence (i.e. not simply choosing Yes/No to apply a singular replacement) you can use a Vim plugin I made called interactive-replace.
Neovim now has a feature inccommand which allows you to preview the substitution:
inccommand has two options:
set inccommand=split previews substitutions in a split pane
set inccommand=nosplit previews substitution in the active buffer
Image taken from: https://medium.com/#eric.burel/stop-using-open-source-5cb19baca44d
Documentation of the feature: https://neovim.io/doc/user/options.html#'inccommand'