-
-
Save sigwyg/1901182 to your computer and use it in GitHub Desktop.
CSSのプロパティを、ベンダープレフィクス付きで複製するスクリプト。(インデントも引き継ぐよう修正+直前のレジスタを保持)
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
" ----------------------------------------------------------------------- | |
" 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> | |
" }}} |
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
" ----------------------------------------------------------------------- | |
" 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> | |
" }}} |
レジスタ使わないVer.を追加。これならたぶん、環境依存ないと思う
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
だいたい理解したのでアレンジしてみた
set clipboard = unnamed な環境に対応。
Yankring環境だとlet @" = hogehoge がダメ(なこともある)。適当なレジスタに変えてみると動く。