Skip to content

Instantly share code, notes, and snippets.

@sigwyg
Forked from edom18/css3-property-duplicate
Created February 24, 2012 14:13
Show Gist options
  • Save sigwyg/1901182 to your computer and use it in GitHub Desktop.
Save sigwyg/1901182 to your computer and use it in GitHub Desktop.
CSSのプロパティを、ベンダープレフィクス付きで複製するスクリプト。(インデントも引き継ぐよう修正+直前のレジスタを保持)
" -----------------------------------------------------------------------
" CSS3PropertyDuplicate(): {{{
" - Origin: https://gist.github.com/972806
" - Forked: https://gist.github.com/1901182
"
" "" -> 無名レジスタ(YなどでYankしたテキストが入る)
" @" -> 無名レジスタの内容を実行する
" @@ -> 直前に実行したレジスタを再実行する
" ""P -> 無名レジスタの内容をペースト
"
" ":let" を使うとレジスタに書き込むことができる
"'clipboard'オプションに"unnamed"文字列が含まれているときには、無名レジスタは"* レジスタと同じ。
function! CSS3PropertyDuplicate()
if &clipboard ==# 'unnamed'
let l:save_reg = @*
else
let l:save_reg = @"
endif
silent normal Y
let l:css3 = @"
let l:ind = matchlist(css3, '\v(\s*)(.*)')
let l:webkit = ind[1] . "-webkit-" . ind[2]
let l:moz = ind[1] . "-moz-" . ind[2]
let l:ms = ind[1] . "-ms-" . ind[2]
let l:o = ind[1] . "-o-" . ind[2]
let @" = webkit . moz . ms . o
normal ""P
if &clipboard ==# 'unnamed'
let @* = save_reg
else
let @" = save_reg
endif
endfunction
nnoremap ,3 :<C-u>call CSS3PropertyDuplicate()<CR>
" }}}
" -----------------------------------------------------------------------
" CSS3PropertyDuplicate(): {{{
" - Origin: https://gist.github.com/972806
" - Forked: https://gist.github.com/1901182
"
" * レジスタ使わないバージョン
"
function! CSS3PropertyDuplicate()
let l:css3 = getline(".")
let l:line = line(".")
let l:ind = matchlist(css3, '\v(\s*)(.*)')
let l:webkit = ind[1] . "-webkit-" . ind[2]
let l:moz = ind[1] . "-moz-" . ind[2]
let l:ms = ind[1] . "-ms-" . ind[2]
let l:o = ind[1] . "-o-" . ind[2]
call append(line -1, [webkit, moz, ms, o])
call cursor(line, 1)
endfunction
nnoremap <silent> ,3 :<C-u>call CSS3PropertyDuplicate()<CR>
" }}}
@sigwyg
Copy link
Author

sigwyg commented Feb 24, 2012

だいたい理解したのでアレンジしてみた

set clipboard = unnamed な環境に対応。
Yankring環境だとlet @" = hogehoge がダメ(なこともある)。適当なレジスタに変えてみると動く。

@sigwyg
Copy link
Author

sigwyg commented Feb 24, 2012

レジスタ使わないVer.を追加。これならたぶん、環境依存ないと思う

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment