Shell Script doesn't color multiline <<EOF statement - visual-studio-code

I'm working with a shell script in VSCode,
I'd like to be able to collapse the function.
In order for me to do that, the 'EOF' word has to have some whitespace before it.
But if I put whitespace before it, the entire coloring of the file is ruined (including all the functions appearing thereafter)
Is there a setting / or another way to do it so it will not behave like this?
Thanks
With EOF word at the beginning of the line
With some whitespace before the EOF

Related

How to convert embedded CRLF codes to their REAL newlines in Vscode?

I searched everywhere for this, the problem is that the search criteria is very similar to other questions.
The issue I have is that file (script actually) is embedded in another file. So when I open the parent file I can see the script as massive string with several \n and \r\n codes. I need a way to convert these codes to what they should be so that it formats the code correctly then I can read said code and work on it.
Quick snippet:
\n\n\n\n\nlocal scriptingFunctions\n\n\n\n\nlocal measuringCircles = {}\r\nlocal isCurrentlyCheckingCoherency
Should covert to:
local scriptingFunctions
local measuringCircles = {}
local isCurrentlyCheckingCoherency
perform a Regex Find-Replace
Find: (\\r)?\\n
Replace: \n
If you don't need to reconvert from newlines to \n after you're done working on the code, you can accomplish the trick by simply pressing ctrl-f and substituting every occurrence of \n with a new line (you can type enter in the replace box by pressing ctrl-enter or shift-enter).
See an example ctrl-f to do this:
If after you're done working on the code you need to reconvert to \n, you can add an invisible char to the replace string (typing it like ctrl-enter invisibleChar), and after you're done you can re-replace it with \n.
There's plenty of invisible chars, but I'd personally suggest [U+200b] (you can copy it from here); another good one is [U+2800] (⠀), as it renders as a normal whitespace, and thus is noticeable.
A thing to notice is that recent versions of vscode will show a highlight around invisible chars, but you can easily disable it by clicking on Adjust settings and then selecting Exclude from being highlighted.
If you need to reenable highlighting in the future, you'll have to look for "editor.unicodeHighlight.allowedCharacters" in the settings.

Changing the default display of line breaks in search window?

I recently switched from Textwrangler to BBEdit. I use these editors to perform large multi-file GREP-search mainly. But in BBEdit I noticed that line breaks automatically get converted to \n in the search window, and that makes in very hard for me to get an overview of the search I'm about to perform, when everything is on one line.
When I copy a text with line breaks, for example
Line
Line
Line
and paste it in the search window, it looks like this:
Line\n\nLine\n\nLine
In TextWrangler I was able to see the line breaks as line breaks, not \n. How can I change that in BBEdit?
Thanks!

Regex to delete all empty lines whatsoever?

In Windows 10 I use a text editor (I'd like not to point out a particular one but I usually use Visual Studio Code AKA "VSCODE").
I need a way to delete all blank lines whatsoever only with regex after I matched them with this code:
^\s*$
After I match the lines themselves, how is it possible to delete the lines?
AFAIK, regex only edit lines, not deleting lines or adding lines.
I desire a way to delete all matched (empty).
Hitting "Enter" or "Delete" in the empty "replace" box doesn't delete lines:
You were close. You were missing the new line character in your regex. This worked for me:
^\s*$\n
Without the newline character, you are matching the blank line itself which you then replace with nothing but you've left the newline character so it still leaves an empty line in place.

Line breaks using dlmcell in Matlab - shows up in Notepad++ but not Notepad

I am using the function dlmcell in Matlab to output text. I want text on a new line each time I append using dlmcell.
When I open my written document in Notepad++, each snippet of text is on a new line as I want it. However, opening it in Notepad that comes with windows, everything is on the same line. Can somebody tell me why this is, and how to fix it?
I'm assuming you're using the string \n to declare a new line in your output. For Notepad++ this is sufficient, because it interprets a new line just with \n. For the Windows Editor you need to include the carriage return also:
substitute:
\n with \r\n
This way not just a new line is created, it also tells the editor to actually continue on the next line.
To illustrate what I mean, open your output file with Notepad++ and activate View > Show Symbol > All characters and you will see something like:
I wrote this with Notepad++ and it automatically adds CR (carriage return) and LF (line feed) at the end of every line. Matlab doesn't if you don't tell it. So your output file only contains LF without the above mentioned substitution.
I've had a look into dlmcell, which is a FEX-function. In the current version \r\n is implemented actually. Do you have the newest version of that function (Download)? If not, something else must be wrong, please post some code.

Surround with quotation marks

How is it possible in Eclipse JDT to convert a multiline selection to String. Like the following
From:
xxxx
yyyy
zzz
To:
"xxxx " +
"yyyy " +
"zzz"
I tried the following template
"${line_selection}${cursor}"+
but that way I only get the whole block surrounded not each line separately. How can I achieve a multiline processing like commenting the selected block?
Maybe this is not what you mean but...
If I'm on a line in Eclipse and I enter double quotation marks, then inside that paste a multiline selection (like your xyz example) it will paste out like this:
"xxxx\n" +
"yyyy\n" +
"zzz"
Then you could just find/replace in a selection for "\n" to "", if you didn't intend the newlines.
I think the option to enable this is in Window/Preferences, under Java/Editor/Typing/, check the box next to "Escape text when pasting into a string literal". (Eclipse 3.4 Ganymede)
Find/Replace with the regex option turned on. Find:
^(.*)$
Replace with:
"$1" +
Well, the last line will have a surplus +, you have to delete it manually.
I would go with a Find/Replace eclipse in regexp mode:
Find:
^((?:\s(?)\S?)((?:\s(?![\r\n])))
Replace with
\1"\2"\3 +
Will preserve exactly whatever space or tabs you have before and after each string, and will surround them with the needed double-quotes. (last '+' needs to be removed)
This may not be exactly the answer you're looking for. You can easily achieve what you're asking by using the sed stream editor. This is available on all flavors of Unix, and also on Windows, by downloading a toolkit like cygwin. On the Unix shell command line run the command
sed 's/^/"/;s/$/"+/'
and paste the text you want to convert. On its output you'll obtain the converted text. The argument passed to sed says substitute (s) the beginning of a line (^) with a quote, and substitute (s) the end of each line ($) with a quote and a plus.
If the text you want to convert is large you may want to redirect sed's input and output through files. In such a case run something like
sed 's/^/"/;s/$/"+/' <inputfile >outputfile
On Windows you can also use the winclip command of the Outwit tool suite to directly change what's in the clipboard. Simply run
winclip -p | sed 's/^/"/;s/$/"+/' | winclip -c
The above command will paste the clipboard's contents into sed and the result back into the clipboard.
Finally, if you're often using this command, it makes sense placing it into a shell script file, so that you can easily run it. You can then even assign an Eclipse keyboard shortcut to it.