How to force single/orphan letters to next line? - libreoffice

I want to automatically change:
blah blah blah b
blah blah blah
into:
blah blah blah
b blah blah blah
in the whole document and keep it like that.
I could insert a hard space before each and every single/orphan letter at the end of the line, but it would take lots of time and also, after slightly modifying text, it would shuffle and cause the same problem again.
Is it possible to automatically force those letters to the next line?

Rather than inserting a space before the character, select the space following the character instead. Press Ctrl+Shift+Space to prevent a line break in that location.
The result:
To do this for all occurrences in the document:
Edit -> Find and Replace.
Find: ([:space:][:alnum:])[:space:]
Replace: $1\u00a0. However, \u syntax does not currently work for replace, so where it says \u00a0, copy and paste a non-breaking space character instead.
Enable Other Options -> Regular Expressions.
Replace All.
Related: https://ask.libreoffice.org/en/question/134113/how-to-detect-non-breakable-space-when-iterating-document-via-uno/

Related

How to prevent line breaks (general)

I'm writing a text on C++. But often the line breaks after the first "+", so I get C+
+
This is just an example. How can I prevent line breaking of arbitrary parts in my odt doc?
There is no formatting option at the moment
Use the Unicode Character U+2060. Insert it an every point the line breaks, but it shouldn't. It glues two parts together.
Example for "C++" ( | represents the text cursor )
C|++
Press Ctrl+Shift+U
u will appear on the screen
Type in 2060
Press Enter
Now the line won't break between C and +.
Move cursor: C+|+
repeat process

How to edit all lines in Visual Studio Code

I have a list of data to which I need to put a ' symbol at the start of the line and at the end of the line. So the original data looks like this:
abcde
cdeab
deabc
eabcd
And I want all of the lines to look like this:
'abcde'
'cdeab'
'deabc'
'eabcd'
In my real data, I would have 10,000 of lines. So if I can do something like Ctrl+Shift+A to select the entire document and then have some magic shortcut to change from selecting all lines to editing all lines that would be perfect!
You could edit and replace with a regex:
Find (Ctrl+F):
^(.+)$
Replace:
'$1'
This regex finds any content on a line and wraps it inside quotes. The $1 refers to whatever is matched inside the parentheses in the regex. In this case, it's "one or more characters" i.e. everything on the line. Be sure to tick the regex icon.
If every line may or may not have a space before the content, and you want every line to have a space, try this:
Find:
^ ?(.+)$
Replace (notice the space before the first quote):
'$1'
Here is an easy way to do this:
Ctrl+A to select all or select your desired text.
Shift+Alt+I to put a cursor at the end of each line.
Type your ' (or whatever you want at the end).
Home will move all your cursors to the beginning of the lines.
Type your ' (or whatever you want at the beginning of all the lines).
You can use the Alt + Shift shortcut.
First press Alt + Shift then click the mouse button on the first line.
Go to the last line, and then do the same.
This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.
Do the same on the other side too.
Use Toggle Multi curosr Modified from action pane.
Select the cursor points with ctrl + <Mouse click> , you can modify everything simultaneously.
This will require lots of manual efforts if lines are more
You can use Find and Replace.
Besides, paste to Excel and using a function to add character '.
The first thing that came to my mind - replace abcde with 'abcde' line by using option Find and Replace option. I'm pretty sure Visual Studio Code has something similar to that.
You can use the Shift +Alt shortcut for windows and for Mac use Shift + Option
First press Alt + Shift/Shift + Option then click the mouse button on the first line.
This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.
Place Cursor where you want to insert/delete text.
Goto Selection Menu and choose Column Selection Mode
Scroll to the bottom of the data and shift + click in the last line where you placed the first cursor.
Perform action (add/delete whatevs)
Repeat for whatever other areas you want to change.
v: 1.74.3
1- You can use the Ctrl + H shortcut (menu Edit → Replace)
Enter abcde in Find Control.
Enter 'abcde' in Replace Control.
Then press Ctrl + Alt + Enter.

sublime text / ms word delete misc line breaks in code

I have a csv file that has random line breaks throughout the file. (probably load errors when the file was created where the loader somehow managed to put a carriage return into the field)
How do I go in and remove all carriage returns / line breaks where the last character is not "
I have word and sublime text available for text editors
I have tried ^p with a letter infront and find and replace, but that doesnt seem to work for some of the lines for some reason
Example
"3203","Shelving Units
",".033"
instead of
"3203","Shelving Units",".033"
and
"3206","Broom
","1.00"
instead of
"3206","Broom","1.00"
Menu > Find > Replace... or Ctrl+H
Select "Regular Expression" (probably a .* icon in the bottom left, depending on your theme).
Use \n to select newlines (LF) or \r\n (CRLF).
As #GerardRoche said you can use search and replace in Sublime Text. Open it via ctrl+h and press alt+r to toggle regex to enable it. (You may want to create a backup of your file before doing such changes.)
Search for (?<=[^"\n])\n+ and replace it with nothing, press Replace All or ctrl+alt+enter to replace it.
The regex just mean: search for alt least one (+) newlines (\n), that are preceded by something different than a quotation mark or a newline (?<=[^"\n]).
You don't need to worry about carriage returns, because ST only uses them when reading and writing the file and not in the editor.

Scratch equals operator problems

I am using scratch.mit.edu version 2.0 on the internet and writing a program to evaluate a postfix expression. As I iterate through the input string such as: "23+" (postfix) letter by letter using the letter..of...block, it works fine.
I then add a letter.. of.. block to identify a spacebar character so the user can insert blanks in the expression eg "2 3 +"
However, there seems no way to recognize a blank character. I tried
1) Lookahead = ""
2) Lookahead =' '
3) Lookahead =''
None of which pick up that a space has been encountered.
Here is the project: https://scratch.mit.edu/projects/77653712/
In Scratch, the box is the string literal - no quotes, unless you're looking for literal quotes. Just put a space in the box.
Just set it to check <(Lookahead) = [ ]>: (brackets are the symbol for the box)
(That black line is me pressing ctrl+a to highlight and show that it exists.)
OK, I have found the solution. There is no character to represent a blank. You simply press space bar once!
You can see the letter nextChar of blanks is an empty space but, you must add space using the spacebar for it to work!!

Notepad++ newline in regex

Suppose you have this file:
x
a
b
c
x
x
a
b
c
x
x
and you want to find the sequence abc (and select the whole 3 lines) with Notepad++ . How to express the newline in regex, please?
Notepad++ can do that comfortably, you don't even need regexes
In the find dialogue box look in the bottom left and switch your search mode to Extended which allows \n etc.
As odds on you're working on a file in windows format you'll be looking for \r\n (carriage return, newline)
a\r\nb\r\nc
Will find the pattern over three lines
Update 18th June 2012
With the new Notepad++ v6, you can indeed search for newlines with regexes. So you can just use
a\r\nb\r\nc
even with regular expressions to accomplish what you want. Note \r\n is Windows encoding of line-breaks. In Unix files, its just \n.
Unfortunately, you can't do that in Notepad++ when using regex search. Notepad++ is based on the Scintilla editor component, which doesn't handle newlines in regex.
You can use extended search for newline searching, but I don't think that will help you search for 3 lines.
More info here.
Update: Robb and StartClass0830 were right about extended search. It does work, but not when using regular expressions search.
^a\x0D\x0Ab\x0D\x0Ac
This will work \x0D is newline and \x0A is carriage return. Assumption is that each line in your file ends with ascii 10 and 13.
I found a workaround for this.
Simply, in Extended mode replace all \r\n to a string that didn't exist in the rest of the document eg. ,,,newline,,, (watch out for special regexp chars like $, &, and *).
Then switch to Regexp mode, do some replacements (now newline is ,,,newline,,,).
Next, switch to Extended mode again and replace all ,,,newline,,, to \r\n.
For Notepad 6 and beyond, do this as a regular expression:
Select Search Mode > Regular expression (w/o . matches newline)
And in the Find what Textbox : a[\r\n]b[\r\n]+c[\r\n]
or if you are looking at the (Windows or Unix) file to see its line breaks as \r\n or \n then you may find it easier to use Extended Mode:
Select Search Mode > Extended (\n, \r, \t, \0, \x...)
And in the Find what Textbox for Windows: a\r\nb\r\nc\r\n
Or in the Find what Textbox for Unix: a\nb\nc\n
Wasn't clear if the OP intent is to select the trailing line return (after the 'c') as well, as would be necessary to remove the lines.
To not select the trailing line return, as appropriate for replacing with a non-empty string, simply remove the final line return from the matching statement.
Note that if there should be a match on the last line of the string, without a matching trailing line return, the match fails.
a\r\nb\r\nc works for me, but not ^a\x0D\x0Ab\x0D\x0Ac
Hmm, too bad that newline is not working with regular expressions. Now I have to go back to Textpad again. :(
Select Search Mode Which is
Extended (\n, \r, \t, \0, \x...)
\n is new line and such
This is Manuel
Find: "(^a.$)\r\n(b.)\r\n^(c.*)$" - pickup 3 whole lines, only storing data
Replace with: "\1\2\3" - Put down (replay) data
Works fine in Regex with Notepad++ v7.9.5
Place holders: ^ Start and $ End of line can be inside or out of ()store as shown, though clearly not necessary in given example. Note "[^x]" is different - here "^" is "NOT".
Advantage of storing and replay allows much more complicated pattern match without having to type in again what you want to end up with, and even change of replay: "\2\3\1" for "bca"
I have run accross this little issue when the document is windows CR/LF
If you click the box for . to match newlines you need .. to match CR/LF so if you have
<blah><blah>",
"<more><blah>
you need to use ",.." to match some string comma cr/lf another string
In Notepad++ you can also try highlighting the desired part of the text and then pressing CTRL+J.
That would justify the text and thus removing all line endings.