I'm trying to edit the python.vim syntax file to duplicate the syntax highlighting for python in Textmate. The attached image illustrates the highlighting of function parameters which i'm struggling to achieve.
The self, a, b is highlighted in Textmate but not in Vim. I figured that I have to do the following.
Match a new region
syn region pythonFunction start="(" end=")" contains=pythonParameters skipwhite transparent
Try to match a string followed by a comma
syn match pythonParameters ".*" contained
So in point 2 the ".*" will match any string at the moment and must be expanded further to be correct. However i'm not sure if i'm on the right path since the match in 2 is not constrained
to region between the brackets (). Any tips or input will be appreciated.
EDIT 1: If anyone wondered how it turned out eventually.
Here is my vim syntax highlighting for python.
EDIT 2: So just for ultimate thoroughness I created a github page for it.
http://pfdevilliers.github.com/Pretty-Vim-Python/
Ok, you've got a couple problems.
There is already a region called pythonFunction, for highlighting def and function names.
This region will match any parenthesis, anywhere
So, find the pythonFunction match, and change it to this:
syn match pythonFunction
\ "\%(\%(def\s\|class\s\|#\)\s*\)\#<=\h\%(\w\|\.\)*" contained nextgroup=pythonVars
Adding nextgroup tells vim to match pythonVars after a function definition.
Then add:
syn region pythonVars start="(" end=")" contained contains=pythonParameters transparent keepend
syn match pythonParameters "[^,]*" contained skipwhite
Finally, to actually highlight it, find the HiLink section, and add:
HiLink pythonParameters Comment
Change Comment to the grouping you want, or add your own. I'm using Statement myself.
Vim, Highlight matching Parenthesis ( ), square brackets [ ], and curly braces: { }
The config options for setting the colors of the foreground and background under the cursor when over a parentheses, square bracket or curly brace is this one:
hi MatchParen ctermfg=16 ctermbg=208 cterm=bold
To enable/disable the background color of the line under the cursor:
:set cursorline
:set nocursorline
To set the color of the background color of the line under the cursor:
hi VisualNOS ctermbg=999
hi Visual ctermbg=999
Here is my adaptation:
https://github.com/sentientmachine/erics_vim_syntax_and_color_highlighting
Related
I got a list of data like exactly like that
51.9499, 7.555780000000027; 51.49705, 9.389030000000048; 51.249182, 6.991165099999989; 47.3163508, 11.09513949999996; 51.33424979999999, 12.574196000000029; 50.0297493, 19.196331099999952; 47.8270212, 16.25014150000004;
and I want to beautify it a bit by having linebreaks behind the "; " so it would rather look like
51.9499, 7.555780000000027;
51.49705, 9.389030000000048;
51.249182, 6.991165099999989;
...
I am using Adobe Brackets and I am trying to put a hard linebreak into the replace dialogue but that doesn't work - what would instead work?
In the replace bar, click on the .* icon to change the replace method to regular expression.
Then you can use ;\s* replace with ;\n to beautify your code accordingly.
You can see an example of this regex being run here.
Outputs the following:
51.9499, 7.555780000000027;
51.49705, 9.389030000000048;
51.249182, 6.991165099999989;
47.3163508, 11.09513949999996;
51.33424979999999, 12.574196000000029;
50.0297493, 19.196331099999952;
47.8270212, 16.25014150000004;
I am trying to match everything between multiple set of brackets
Example of data
[[42.30722,-83.181125],[42.30722,-83.18112667],[42.30722167,-83.18112667,[42.30721667,-83.181125],[+42.30721667,-83.181125]]
I need to match everything within the inner brackets as below
42.30722,-83.181125,
42.30722,-83.18112667,
42.30722167,-83.18112667,
42.30721667,-83.181125,
+42.30721667,-83.181125
How do I do that. I tried \[([^\[\]]|)*\] but it gives me values with brackets. Can anybody please help me with this. Thanks in advance
Seems like one of them is missing a bracket maybe, or if not, maybe some expression similar to:
\[([+-]?\d+\.\d+)\s*,\s*([+-]?\d+\.\d+)\s*\]?
might be OK to start with.
Test
import re
expression = r"\[([+-]?\d+\.\d+)\s*,\s*([+-]?\d+\.\d+)\s*\]?"
string = """
[[42.30722,-83.181125],[42.30722,-83.18112667],[42.30722167,-83.18112667,[42.30721667,-83.181125],[+42.30721667,-83.181125]]
"""
print([list(i) for i in re.findall(expression, string)])
print(re.findall(expression, string))
Output
[['42.30722', '-83.181125'], ['42.30722', '-83.18112667'], ['42.30722167', '-83.18112667'], ['42.30721667', '-83.181125'], ['+42.30721667', '-83.181125']]
[('42.30722', '-83.181125'), ('42.30722', '-83.18112667'), ('42.30722167', '-83.18112667'), ('42.30721667', '-83.181125'), ('+42.30721667', '-83.181125')]
If you wish to simplify/modify/explore the expression, it's been explained on the top right panel of regex101.com. If you'd like, you can also watch in this link, how it would match against some sample inputs.
A little late, but figured I would include it anyhow.
Your 3rd set is missing a ']'.
If that is in there, then in Alteryx, you can just use Text to Columns splitting to Rows and ignore delimiter in brackets
Having a bit of trouble with some code I'm working through. Basically, I have transcripts (txt files) for a few Japanese anime, of which I want to remove everything but the spoken lines (Japanese sentences) in order to do some NLP experiments.
I've managed to accomplish a good bit of cleaning, but where I'm stuck is with parentheses. A majority of the elements in my list start with a character's name inside parentheses (i.e. (Armin)). I want to remove these, but all the regex code I've found online doesn't seem to work.
Here's a snippet of the list I'm working with:
['(アルミン)その日', '人類は思い出した', '(アルミン)奴らに', '支配されていた恐怖を', '(アルミン)鳥籠の中に', 'とらわれていた―', '屈辱を', '(キース)総員', '戦闘用意!', '目標は1体だ', '必ず仕留め―', 'ここを', '我々', '人類', '最初の壁外拠点とする!', '(エルヴィン)あっ…', '目標接近!', '(キース)訓練どおり5つに分かれろ!', '囮は我々が引き受ける!', '全攻撃班', '立体機動に移れ!', '(エルヴィン)全方向から', '同時に叩くぞ!', '(モーゼス)やあーっ!']
I've tried the following code (it's as close as I could get):
no_parentheses = []
for line in mylist:
if '(' in line:
line = re.sub('\(.*\)','', line)
no_parentheses.append(line)
else:
no_parentheses.append(line)
But when I view the results, those pesky parentheses remain in my list mockingly.
Could anyone offer suggestions to resolve this issue?
Thanks again!
The brackets used in the text are full-width brackets. Specifically, U+FF08 FULLWIDTH LEFT PARENTHESIS, and U+FF09 FULLWIDTH RIGHT PARENTHESIS.
Your regex should use full-width brackets as well.
line = re.sub('(.*)','', line)
I am trying to make an angularjs syntax highlighting file for vim. A piece of the file is:
syn match ngMethods /\.[0-9A-Za-z_\-\$]\+\s*\((\|=\)/ contains=AngularMethods
syn keyword AngularMethods contained $addControl $anchorScroll $animate ...
syn match ngObjMethods /^\s*[0-9A-Za-z_\-\$]\+\s*:/ contains=AngularObjectMethods
syn keyword AngularObjectMethods contained compile controller link ...
etc...
Down below I have:
hi def link AngularMethods Function
hi def link AngularObjectMethods Function
The first regular expression (for AngularMethods) is supposed to capture things like $addControl in the following:
myelement.$addControl()
myelement.$addControl = function ()
The second regular expression (for AngularObjectMethods) captures things like compile in:
compile : function () {}
The AngularMethods one does NOT work but the latter one does. Can anyone see the problem? I've also tried using the regexes:
/\.\zs[0-9A-Za-z_\-\$]\+\ze\s*\((\|=\)/
/\.[0-9A-Za-z_\-\$]\+\s*\((\|=\)\#=/
The former matches the exact word. The latter is something I saw in another syntax file. Any ideas? Thanks for your help!
Edit:
Kent (below) was correct about the keyword. This uncovered the real problem which is that I have another regex:
syn match ngProperties /\.[0-9A-Za-z_\-\$]\+\s*[^(=]/ contains=AngularProperties
syn keyword AngularProperties contained $attr $dirty $error ...
which is supposed to be the complement of the ngMethods regex. If I comment out the ngProperties regex, the ngMethods regex works. This means ngProperties is bad. It is supposed to catch things like $attr in:
var myAttribute = element.$attr;
I will try to fix this. Can someone post the correct regex just in case?
The regex is not the problem for your syntax.
What very likely the cause of the problem is, your iskeyword option doesn't have the dollar ($) sign.
what you can test is:
remove the $ from contained $addControl $anchorScrol, to see if it will work
or
execute: set iskeyword+=$ to see if it works.
I'm using dflydev's markdown which is based on michelf's project to transform Markdown into HTML.
My site is RTL by default and I'd like to add a custom tag to allow left-aligning paragraphs,
something like:
regular text, right aligned.
<- some text that will be aligned to the left
<--
fenced text that will be aligned to the left
<--
I'm trying to build the regex pattern to catch those blocks:
For <- ... I have: /^<- ([^\n]+)/
For the fenced block I couldn't get a working pattern
I'd like to get help on the fenced block regex and on improving the one-line regex I already have.
Thanks!
This would match your second group:
^<--.*?<--$
For your first group I would use something like this instead:
^<-[^-][^\r\n]*?$
For your first case you can use
/^<-(.*?)$/
and get the first group.
For the second case use
/^<--(.*?)<--$/
and get the first group.