I'm working on a Sublime Text 3 plugin, which contains a number of completions for the standard library. Some of these functions (e.g. io.open( filename, mode )) contain the dot character (".").
The problem is, Sublime Text cancels the completion dialog when a "." is typed (word boundary).
To get around this, I've tried using underscores instead of dots in the triggers:
{"trigger": "io_open( filename, mode )", "contents": "io.open( ${1:filename}, ${2:mode} )"}
However, this doesn't work very well at all. If the user tries to type in io.open instead of io_open, Sublime restarts the completion at the dot, and they end up with io.io.open.
Is there any way around this? Having the dot character as word boundary is useful for selecting text, so I'd like to keep that if it is possible.
Related
Dvelving straight into the problem; all I'm trying to do here is to duplicate a line and add a bracket at the end using Regular Expressions and automate the process through the Replace With dialog in Notepad ++.
My issue visualized:
In the representation underneath, I have a bunch of instances of "["Mesh"]" that all have different path values assigned to it. All I want to do is duplicate it the path entry and add bracket at the end before the comma in the duplicated one.
What I have right now:
...
["Mesh"] = Platform(
"models/ships/japan/Zuikaku.mmod",
...
What I'm trying to achieve:
...
["Mesh"] = Platform(
"models/ships/japan/Zuikaku.mmod",
"models/ships/japan/Zuikaku.mmod"),
...
Without getting too specific, since there are ~500 of these instances across the file I'm modifying, I do not want to go through each one while simply clicking CTRL + D to duplicate each line and add the bracket as that would take literal ages to do.
I have some limited experience with Regular Expressions from previous uses, but very limited. I know I can select the entire line in the Search dialog using ".*" but that's as far as I've gotten.
Thank you in advance for your time!
You should be able to use this regex (disable . matches newline). I am using (\R+) to capture end-of-line characters (and reproduce them in the output) so that it will work on systems that use other than just newline to end lines.
(\["Mesh"\]\s*=\s*.*(\R+))(.*),$
Replace with
$1$3,$2$3\),
For the input of
...
["Mesh"] = Platform(
"models/ships/japan/Zuikaku.mmod",
...
This gives
...
["Mesh"] = Platform(
"models/ships/japan/Zuikaku.mmod",
"models/ships/japan/Zuikaku.mmod"),
...
Whenever I paste text into a Google Docs document, all the newline characters get convereted into vertical tab characters (\013 OR \v). This happens regardless of the source of the clipboard text (webpage, word, notepad++).
Usually this means I have to work my way through the document clearing all the vertical tabs and replacing them with proper newlines by backspacing the character and hitting return. However, I want to write a script to replace all the characters in the doc at once. The Replace ui feature doesn't support newline characters but I'm hoping the scripting api does.
I have written the code below, but though it runs, the vertical tab characters are not replaced. I can still see hundreds in the document with the find/replace ui feature. What am I doing wrong?
function myFunction() {
var body = DocumentApp.getActiveDocument().getBody();
body.replaceText("\\v", "\n");
}
I have a document in vim which contains encoding-related chars I want to get rid of (e.g. replace with "").
I have a general problem in describing their origin. There are examples of how they are displayed in different editors (my desired tool to get rid of them is vim).
in vim:
Oś<9c>więcim (<9c> is a part I would like to get rid of)
in Geany:
(but copy-paste copies without this 'square' sign)
in LibreOffice Calc:
Please note there are other Polish-langauage-specific signs in my text whcih are displayed correct.
Q: how to regex it out in vim?
You can enter the <9c> via :help i_CTRL-V_digit by pressing Ctrl + V (on Windows, often Ctrl + Q instead), followed by X and the hexadecimal number:
:%s/<C-V>x9c//g
Alternatively, the special \%x9c regular expression atom matches that value:
:%s/\%x9c//g
Alternatively, you could also just yank the character when the cursor is on it via yl, and then paste in the :s command-line via <C-R>".
First, I'm using EditPadPro for my regex cleaning, so any answers given should work within that environment.
I get a large spreadsheet full of data that I have to clean every day. I've managed to get it down to a couple of different regexes that I run, and this works... but I'm curious to see if it's possible to reduce down to a single regex.
Here is some sample data:
3-CPC_114851_70095_70095_CAN-bre
3-CPC_114851_70095_70095_CAN
b11-ao1-113775-bre
b7-ao-114441
b7-ao-114441-bre
b7-ao1-114441
b7-ao1-114441-bre
http://go.nlvid.com/results1/?http://bo
go.nlv/results1/?click
b4-sm-1359
b6-sm-1356-bre
1359_195_1453814569-bre
1356_104_1456856729
b15-rad-8905
b15-rad-8905-bre
Here is how the above data needs to end up:
114851-bre
114851
113775-bre
114441
114441-bre
114441
114441-bre
http://go.nlvid.com/results1/
go.nlv/results1/
sm-1359
sm-1356-bre
sm-1359-bre
sm-1356
rad-8905
rad-8905-bre
So, there are numerous rules, such as:
In cases of more than 2 underscores, the result needs to contain only the value immediately after the first underscore, and everything from the dash onwards.
In cases where the string contains "-ao-", "-ao1-", everything prior to the final numeric string should be removed.
If a question mark is present, everything from the mark onwards should be removed.
If the string contains "-sm-" or "-rad-", everything prior to those alpha strings should be removed.
If the string contains 2 underscores, averything after the first numeric string up to a dash
(if present) should be removed, and the string "sm-" should be prepended.
Additionally there is other data that must be left untouched, including but not limited to:
113535|24905|24905
as well as many variations on this pattern of xxxxxx|yyyyy|zzzzz (and not always those string lengths)
This may be asking way too much of regex, I'm not sure as I'm not great with it. But I've seen some pretty impressive things done with it, so I thought I'd put this out to the community and see what you come back with.
Jonathan, I can wrap all of those into one regex, except the last one (where you prepend sm- to a string that does not contain sm). It is not possible in this context, because we cannot capture "sm" to reuse in the replacement, and because there is no "conditional replacement" syntax in EPP.
That being said, you can achieve what you want in EPP with two regexes and one macro to chain the two.
Here is how.
The solution below is tested in EPP.
Regex 1
Press Ctrl + Sh + F to enter Search / Replace mode
Enter the following Search and Replace in the appropriate boxes
At the top right of the Search bar, click the Favorite Searches pull-down, select "Add", give it a name, e.g. Regex 1
Search:
(?mx)^
(?=(?:[^_\r\n]*?_){3})[^_\r\n]+?_([^_\r\n]+)[^-\r\n]+(-[^\r\n]+)?
|
[^\r\n]*?-ao1?-\D*([^\r\n]+)
|
([^\r\n?]*)(?=\?)[^\r\n]+
|
[^\r\n]*?-((?:sm|rad)-[^\r\n]+)
Replace:
\1\2\3\4\5
Regex 2
Same 1-2-3 steps as above.
Search
^(?!(?:[^_\r\n]*?_){3})(?=(?:[^_\r\n]*?_){2})(\d+)(?:[^-\r\n]+(-[^\r\n]+)?)
Replace
sm-\1\2
Chaining Regex 1 and Regex 2
Top menu: Macros, Record Macro, give it a name.
Click the Favorite searches pulldown, select Regex 1
Hit Replace All.
Click the Favorite searches pulldown, select Regex 2
Hit Replace All.
Macros, Stop recording.
Whenever you want to do your sequence of replacements, pull it by name under the Macros menu.
Testing This
I have tested my "Jonathan macro" on your input. Here is the result:
114851-bre
114851
113775-bre
114441
114441-bre
114441
114441-bre
http://go.nlvid.com/results1/
go.nlv/results1/
sm-1359
sm-1356-bre
sm-1359-bre
sm-1356
rad-8905
rad-8905-bre
Try this:
Toggle the Search Panel : SHIFT+CTRL+F
SEARCH: .*?((?:sm-|rad-)?(?:(?:\d+|[\w\.]+\/.*?))(?:-\w+)?$)
REPLACE: $1
Check REGEX and WORDS
Click Replace All or Hit CTRL+ALT+F3
Check the image below:
I use Sublime 2 for developing R and PHP code, although I imagine this shortcut would be useful for other languages.
If I copy the path of a file from Windows Explorer / XYPlorer (or other source) it has backslashes for directories. When entering a path into the source code, it needs forward slashes.
Sublime has some reasonably powerful macro commands, but I cannot think of a combination that would be able to:
take the string of text on the current line
replace all instances of '\' and replace them with '/'
Here is the workflow that I envisage:
Locate my filename in Explorer and copy its path
In Sublime, write a line of code and paste in the path
Hit a keyboard shortcut, say Ctrl+Shift+\, and all back slashes are converted to forward slashes
The result:
myPath = "E:\WORK\Code\myFile.csv";
Becomes:
myPath = "E:/WORK/Code/myFile.csv";
Without running the risk of backslashes elsewhere in the file being changed (e.g. \n characters), and without having to use multiple key presses or mouse clicks.
I imagine this would be possible with Regex. Two things I am no expert in are Sublime macros or regex, so I wonder if anyone else knows the magical commands that would achieve this?
I tried this for about 15 minutes. A few things:
Sublime text 2 doesn't allow for find/replace with macros
Sublime text 3 doesn't allow for 'find in selection'
So, I think you are kind of beat right now other than writing a plugin, which would be fairly straightforward.
This works for Sublime Text 3:
Type r before the string to tell python to read the directory as a raw string.
This way all the backslashes are read as slashes instead of 'ignore next character' (default meaning of \ in python)
Example
myPath = r"E:\WORK\Code\myFile.csv"
Python should now read the \ as /