I want to customize syntax highlighting in Vim (GUI version). There is an existing syntax file for my language. I want to add to that syntax highlighting a background colour to each line if that line starts with >. I figured out that I can basically achieve this by
:syntax match Output /^>.*$/
and adding
:hi Output guibg=LightBlue
to the colourscheme. The background of the text in these Output lines gets coloured then in light blue, but it overrides the foreground colour as well. So most of the syntax highlighting disappears. How can I keep the foreground syntax highlighting in these lines?
Also: Is there a way to extend the highlighting of the background to the end (right end of the screen) of these lines?
Here is how to preserve the syntax, I'm matching lines starting with {
:hi Output guibg=LightBlue
:match Output '\%>0v{.*'
Edit: since you want the opposite you need
:match Output '^[^<].*$'
Try this:
:hi Output guibg=LightBlue guifg=NONE
The easiest way to achieve what you're looking for is with the :match command as Eric Fortis has pointed out.
The only way I know of to achieve this with syntax highlighting will require you to match the entire line as you are currently doing. You will then need to specify, using the contains=... modifier, which syntax elements can be in your line. I'm also pretty sure these elements will need to have the contained attribute assigned to them. This way any element found in your line i.e matched by the .* will preserve it's highlighting.
See :help :syn-contains for more.
Related
My Vim is not highlighting the relatively new %i syntax. Here's an example:
I included a %w example, which works properly, to show the desired effect.
How can I get Vim to highlight %i properly?
If you’d type :syn ⏎ in control mode while editing any ruby file, you’ll see all the syntax definitions (or open system-wide syntax theme for ruby /usr/share/vim/vim81/syntax/ruby.vim or where is it located.)
The one responsible for %i[] would be rubySymbol.
%i[] is by no mean “relatively new,” the issue is your color theme does not highlight symbols differently. Not only literals, all the symbols. Run:
:hi rubySymbol term=bold ctermfg=Red
and you’ll see it perfectly works. You might tune it according to your needs (see e. g. rubyString for the inspiration) and put this somewhere in your ~/.vim/syntax/ruby.vim.
By default, Vim highlights Ruby's string delimiters and symbol delimiters differently. The string delimiters are highlighted as type Delimiter, and the symbol delimiters are highlighted the same as symbols, which is, by default, of type Constant.
If you want to highlight the %i and brackets the same as the %w, you can run the following command:
:hi link rubySymbolDelimiter rubyStringDelimiter
If you like that setting, you can put it in a file called .vim/after/syntax/ruby.vim and it will be picked up automatically whenever the Ruby syntax is enabled.
Note that in newer versions of Vim, the above command will also cause the colon in front of a symbol to be highlighted the same way as the %i. That functionality isn't configurable, since they both use the rubySymbolDelimiter match group.
Does anybody know of a non-manual method of highlighting syntax when pasted in InDesign?
I'm trying to show code of a project in an InDesign documentation but don't want to have to manually highlight the code, and preferably add numbered rows too.
Is there a plugin to achieve this?
This is the style in which I'd like to format the code.
Cheers
Not sure if you worked out an answer to this, but there's no magic button that will solve your problem.
However, InDesign does have a facility in each Paragraph style called GREP that can do what you're looking for.
This lets you write 'regex' or 'regular expressions' that are just rules for what to apply a given character style to. Yes, they look about as meaningful as Harry Potter incantations at first glance, but 2 or 3 simple regexes will get you a long way.
For instance:
(\<|<)!--\s*.*?\s*--(\>|>)
Will target HTML comments only.
(?<=").*?(?=")
This will target anything wrapped in straight double quotes.
(?<=\().*?(?=\))
This will target any text inside parentheses ().
There's an '#' symbol button in that GREP style next to where you type the regex - that gives you a drop-down menu that is almost like a 'Regex Wizard'. Try that too.
When you've got a regex that works, create a new character style for the text color and select it in the 'Apply Style' input.
Regexr.com has a tool that is good for testing this stuff. Paste your code sample in the bottom panel and your line of regex in the top. The bits that it targets will turn blue.
There is a searchable community panel on the left where people have probably already written expressions like the one you need.
I'm working out a JavaScript highlighter at the moment. It's a shame there's no communal 'Indesign style sharing library'.
Best of luck.
If had luck pasting syntax highlighted code into a Rich Text editor like Libre Office and then pasting it into Indesign. Just make sure whatever font your syntax highlighted code is in is also in InDesign because you'll get font missing errors when you pre-flight the book.
Hitting cmd+f to find text in SublimeText, I frequently see something like:
Clearly 'someText' exists on the page. Why can't Sublime find it?
Note this sometimes seems to work, and sometimes fails. I can't work out the difference though.
How can I reliably find text with Sublime Text?
I've tried to reproduce this problem with Sublime Text 2 and this is what I found:
If you place caret before the text and the hit find, the text will be found
If you place the caret after the text and then hit find, the text will not be found
It seems that Sublime Text doesn't wrap search by default. You can enable it by toggling the button with the arrow icon (second one from the left of Find what, its tooltip should say Wrap). Then the search works regardless of the caret position.
Look at the buttons right before search box. Sometimes they are just get disabled accidentally, mis-click, or the short-cut get trigged, then the search doesn't behave as expected.
From left to right, RegExp, case sensitive, whole word, wrap(search whole doc, not just below current line), you can see them with mouse pointer hover.
I strongly suggest you to disable those shortcuts to prevent unexpected toggle of these :)
Also, turning off the regex may help you in searching for symbols which have special meaning in regex. For instance, someText(foo) will not be searchable in regex mode without escaping the brackets or putting the search string in quotes.
Is there a way to simply have my blocks and their closing end keyword align properly with vim? If I have a function which is nested with several conditions, things can start to get ugly fast. Can vim save the day?
Sure. Just select the relevant block of code and press =.
There's also a nice Vim plugin called endwise that automatically inserts the ends for you.
gg=G
(go to top, re-indent all the way down to the bottom)
Im facing some problems, I looked around in the forum and didnt find
any solutions discussed. Im sorry if these have been resolved earlier.
Is there someway I can make the VIM line break after 80 characters. I
dont want the text to wrap around but create a new line. And I wish it would
break off the complete last word. So instead of fo in the previous and o
in the next line, can it break with foo in the next line?
When I end my comment and press enter, I get a # in the new line. This is
cool but when I delete # and want to start a line of code, I dont get syntax
highlighting there. It still thinks what Im typing is a comment. Is this a
bug or am I doing it wrong?
One more thing is that I have set the shiftwidth to 4. But when I press
Ctrl+S to save the document, the cursor jumps to the beginning of the
sentence. I then need to manually go back to my original position to begin
the code. Is there a way I can resolve this?
Thank you for reading this. I am new to Ruby and Vim. I hope you guys help
me out.
Ctrl-S ? This is not known to me. In Vim/Gvim, a file is usually saved by
:w filename.ext (if none's been given yet)
or
:saveas filename.ext
(for all of these commands try ":help :w" or ... the same principle).
I don't know about the comment part, since I don't do Ruby, but it would be pretty wise for you to get yourself a nice commenter plugin (I think I use LineCommenter) - eases up on the commenting. Just write the comment, and add the #'s later (set it to work in normal and in visual mode; it works beautifully).
As for the breaking the text part, that could be solved by adding
:set tw=80
"wrapscan" is the vim feature that wraps a whole word to the next line; it might not be set by default in your configuration - probably isn't. So in addition to
:set tw=78 you probably want to try one of these:
:set wrapscan
:set wrap <- just a shorter version
:set nowrap <- to turn the wordwrap feature back off
Incidentally, rather than setting the text width (tw) to some number of characters (smaller than your window), you could instead set the margin you want to leave on the right side of the window like so:
:set wrapmargin=1
If wrapmargin is set to something other than 0, textwidth should be ignored.
I would use ":w" to save and continue editing (or ":w filename" if it's a new file) and "ZZ" or ":wq" to save-and-exit when you're done - none of those will move the cursor position.
I'm not sure where your "#" continuation is coming from, but I'd also make sure to set these if they aren't already (you can check what variables are set by just typing ":set" with no other options):
:set syntax=ruby
:set filetype=ruby
:syntax enable
If you started with an empty document and then added "#!/usr/bin/ruby" to it, vim won't notice you're editing ruby until you save&exit and reopen the file. There are other cases where syntax coloring isn't very bright or needs a nudge but yes, that sounds like a bug to me.