├── README.md └── plugin └── csscomb.vim /README.md: -------------------------------------------------------------------------------- 1 | # CSScomb plugin for Vim 2 | 3 | ## About 4 | Plugin based on CSScomb algorithm. 5 | 6 | The algorithm of CSScomb simulates web-technologists actions upon working with CSS-code to the limit. Usually to re-order code you move lines over each other considering comments in the code, multilines records of property values, hacks and everything that could be found in the real file. CSScomb reproduces these actions for you. This means that the parser "thinks" as a person editing the text, not as a blind robot parsing CSS. 7 | 8 | For more info, online demo and tests see [csscomb.com](http://csscomb.com/) 9 | 10 | 11 | ## The Requirements 12 | 13 | CSScomb is written in pure JavaScript. Install with: 14 | 15 | ```BASH 16 | npm install -g csscomb 17 | ``` 18 | 19 | ## Installation 20 | 21 | ### With Pathogen 22 | 23 | ``` 24 | cd ~/.vim/bundle 25 | git clone https://github.com/csscomb/vim-csscomb.git 26 | ``` 27 | 28 | ### With Vundle 29 | Add this to .vimrc: 30 | ``` 31 | Bundle 'git://github.com/csscomb/vim-csscomb.git' 32 | ``` 33 | 34 | ### With NeoBundle 35 | Add this to .vimrc: 36 | ``` 37 | NeoBundle 'csscomb/vim-csscomb' 38 | ``` 39 | 40 | ### Manual without plugins manager 41 | ``` 42 | git clone https://github.com/csscomb/vim-csscomb.git csscomb 43 | cp -r csscomb/plugin/* ~/.vim/plugin/ 44 | ``` 45 | 46 | ## Usage 47 | Vim command: 48 | ``` 49 | :CSScomb 50 | ``` 51 | 52 | ## Suggested Configuration 53 | 54 | ```VIML 55 | " Map bc to run CSScomb. bc stands for beautify css 56 | autocmd FileType css noremap bc :CSScomb 57 | " Automatically comb your CSS on save 58 | autocmd BufWritePre,FileWritePre *.css,*.less,*.scss,*.sass silent! :CSScomb 59 | ``` 60 | -------------------------------------------------------------------------------- /plugin/csscomb.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File: csscomb.vim 3 | " Author: Aleksandr Batsuev (alex@batsuev.com) 4 | " WebPage: https://github.com/batsuev/csscomb-vim 5 | " License: MIT 6 | 7 | let g:CSScombPluginDir = fnamemodify(expand(""), ":h") 8 | 9 | function! g:CSScomb(count, line1, line2) 10 | let content = getline(a:line1, a:line2) 11 | 12 | let tempFile = tempname() . '.' . &filetype 13 | call writefile(content, tempFile) 14 | let systemOutput = system('csscomb ' . shellescape(tempFile)) 15 | if len(systemOutput) 16 | echoerr split(systemOutput, "\n")[1] 17 | else 18 | let lines = readfile(tempFile) 19 | call setline(a:line1, lines) 20 | endif 21 | endfunction 22 | 23 | command! -nargs=? -range=% CSScomb :call g:CSScomb(, , , ) 24 | --------------------------------------------------------------------------------