What is the meaning of semantic_escape_chars? - terminal

I believe I have done an extensive google for semantic_escape_chars, but i have failed to find what the meaning of that config is. When are semantic_escape_chars used?

The sample configuration says the semantic_escape_chars configuration option is used to specify a string of characters that are used to separate "semantic words". These are words that are seen as a single unit when you perform any actions on them, similar to the concept of words in vim.
This is used by the vi binding actions (SemanticLeft, SemanticRight, SemanticLeftEnd, etc.) which under allow the cursor to be moved semantically based on boundaries specified by semantic_escape_chars.
More concretely, in your alacritty.yml, if you have
selection:
semantic_escape_chars: " ,:;()[]{}"
key_bindings:
- { key: B, mode: Vi|~Search, action: SemanticLeft }
- { key: W, mode: Vi|~Search, action: SemanticRight }
And you enter vi mode (Ctrl+Shift+Space) with the following in your prompt
foo.png bar,baz
Assuming your cursor is at the first character, hitting "w" would take you to the beginning of the next semantic word, which would be the "b" in "bar".
If instead, you included an . in the semantic_escape_chars, pressing "w" would take you to the "o" at the end of "foo" since that is the end of the boundary for that semantic word as it is followed by the semantic escape character ..

Related

Custom line break in gedit 3.36.2

I'm looking for the option to set the line break at a specific point (e.g. after 75 characters). The option Text Wrapping allows only the line break when the text reaches the end of the screen.
For a cheap solution, you could try the following regex (Hotkey: Ctrl + H)
For tl;dr:
Find (.{75})\s
Replace with \1\n
and then "Replace All"
long version:
Explanation for Find: look for a space character after position 75 of any literal.
Explanation for Replace with: replace this space (i.e. matchgroup 1) with a newline character
For a more sophisticated approach, that means in order to split at a certain operand position and insert a hyphen, there is still room for improvement.
However, I hope this may serve you as a starting point ...
PS: Awh, don't forget to tick "Regular expression" and "Wrap around".

tmLanguage syntax highlighting with begin-end rules without highlighting a begin that doesn't have an end

I am creating a simple postfix programming language. The syntax is as follows:
2 3 add adds the two integers 2 and 3 together. "hello, world!" puts puts the string "hello, world!" to STDOUT.
The defining of new functions that can be used, is done as follows:
"fourth_pow"
"This function raises the argument on the top of the stack to the fourth power."
[
dup dup dup mul mul mul
]
def
Whitespace and newlines are not important in the language grammar. This means that above definition could also have been made as "fourth_pow" "..." [ dup dup dup mul mul mul] def (but of course, this is less readable).
I now want to highlight the syntax of this language, such that in a definition statement as above, the newly defined function name and the def keyword are highlighted.
A snippet from the .tmLanguage file (in YAML-format) is:
definition:
name: "entity.other.function.jux-beta_syntax"
begin: ("([a-zA-Z_][\w]*[?!]?)")
end: (def)
beginCaptures:
'1': {name: "entity.name.function.jux-beta_syntax"}
contentName: "support.constant.jux-beta_syntax"
patterns:
- include: '#comment'
- include: '#quotation_start'
- include: '#quotation_end'
- include: '#string'
- include: '#identifier'
- include: '#integer'
(See the whole file here)
This 'works', but it means that when at the end of the file, I start a new string, it is highlighted as if it would be a function definition. This because the 'begin' part of the #definition rule matches. But what I want to happen, is to only colour it if the match could be closed.
Is there a way to do so using the tmLanguage format?
The major problem is that, at least in Sublime Text (I haven't tested TextMate or VSCode), the regex engine can only match one line at a time using .tmLanguage files. Therefore, something like this:
(?m:("([a-zA-Z_][\w]*[?!]?)")(.*)(def))
using the ?m: multiline option (. matches newlines) won't work, although it works just fine in Ruby (the regex engine is based on Oniguruma). Because syntax highlighting only goes one line at a time, your beginCaptures matches as soon as a double-quoted string is entered. Of course, once the body of the function and def are written, everything highlights appropriately.
Unfortunately, I'm not fluent enough in it to give you a relevant working example, but you may want to check out the new sublime-syntax format in the most recent versions of Sublime Text 3. It functions using a stack, so you can push and pop contexts, allowing for matching on multiple lines. In the Selected Examples section, look at Bracket Balancing as an example - it highlights closing parentheses ) without a matching opening paren (.
Good luck!

Forward delete character?

To dynamically delete a character from a string, you can use the /b character.
puts "Hello\b World!" #=> Hell World!
\b basically does the same thing as a backspace. Is there a character that emulates a forward delete?
In the execution of:
puts "Hello\b World!"
The \b doesn't delete the prior character. This is a common misconception since a backspace used on a keyboard will delete the previously typed character prior to the cursor on screen and from the keyboard input buffer. That behavior occurs because of how the keyboard input software of the operating system is designed.
In the case of the above puts, the o still exists in the string. What happens is that, when displayed, the backspace causes the o to be overwritten by the following space. This occurs because the o is display first, followed by the backspace (output cursor is backed up one character position), followed by the space, in sequence.
If you could have such a case where:
puts "Hello<del> World!"
would display HelloWorld!, then that would mean the output of the value of <del> would somehow cause the following output of space () to not occur. In other words, the <del> would have the function of, "whatever the next charter is that comes for the output, skip it". I don't believe such a control character exists in Windows or Linux output, although I suppose it would be possible to write an output driver that would have that behavior for some defined control character.
You might even be able to do something like this:
"Hello W<left-arrow><left-arrow><del><right-arrow>orld!"
Which would display HelloWorld if your terminal is set up to accept control characters that move the cursor left or right. But it still obviously isn't the same functionality as the "delete in the future" case.

Visual Studio - How to replace text preserving case

Using the find and replace dialog in Visual Studio (2010) is it possible to replace some text but to preserve the case of the text being replaced.
ie. I want to change 'foo' to 'bar' but in my code I have Foo, foo and FOO. I want the replacement to be Bar, bar, BAR respectively.
Is it possible? I suspect I need to use the regular expression functionality but I need assistance in doing so.
EDIT: I know I can set the match case option, but all that option does is limit the replace to text matching the case of the search term. This is how I am doing it at the moment, but it is tiresome having to do three replacements - foo, Foo and FOO
It is - simply expand the Find Options area of the Find and Replace dialog and check the Match Case checkbox.
Full documentation on the dialog can be found here:
Match case - Only displays instances of the Find what string that are matched both by content and by case. For example, a search for "MyObject" with Match case selected will return "MyObject" but not "myobject" or "MYOBJECT."
Edit: (following clarification)
I don't know of an easy way to do what you want. A RegEx could possibly be constructed that does this, but I suspect that doing 3 search and replace would be faster, easier and less error prone than a RegEx, in this case.
I think if you use "match case" = true then you can replace "Foo" to "Bar" and "foo" to "bar"

How do you do block comments in YAML?

This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
How do I comment a block of lines in YAML?
YAML supports inline comments, but does not support block comments.
From Wikipedia:
Comments begin with the number sign ( # ), can start anywhere on a line, and continue until the end of the line
A comparison with JSON, also from Wikipedia:
The syntax differences are subtle and seldom arise in practice: JSON allows extended charactersets like UTF-32, YAML requires a space after separators like comma, equals, and colon while JSON does not, and some non-standard implementations of JSON extend the grammar to include Javascript's /* ... */ comments. Handling such edge cases may require light pre-processing of the JSON before parsing as in-line YAML.
# If you want to write
# a block-commented Haiku
# you'll need three pound signs
The specification only describes one way of marking comments:
An explicit comment is marked by a “#” indicator.
That's all. There aren't any block comments.
I am not trying to be smart about it, but if you use Sublime Text for your editor, the steps are:
Select the block
Cmd + / on Mac or Ctrl + / on Linux and Windows
Profit
I'd imagine that other editors have similar functionality too. Which one are you using? I'd be happy to do some digging.
In Vim you can do one of the following:
Comment all lines: :%s/^/#
Comment lines 10 - 15: :10,15s/^/#
Comment line 10 to current line: :10,.s/^/#
Comment line 10 to end: :10,$s/^/#
or using visual block:
Select a multiple-line column after entering visual block via Ctrl+v.
Press r followed by # to comment out the multiple-line block replacing the selection, or Shift+i#Esc to insert comment characters before the selection.
An alternative approach:
If
your YAML structure has well defined fields to be used by your app
AND you may freely add additional fields that won't mess up with your app
then
at any level you may add a new block text field named like "Description" or "Comment" or "Notes" or whatever
Example:
Instead of
# This comment
# is too long
use
Description: >
This comment
is too long
or
Comment: >
This comment is also too long
and newlines survive from parsing!
More advantages:
If the comments become large and complex and have a repeating pattern, you may promote them from plain text blocks to objects
Your app may -in the future- read or update those comments
One way to block commenting in YAML is by using a text editor like Notepad++ to add a # (comment) tag to multiple lines at once.
In Notepad++ you can do that using the "Block Comment" right-click option for selected text.
Emacs has comment-dwim (Do What I Mean) - just select the block and do a:
M-;
It's a toggle - use it to comment AND uncomment blocks.
If you don't have yaml-mode installed you will need to tell Emacs to use the hash character (#).
If you are using Eclipse with the YEdit plugin (an editor for .yaml files), you can comment-out multiple lines by:
selecting lines to be commented, and then
Ctrl + Shift + C
And to uncomment, follow the same steps.
For RubyMine users on Windows:
Open the file in the editor.
Select the block and press:
Ctrl + /,
And you will have the selected block starting with #.
Now if you want to uncomment the commented block, press the same key combination Ctrl + forward slash again.
In the Azure DevOps browser (pipeline YAML editor),
Ctrl + K + C Comment Block
Ctrl + K + U Uncomment Block
There also a 'Toggle Block Comment' option, but this did not work for me.
There are other 'weird' ways too: Right-click to see 'Command Palette' or F1
Then choose a cursor option.
Now it is just a matter of #.
Or even smarter [Ctrl + K] + [Ctrl + C]
In a .gitlab-ci.yml file, the following works:
To comment out a block (multiline): Select the whole block section >
Ctrl K C
To uncomment already commented out block (multiline): Select the
whole block section > Ctrl K U

Resources