使用单个键击从Vim中的HTML文件跳转到css文件中的CSS选择器 [英] jump to CSS selector in a css file from the HTML file in Vim using a single keystroke

查看:333
本文介绍了使用单个键击从Vim中的HTML文件跳转到css文件中的CSS选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意:我已通过此链接跳转到在VIM中编辑HTML时的CSS定义,但它不能帮助我。

Please note: I have been through this link Jump to CSS definition when editing HTML in VIM, but it couldn't help me.

我想跳转到CSS定义,函数从html文件。我会喜欢在下面的一个关键组合跳到它的定义,而不只是定义所在的文件。

I am looking to jump to the CSS definition or for that matter a javascript function from the html file. I would love to hit a key combo below the word to jump to its definition, not just the file in which the definition resides.

我目前需要搜索的词打开缓冲区,然后到达所需缓冲区中的所有搜索结果。这是非常耗时。

I currently need to search the word in opened buffers and then reach to all the search results in the required buffer. It is very time consuming.

请帮助我这个非常规则的要求。

Please help me with this very regular requirement.

推荐答案

这个快速和脏的函数似乎为* .html - > * .css:

This quick and dirty function seems to do the trick for *.html -> *.css:

function! JumpToCSS()
  let id_pos = searchpos("id", "nb", line('.'))[1]
  let class_pos = searchpos("class", "nb", line('.'))[1]

  if class_pos > 0 || id_pos > 0
    if class_pos < id_pos
      execute ":vim '#".expand('<cword>')."' **/*.css"
    elseif class_pos > id_pos
      execute ":vim '.".expand('<cword>')."' **/*.css"
    endif
  endif
endfunction

nnoremap <F9> :call JumpToCSS()<CR>




  • test.html / p>

    • test.html

      <html>
        <body>
          <div class="foo" id="bar">lorem</div>
          <div id="bar" class="foo">ipsum</div>
          <div id="bar">dolor</div>
          <div class="foo">sit</div>
        </body>
      </html>
      


    • foo / foo.css
      $ b

    • foo/foo.css

      .foo {
        background-color: red;
      }
      


    • bar / bar.css / p>

    • bar/bar.css

      #bar {
        border-color: gold;
      }
      


    • test.html 中的任何 foo bar 属性值,击中< F9> 跳转到正确的文件中的正确定义。可以修改函数以在分割中打开目标文件,只搜索链接的样式表...或者被ZyX完全嘲讽和破坏; - )。

      With the cursor on any foo or bar attribute value in test.html, hitting <F9> jumps to the right definition in the right file. The function could be modified to open the target file in a split, search only the linked stylesheets… or be completely ridiculed and destroyed by ZyX ;-).

      编辑

      edit

      一些额外的指针:


      • :help iskeyword 为此函数使用dash-joined名称

      • :help expand ()

      • :help searchpos() $> $ > ** 通配符

      • :help iskeyword for this function to work with dash-joined names
      • :help expand()
      • :help searchpos() and :help search() for the meanings of the arguments
      • :help starstar for the use of the ** wildcard

      这篇关于使用单个键击从Vim中的HTML文件跳转到css文件中的CSS选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆