Skip to content

Instantly share code, notes, and snippets.

@phalkunz
Created October 7, 2014 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phalkunz/270a63e885e3a5035ddd to your computer and use it in GitHub Desktop.
Save phalkunz/270a63e885e3a5035ddd to your computer and use it in GitHub Desktop.
Vim command for displaying rule path
"""
" USAGE:
"
" 1. Place the cursor in the rule that you want to look up
" 2. :SCSSShowRulePath
"""
command! ScssShowRulePath :call ScssRulePath()
function! ScssRulePath()
let start_line_num = 0
let curr_line_num = line(".")
let last_line_num = line("$")
let running_line_num = start_line_num
let path_parts = []
while running_line_num < last_line_num
let line_content = getline(running_line_num)
if(match(getline(running_line_num), "{") > -1)
let line_content = substitute(line_content, "{", "", "")
let line_content = Trim(line_content)
call add(path_parts, line_content)
endif
if(running_line_num == curr_line_num)
break
endif
if(match(getline(running_line_num), "}") > -1)
if(len(path_parts) > 0)
call remove(path_parts, len(path_parts) - 1)
endif
endif
let running_line_num = running_line_num + 1
endwhile
echo join(path_parts, " ▶ ")
endfunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment