How display actual syntax highlight in vim? - vim

Recently I wrote a text file without a file extension with the vim text editor and got text highlightning for all words between singel quotes like 'word' and all words ending with a colon like word:
I like this kind of highlightning.
But because I havent typed any command, which usually starts with ESC :command, I was surprised how this could happen.
Is there a command to display the actual syntax highlight which is in use?
I already have tried the command :set syntax=php which seems simliar only with different color for words like word:
Does anyone have suggestions?

Try entering the command
:echo &syntax
This will display the value that the syntax variable has been set to.

set option=value "set the option with value
set option? "read/print the current value of the option
set option! "set the option with opposite value, like set nu and set nu!
the option value is also saved in variable &option so you can read in script way.

Related

Vim errorformat string to show message in QuickFix removing part of it

I'm writing an errorformat string, and it works for the most part. My problem is that I have lines like this as the makeprg output:
Some text I want to show in the QuickFix window^M
Yes, the line ends with an spurious ^M character I want to remove. So, what I want in my QuickFix window is this, without the ^M character:
|| Some text I want to show in the QuickFix window
but I have this instead:
|| Some text I want to show in the QuickFix window^M
So far, this is the relevant part of my errorformat:
set errorformat=%+GSome text%m
I've tested, without success, something like this:
set errorformat=%+GSome text%m%-G^M%.%#
but it throws an error (not from the ^M which is a literal control-M char, not a caret followed by an M).
Obviously the solution is not using %G but I am at a loss here.
How can I remove the line ending character from the line here? And also, removing the initial || would be a plus, but I think it's impossible to do in Vim.
Thanks in advance!
Edited to make clearer how the input text looks
Well, turns out I found a solution, probably not very good but it works, using trial and error.
set errorformat=%\\(Some Text%*[^.]).%\\)%\\#=%m
That is, the solution is using the Vim pattern (regex) expressions within errorformat, which has a quite arcane look but works, together with %* to match unknown text on the rest of the line
The solution uses \#=, a zero-width match, and requires some kind of terminator for the line, which appears before the ^M character I want to ignore, and some kind of text appearing somewhere on the line to match that line and not others.
Probably there is a much better solution but this is the best I could do myself.

vim: how to let vim use apostrophe as start of a string

I am working on a sql file with some m4 macro embedded. Since m4 uses apostrophe to mark the start of string literals, it breaks the string highlighting of the file totally. Like
m4_include(`SQLCommon.m4')
I am wondering whether there is any option we can let vim to pair apostrophe with a single quotation mark. I searched on-line but didn't find any answer.
Thanks!
You're going to want to override vim's normal syntax highlighting for sqlString.
I was able to get the behavior I think you're looking for with just this:
:syntax region m4String start=/`/ end=/'/
To achieve nesting, we have to tell vim that a m4 string can contain more of the same:
:syntax region m4String start=/`/ end=/'/ contains=m4String extend
If you'd like to color those strings separately instead of just disrupting the normal highlighting you can separately link to the String highlight group.
:hi link m4String String
I wasn't entirely sure what you were looking for though; if the backtick-apostrophe delimited strings are inside of the normal SQL strings this won't work.

how to get the digraph key or unicode from a special character

I am configuring tmux & powerline. I would like to change the default separators in tmux status line. I managed to figure out where to do it, however I could not get the special character that I want.
I want to type, in Vim, a left/right pointing triangle that spans the whole line-height, but the only thing I could find is a small triangle (unicode : 25B6,25BA,25C0,25C4...)
There is a big right pointing triangle already in a powerline configuration file, which I could copy and paste, but I want to know its unicode and want a left one. Is there a way to get the unicode from the symbol in Vim or anywhere else?
You can get the codepoint value of a character in Vim by positioning the cursor on the character in question and typing either ga or :ascii.
You can either use ga in command mode or :ascii on the command line (even though it says ascii, it shows information for general encodings)
You may add a permanent preview of current character in your status line (see :h statusline), eg.:
:let &statusline = &statusline . "\ [%03b\ 0x%B]"

How to color a diff quoted by Mutt in Vim?

What is the best way to color diff, quoted in Mutt, using Vim?
If I receive a diff as attachment, I want to comment some lines, but while replying mutt adds the quotation mark (>) which is fine for me, but then it breaks the diff coloration in Vim.
How to add to the current diff pattern to match even with the first > chars? (It would be better to match more ^[> ] patterns)
Example of diff quoted message:
> ## -52,22 +48,17 ##
> -msgid "foo is deprecated."
> +msgid "bar is deprecated."
I'd start by writing a custom syntax file, say ~/.vim/syntax/muttdiff.vim:
syn match quote "^>* "
syn match quotedDeletion "^>* *-.*" contains=quote
syn match quotedAddition "^>* *+.*" contains=quote
hi quotedDeletion ctermfg=red
hi quotedAddition ctermfg=green
hi quote ctermfg=white
And make vim source the file if it is editing a mutt message.
It's a good start if you want to learn how to create a custom syntax file for vim.
I would suggest to set the indent_string from it's default value ("> ") to an empty string using a macro.
Example with a key ",r" bound:
macro index ,r ":set indent_string=\"\"<enter><reply>"
You would need to set it back to default after the command. So something like:
macro index ,r ":set indent_string=\"\"<enter><reply>:set indent_string=\"> \"<enter>"
(Take care those are not tested - just guessing the syntax here.)
But there is another issue - vim usually opens in the fileformat set to "mail" or something like that. You would need to set it to "diff" explicitely. So in Vim you need to:
:set filetype=diff
:syntax on
Maybe another macro or something like that. I know this is not ideal, but it's something at least ;-) Good luck.

Is there a way to paste the output of a vim command into the buffer?

Something that I want to do from time to time is paste the output of a vim command into the buffer. E.g. when I'm editing my vimrc, it'd be nice to be able to fiddle with statusline and then be able to just do something akin to
"=set statusline?<Enter>p
Problem is, that yields
E121: Undefined variable: set
E15: Invalid expression: set statusline?
Press ENTER or type command to continue
I figure that this is possible, and that I just don't know enough about the builtin functions and how to use them (I see expand used here and there, but have never successfully made it work for me in any context), even though I (think that I) have a pretty solid understanding of normal mode.
Note that this specific example is a little contrived, but I can't think of a better one right now. For the specific use case above, I could just ":p to get the whole set command that I used during experimentation and then edit to suit, but fairly regularly I run into other cases where I want vim to tell me something and then I want to paste that output somewhere so that I can continue to look at it while continuing with my work.
You can paste an option setting:
"=&statusline<Enter>p
I don't know of any way to put the output of an arbitrary command in the buffer, however.
The values of settings are stored in variables that are prepended with an & symbol. So the value that statusline is set to can be accessed by referencing &statusline. To insert into a document one way is to use the "expression" register, <ctrl-R>=. To use it enter insert mode and press <ctrl-R> and then =. You will see an equals sign in the command line, where you can enter: &statusline and then press enter. This will insert the value into the buffer.

Resources