In code files, when I expand selection, brackets, quotes, and spaces are used to delimit "levels" of expansion.
However, when I'm working in plain text, expand selection ignores brackets and goes from selecting one word to then selecting a whole line.
Is there any way to have expand selection respect brackets and quotes in plain text files?
Related
I'm doing a lot of text editing right now that involves replacing spans of text with spaces (same number of spaces as number of replaced characters). It would be easier and more efficient if I could somehow highlight/select the text to replace, and then replace it all with blank spaces instead of first deleting the text and then manually refilling the spaces, tabs or newlines, especially during moments where I want to be precise.
For example:
This is my example sentence.
I decide I want to select 'my example' and delete it, like this:
This is sentence.
Instead of having it go like this:
This is sentence.
Is there an easier way to do this?
This is also easy with this extension, Find and Transform (disclaimer: I wrote it). Here is a keybinding that would work (in your keybindings.json):
{
"key": "alt+q", // whatever keybinding you want
"command": "findInCurrentFile",
"args": {
"replace": [ "$${ return `$1`.replace(/./g, ' '); }$$" ],
"isRegex": true,
"restrictFind": "selections",
"postCommands": "cancelSelection" // if you had multiple selections and wanted to clear them
}
}
"restrictFind": "selections" will only work within selections, as many as you want. If you had repetitive text in the document, you could omit this argument and it will find the selected text wherever it occurs in the document and replace it.
The $1 referred to is the selected text.
What you can do is switch your editor find mode to regex, and put "[^\s]" in the find input, and then " " (space) in the replace input. Then select the text you want to replace with spaces and either click the "Find in Selection" button or use the keyboard shortcut (Ex. alt+l). Then click "Replace All" or use the keyboard shortcut (Ex. ctrl+alt+enter).
This will replace each instance of any non-whitespace character in the selection with a space character.
If you don't want to preserve the types of whitespace characters (Ex. keeping tab characters as tab characters), just put "." in the find input field instead of "[^\s]".
You can use the extension Regex Text Generator
Add this to your settings.json
"regexTextGen.predefined": {
"Replace with spaces": {
"originalTextRegex": "(?g)(.)",
"generatorRegex": " {S}"
}
}
Select the text you want to replace, multi cursor is supported.
Execute command: Generate text based on Regular Expression (regex)
Select the predefined: Replace with spaces
Press Enter 2 times.
You are able to preview the replacement and Escape if needed when you are allowed to edit the generator expression.
You can create a key binding for this if you need to do it a lot. See the extension page for an example.
Most text editors for writing code have settings that define which characters break words for things like keystroke navigation and tab-completion. Atom has a Non Word Characters field in the settings, Sublime Text has a JSON setting word_separators, and Visual Studio Code has a JSON setting editor.wordSeparators. There is some variation, but they all default to something similar to this backslash-escaped string
"`~!##$%^&*()-=+[{]}\\|;:'\",.<>/?"
None of them appear to include whitespace characters as word separators. This makes complete sense to me, but is it possible to prevent any of these editors (or an editor I haven't listed) from treating a single space as a word separator? I want to change this behavior because I have a special case where I'd like to tab-complete strings that contain single spaces.
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.
A quotation mark placed by the Eclipse editor works just fine in an XML file. Yet if I edit the XML in Microsoft Word and type in a new quotation mark and then place the XML back into Eclipse I get errors. The two quotation marks look different: one looks normal, while the one from Word looks like an italic version. When I replace the Word Quotation marks with the Eclipse marks the errors go away. I'm sure its different ascii codes. What's going on here?
Word is inserting smart quotes (that is the technical term for them). The ones that word puts are opening and closing ones. Word is created as a document editor, not a code editor. It puts in corrections to make your documents look better, not preserve language syntax. If you still want to use word as a code editor, you can disable smart quotes (in Word 2007 it is under Options > Proofing > AutoCorrect Options... > AutoFormat Tab > "Straight quotes" with "smart quotes")
Microsoft Word automatically changes quotation marks into curly quotation marks (left and right) as you type. The curly ones are not the same ACSII character as the normal quotation mark.
In Word 2003, there's a setting in AutoCorrect options in the AutoFormat As You Type tab that says replace "straight quotes with smart quotes", so you can disable this feature. I don't know where to find this setting in later versions of Word.
I need to create lines of text that say something like [Insert text here], but when you click anywhere between those brackets, the entire bracket (text included) gets highlighted. If you use some of Words' templates, these kind of sentences appear as placeholders. This is what I am trying to accomplish; placeholder text.
Type Ctrl+F9... type the text [macrobutton nomacro "your text here"] inside the brackets.
Alt+F9 will toggle the code on and off.