Last active
August 29, 2015 14:00
-
-
Save moyashipan/11177018 to your computer and use it in GitHub Desktop.
PwdYaml
This file contains hidden or 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
" .vim/autoload/yml.vim | |
function! yml#search(pos) | |
let indent = indent(a:pos) | |
let keys = [s:get_key(getline(a:pos))] | |
for n in range(line(a:pos), 1, -1) | |
if indent(n) == (indent - &tabstop) | |
call insert(keys, s:get_key(getline(n))) | |
let indent = indent - &tabstop | |
endif | |
endfor | |
echo join(keys, '/') | |
endfunction | |
function! yml#jump(path) range | |
let indent = 0 | |
let min_line = 1 | |
let max_line = line("$") | |
for key in split(a:path, '/') | |
call cursor(min_line, 0) | |
let space = repeat(" ", indent) | |
call search('^' . space . key . ':', 'W', max_line) | |
let min_line = line('.') | |
call search('^' . space . '[^ ]\+:', 'W', max_line) | |
if line('.') != min_line | |
let max_line = line('.') | |
endif | |
let indent = indent + &tabstop | |
endfor | |
endfunction | |
function! s:get_key(line_str) | |
let space_with_key = matchstr(a:line_str, '^[^:]\+') | |
return substitute(space_with_key, '[ :]*', '', 'g') | |
endfunction | |
" .vim/ftplugin/yaml.vim | |
command! -nargs=0 YamlPwd call yml#search('.') | |
command! -nargs=1 YamlJump call yml#jump(<f-args>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
そのままでもいい感じですね!