Created
February 15, 2013 17:05
-
-
Save tacahiroy/4961768 to your computer and use it in GitHub Desktop.
Chef's attribute notation converter
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
let s:chef = {} | |
function! s:chef.convert_attr_notation() abort | |
if !search('\>', 'bcnW') | |
return | |
endif | |
let [bufnbr, lnum, col, offset] = getpos('.') | |
let line = getline(lnum) | |
if match(line, '\.') == -1 | |
return | |
endif | |
let sc = self.find_attr_pos() | |
let ec = col | |
let l = matchstr(line, printf('.*\%%<%dc', sc)) | |
let r = matchstr(line, printf('\%%>%dc.*', ec)) | |
let attrs = split(matchstr(line, printf('\%%%dc.\+\%%%dc', sc - 1, ec + 1)), '\.') | |
let attr = attrs[0] . join(map(attrs[1:], '"[:".v:val."]"'), '') | |
call setline(lnum, l . attr . r) | |
call setpos('.', [bufnbr, lnum, len(l . attr) + 1, 0]) | |
execute 'startinsert' | |
endfunction | |
function! s:chef.find_attr_pos() | |
let pos = searchpos('\(^\|\s\)', 'bnW') | |
return pos[1] + 1 | |
endfunction | |
command! ChefConvertAttrNotation call s:chef.convert_attr_notation() | |
inoremap <silent> <C-y>x <C-g>u<Esc>:ChefConvertAttrNotation<Cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment