Does Ruby have block comments?
If not, is there an efficient way of inserting # in front of a block of highlighted code in TextMate?
You can do
=begin
[Multi line comment]
=end
=begin and =end must be at the beginning of the line (not indented at all).
Source
Also, in TextMate you can press Command + / to toggle regular comments on a highlighted block of code.
Source
Ruby has documentation comments - they look like this:
=begin
...
=end
Not perfect but they get the job done in a pinch.
[Edit] It is important to note that =begin and =end must be at the beginning of their respective lines.
In TextMate, you can alt-drag vertically to select a column of text. This will duplicate the insertion point across all the lines you select, so you can insert or delete multiple #s at once.
UPDATE: Also in TextMate, assuming you have the right language selected, Cmd + / will toggle commenting every line in a selection regardless of language.
In TextMate 2 you can ⌘/ to comment out the current line or selected lines.
Related
I used custom renderer to display a Label as RichTextBlock. Using Paragraph, there is a TextIndentProperty to indent first line. However, I also need "Hanging Indentation" found in RichEditBox or SetIndent found in ITextParagraphFormat.
Is there a way to implemnent "Hanging Indentation" in RichTextBlock?
I have found the solution to this question.
Use left-padding to shift the entire paragraph in (say 10px)
Then, use text-indent with negative value to shift the first line of the paragraph out again (say -10px).
With this method, a hanging indentation can be achieved.
I found some instructions on how to show/hide differences in comments using beyond compare. However most of the answers show how to set comment as important text or not. That is, if a portion of code is commented on both sides then check if the comment are different or not.
I would like to ignore when only one side of the comparison is commented. In other words if I have
# # line1
# line2
on one side and
# line1
line2
I would like both lines to be marked as "unimportant differences" (if indeed the text is the same, otherwise to be marked as differences).
Beyond Compare will only compare text if it is of the same grammar element type. If one side is regular code and the other side is a comment, it will always mark it as an important difference.
To make regular text on one side and the same text commented on the other side show as a match, you'll need to edit the definition of a comment in the file format.
To edit a format, open Tools > File Formats.
Select the format that matches your files.
Go to the Grammar tab.
Select the Comment grammar element, which might be defined as # to end of line.
Click the Edit (gear) button.
Set the Category radio button to Basic.
Text matching: ^#\s
Check Regular expression.
Click OK, then Save.
The updated file format will treat # followed by a whitespace character as an unimportant comment, the remaining text in the line will be treated as regular text and compared to the other side.
I am parsing a csv file and the file has "\t" characters after every column. Why is it that when I print out the individual lines in terminal or open the file in my text editor that the tab spacing between each of the columns is different?
When you use tab, you're essentially moving to the next tab location, not moving over a specific distance. To see the difference, try using 4 spaces instead of tab. Or, alternatively, run the following code, and I think it may become clear to you.
puts "Hel\tlo world!"
puts "H\tello world!"
puts "Hell\to world!"
Hope that helps.
Do you mean something like
1 1
12345678 1
as a result of
puts "1\t1"
puts "12345678\t1"
A tab jumps to the next position in 8-space steps (8 spaces is a common distance, but it depends on settings of your editor. For ruby often is 2-space distance is used).
If the previous text is longer then 8 characters, then you jump to the next position and you have the impression of different tab spacing.
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.
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.