找出 vim 中特定关键字/符号属于哪个突出显示组

发布于 2024-08-05 03:27:57 字数 356 浏览 6 评论 0原文

我从 TextMate 转到 Vim,我想自定义我的 vim 颜色方案。如果我能找出任何特定单词或符号属于哪个突出显示组,那将非常有帮助。在 TextMate 中,我会将插入符号放在有问题的单词/符号上,然后按 ctrl-shift-p,然后会出现一个工具提示,内容如下:

text.html.basic
meta.tag.structure.any.html
string.quoted.double.html

根据此信息,编辑要应用的 TextMate 颜色主题非常简单(或删除)格式化相关文本。

在 Vim 中,如果我想更改某个单词或符号的格式,我不知道从哪里开始。有没有相当于 TextMate 的 ctrl-shift-p 的东西?

I am coming to Vim from TextMate, and I would like to customise my vim colorscheme. It would be really helpful if I could find out to which highlight-group(s) any particular word or symbol belongs. In TextMate, I would place the caret on the word/symbol in question, then hit ctrl-shift-p and a tool tip would appear saying something like:

text.html.basic
meta.tag.structure.any.html
string.quoted.double.html

From this information, it is really straightforward to edit a TextMate color theme to apply (or remove) formatting to the text in question.

In Vim, if I want to change formatting for a certain word or symbol, I'm not sure where to start. Is there anything equivalent to TextMate's ctrl-shift-p?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黄昏下泛黄的笔记 2024-08-12 03:27:57

我不确定我理解是否正确,但是您在寻找这个吗?

" adds to statusline
set laststatus=2
set statusline+=%{synIDattr(synID(line('.'),col('.'),1),'name')}

" a little more informative version of the above
nmap <Leader>sI :call <SID>SynStack()<CR>

function! <SID>SynStack()
    if !exists("*synstack")
        return
    endif
    echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc

I'm not sure I understood right, but are you looking for this ?

" adds to statusline
set laststatus=2
set statusline+=%{synIDattr(synID(line('.'),col('.'),1),'name')}

" a little more informative version of the above
nmap <Leader>sI :call <SID>SynStack()<CR>

function! <SID>SynStack()
    if !exists("*synstack")
        return
    endif
    echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
似最初 2024-08-12 03:27:57

获取有关突出显示的大量信息的另一种方法:

map <F3> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#")<CR>

如果我将鼠标移动到 C 文件中的注释上并按 F3,我会得到:

hi<cCommentStart> trans<cCommentStart> lo<Comment> FG:#00ff00

这表明它位于突出显示组 cCommentStart,链接到 Comment 并以绿色显示 (#00ff00)。这是(修改)自此处,请参阅该页面以获取更多信息。

Another way to get lots of information about the highlighting:

map <F3> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#")<CR>

If I move over a comment in a C file and press F3, I get:

hi<cCommentStart> trans<cCommentStart> lo<Comment> FG:#00ff00

which shows that it is in the highlight group cCommentStart, which is linked to Comment and coloured in green (#00ff00). This is (modified) from here, see that page for more information.

£噩梦荏苒 2024-08-12 03:27:57

更新:来自 :help synID() (参见示例):

synID({line}, {col}, {trans})                           *synID()*
                The result is a Number, which is the syntax ID at the position
                {line} and {col} in the current window.
                The syntax ID can be used with |synIDattr()| and
                |synIDtrans()| to obtain syntax information about text.
                {col} is 1 for the leftmost column, {line} is 1 for the first
                line.
                When {trans} is non-zero, transparent items are reduced to the
                item that they reveal.  This is useful when wanting to know
                the effective color.  When {trans} is zero, the transparent
                item is returned.  This is useful when wanting to know which
                syntax item is effective (e.g. inside parens).
                Warning: This function can be very slow.  Best speed is
                obtained by going through the file in forward direction.

                Example (echoes the name of the syntax item under the cursor):  
                        :echo synIDattr(synID(line("."), col("."), 1), "name")

据我所知,您能做的最好的是 :syntax,这将为您提供当前文件加载的所有语法的列表。我不知道有什么可以给出当前缓冲区的语法解析。

请注意,:syntax只是定义了语法项,它使用了:highlight 命令为语法项提供颜色。

一旦您决定要进行哪些更改,请将它们放入 ~/.vim/after/syntax/.vim 中。这些将在加载默认语法文件后应用您的更改。

UPDATE: From :help synID() (see the example):

synID({line}, {col}, {trans})                           *synID()*
                The result is a Number, which is the syntax ID at the position
                {line} and {col} in the current window.
                The syntax ID can be used with |synIDattr()| and
                |synIDtrans()| to obtain syntax information about text.
                {col} is 1 for the leftmost column, {line} is 1 for the first
                line.
                When {trans} is non-zero, transparent items are reduced to the
                item that they reveal.  This is useful when wanting to know
                the effective color.  When {trans} is zero, the transparent
                item is returned.  This is useful when wanting to know which
                syntax item is effective (e.g. inside parens).
                Warning: This function can be very slow.  Best speed is
                obtained by going through the file in forward direction.

                Example (echoes the name of the syntax item under the cursor):  
                        :echo synIDattr(synID(line("."), col("."), 1), "name")

As far as I know, the best you can do is :syntax, which will give you a listing of all the syntax loaded for the current file. I don't know of anything that will give the syntatical parsing of the current buffer.

Note that :syntax just defines the syntax items, it's uses of the :highlight command that give the coloring for a syntax item.

Once you've decided what changes you want to make, put them in ~/.vim/after/syntax/<filetype>.vim. These will apply your changes after the default syntax files are loaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文