Created
October 7, 2014 08:16
-
-
Save phalkunz/270a63e885e3a5035ddd to your computer and use it in GitHub Desktop.
Vim command for displaying rule path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
" 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