├── .gitignore ├── .travis.yml ├── test ├── double_tab_test.vader ├── misc_test.vader ├── space_test.vader ├── tab_test.vader ├── prevent_expansion_test.vader ├── enter_test.vader ├── mid_enter_test.vader ├── semicolon_test.vader ├── fallback_test.vader ├── expansion_test.vader └── stylus_test.vader ├── LICENSE.md ├── Makefile ├── README.md ├── plugin └── hyperstyle.vim ├── python ├── indexer.py ├── reference.py ├── hyperstyle.py ├── test.py └── definitions.py ├── autoload └── hyperstyle.vim ├── HISTORY.md ├── doc └── hyperstyle.txt └── REFERENCE.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | vendor 3 | doc/hyperstyle.txt.new 4 | doc/tags 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: "python" 2 | python: [ "2.7" ] 3 | script: make test 4 | -------------------------------------------------------------------------------- /test/double_tab_test.vader: -------------------------------------------------------------------------------- 1 | Given css: 2 | Do (pressing tab twice): 3 | a dis\bl\ 4 | Expect (expands both the property and the value); 5 | display: block; 6 | -------------------------------------------------------------------------------- /test/misc_test.vader: -------------------------------------------------------------------------------- 1 | Given css: 2 | Do (m:a; dib;): 3 | a m:a; dib; 4 | Expect (multiple statements don't stack on the same line); 5 | margin: auto; dib; 6 | -------------------------------------------------------------------------------- /test/space_test.vader: -------------------------------------------------------------------------------- 1 | # Given css: 2 | # display: block; 3 | # 4 | # Execute: 5 | # set sts=2 sw=2 ex 6 | # 7 | # Do: 8 | # A cur\pointer 9 | # 10 | # Expect (expands after ;): 11 | # display: block; cursor: pointer 12 | -------------------------------------------------------------------------------- /test/tab_test.vader: -------------------------------------------------------------------------------- 1 | Given css (with a property shorthand); 2 | di 3 | Do (pressing tab): 4 | A\_ 5 | Expect (expands the property); 6 | display: _ 7 | 8 | Given css (with a statement shorthand); 9 | m0a 10 | Do (pressing tab): 11 | A\_ 12 | Expect (expands the statement); 13 | margin: 0 auto;_ 14 | 15 | -------------------------------------------------------------------------------- /test/prevent_expansion_test.vader: -------------------------------------------------------------------------------- 1 | Given css (with a :before selector); 2 | p:before 3 | Do (pressing enter): 4 | A\_ 5 | Expect (doesn't expand :before); 6 | p:before 7 | _ 8 | 9 | Given css (with a brace); 10 | cursor:w{ 11 | Execute: 12 | set sts=2 sw=2 ex 13 | Do (pressing enter): 14 | A\_ 15 | Expect (doesn't expand open braces); 16 | cursor:w{ 17 | _ 18 | -------------------------------------------------------------------------------- /test/enter_test.vader: -------------------------------------------------------------------------------- 1 | Given css (with a statement shorthand); 2 | dib 3 | Do (pressing enter): 4 | A\_ 5 | Expect (expands the statement); 6 | display: inline-block; 7 | _ 8 | 9 | Given css (db inside a block): 10 | a { 11 | db 12 | } 13 | Do (pressing enter): 14 | jA\_ 15 | Expect (expands the statement): 16 | a { 17 | display: block; 18 | _ 19 | } 20 | -------------------------------------------------------------------------------- /test/mid_enter_test.vader: -------------------------------------------------------------------------------- 1 | # In the line: 2 | # display: block;| color: blue; 3 | # In v0.5.0, you used to not be able to press to break them apart. 4 | 5 | Given css; 6 | display: block;color: blue; 7 | 8 | Execute: 9 | set sts=2 sw=2 ex 10 | 11 | Do: 12 | 0f;a\ 13 | 14 | Expect (keeps enter working in the middle of a line); 15 | display: block; 16 | color: blue; 17 | -------------------------------------------------------------------------------- /test/semicolon_test.vader: -------------------------------------------------------------------------------- 1 | Given css: 2 | Execute: 3 | set sw=2 sts=2 ex 4 | Do: 5 | a margin: 0 auto\_ 6 | Expect (automatic semicolon insertion); 7 | margin: 0 auto; 8 | _ 9 | 10 | Do: 11 | a background: linear-gradient(\\_ 12 | # Do `del` here to account for auto-pairs, just in case 13 | Expect (supress automatic semicolon insertion): 14 | background: linear-gradient( 15 | _ 16 | 17 | -------------------------------------------------------------------------------- /test/fallback_test.vader: -------------------------------------------------------------------------------- 1 | Given css (nothing in particular); 2 | 123 3 | Do (pressing enter): 4 | A\_ 5 | Expect (safely lets enter through); 6 | 123 7 | _ 8 | 9 | Given css (nothing in particular); 10 | 123 11 | Do (pressing enter): 12 | A\_ 13 | Expect (safely lets space through); 14 | 123 _ 15 | 16 | Given css (nothing in particular); 17 | xxxxxx 18 | Execute: 19 | set sts=2 sw=2 ex 20 | Do (pressing tab): 21 | A\_ 22 | Expect (safely lets tab through); 23 | xxxxxx _ 24 | -------------------------------------------------------------------------------- /test/expansion_test.vader: -------------------------------------------------------------------------------- 1 | Given css (di); 2 | di 3 | Do (pressing :): 4 | A:_ 5 | Expect (expands the property); 6 | display:_ 7 | 8 | Given css; 9 | margin: a 10 | Do (pressing ;): 11 | A; 12 | Expect (expands the value); 13 | margin: auto; 14 | 15 | Given css; 16 | margin:auto 17 | Do (pressing ;): 18 | A; 19 | Expect (inserts a space after : in the property); 20 | margin: auto; 21 | 22 | Given css; 23 | dib 24 | Do (pressing ;): 25 | A; 26 | Expect (expands a full statement); 27 | display: inline-block; 28 | 29 | Given css; 30 | brad4 31 | Do (pressing ;): 32 | A; 33 | Expect (expands numeric values); 34 | border-radius: 4px; 35 | -------------------------------------------------------------------------------- /test/stylus_test.vader: -------------------------------------------------------------------------------- 1 | # Tests indented syntaxes and stuff. 2 | 3 | Given sass: 4 | .div 5 | _ 6 | Do (dib;): 7 | Gxadib\_ 8 | Expect sass (display: inline-block): 9 | .div 10 | display: inline-block 11 | _ 12 | 13 | Given stylus: 14 | Execute: 15 | set sw=2 sts=2 ex 16 | Do: 17 | adiv\ di\_ 18 | Expect stylus (stylus: expands properties via tab); 19 | div 20 | display: _ 21 | 22 | Given stylus: 23 | Do: 24 | adiv\ moa\_ 25 | Expect (stylus: expands statements via tab); 26 | div 27 | margin: 0 auto_ 28 | 29 | Given stylus: 30 | Do: 31 | amoa\_ 32 | Expect (don't expand tabs when there's no indentation): 33 | moa _ 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Rico Sta. Cruz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | vim := vim 2 | plugins = ${HOME}/.vim/plugged 3 | redirect := >/dev/null 4 | 5 | test: test-python test-vim 6 | 7 | test-python: python/test.py 8 | @if which python >/dev/null; then python --version; python $<; fi 9 | @if which python3 >/dev/null; then python3 --version; python3 $<; fi 10 | 11 | autotest: 12 | find plugin test python | entr make test 13 | 14 | # Automated vim testing via vader.vim 15 | test-vim: vendor/vimrc 16 | @env HOME=$(shell pwd)/vendor ${vim} -Nu $< +"Vader! test/*" 17 | 18 | vim: vendor/vimrc 19 | @env HOME=$(shell pwd)/vendor ${vim} -Nu $< _test.css 20 | 21 | vendor/vimrc: vendor/vader.vim vendor/auto-pairs 22 | @mkdir -p ./vendor 23 | @echo "filetype off" > $@ 24 | @echo "set rtp+=vendor/vader.vim" >> $@ 25 | @echo "if has('\$$test_autopairs') | set rtp+=vendor/auto-pairs | endif" >> $@ 26 | @echo "set rtp+=." >> $@ 27 | @echo "filetype plugin indent on" >> $@ 28 | @echo "syntax enable" >> $@ 29 | 30 | vendor/vader.vim: 31 | @mkdir -p ./vendor 32 | @git clone https://github.com/junegunn/vader.vim.git ./vendor/vader.vim 33 | 34 | vendor/auto-pairs: 35 | @mkdir -p ./vendor 36 | @git clone https://github.com/jiangmiao/auto-pairs.git ./vendor/auto-pairs 37 | 38 | doc: REFERENCE.md doc/hyperstyle.txt 39 | 40 | REFERENCE.md: python/definitions.py 41 | python python/reference.py --md > $@ 42 | 43 | doc/hyperstyle.txt: python/definitions.py 44 | python python/reference.py --vim > $@ 45 | 46 | .PHONY: test vendor/vimrc doc 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-hyperstyle 2 | 3 | Type faster by shorthand that will auto-expand as you type. Supports less, sass, scss, stylus, and plain CSS. 4 | 5 | ![](https://raw.githubusercontent.com/rstacruz/vim-hyperstyle/gh-pages/screencast.gif?2) 6 | 7 | [![Status](https://travis-ci.org/rstacruz/vim-hyperstyle.svg?branch=master)](https://travis-ci.org/rstacruz/vim-hyperstyle) 8 | 9 |
10 | 11 | ## Expansions 12 | 13 | Expansions intelligently happen as you type. Unlike [emmet], there are no hotkeys required—expansion will happen as you type whenever they make sense. 14 | 15 | * Properties will be auto-completed:
`m:` → `margin:` 16 | 17 | * You can put numeric next to property shortcuts:
`z1⏎` → `z-index: 1;` 18 | 19 | * Values will be auto-completed:
`float:l` → `float: left` 20 | 21 | * Default units will be added:
`border-radius: 4⏎` → `border-radius: 4px;` 22 | 23 | * Shortcuts for common statements are available:
`fl⏎` → `float: left;` 24 | 25 | * Semicolons are inserted automatically so you can write CSS in one go:
`dib` `⏎` `m0a` `⏎` 26 | 27 | * Semicolons are omitted for `.styl` and `.sass` 28 | 29 | * ...and lots more goodies 30 | 31 |
32 | 33 | ## Examples 34 | 35 | | Shortcut | Expansion | 36 | | --- | --- | 37 | | `dib` | display: inline-block; | 38 | | `m0` | margin: 0; | 39 | | `m0a` | margin: 0 auto; | 40 | | `m-15` | margin: -15px; | 41 | | `m:auto` | margin: auto; | 42 | | `fle 1 auto` | flex: 1 auto; | 43 | | `float left` | float: left; | 44 | 45 | **[View full reference →](REFERENCE.md)** 46 | 47 |
48 | 49 | ## Installation 50 | 51 | Using [vim-plug]: 52 | 53 | ```vim 54 | Plug 'rstacruz/vim-hyperstyle' 55 | ``` 56 | 57 | Python support is required. For Neovim: 58 | 59 | :help nvim-python 60 | 61 | For OSX/Homebrew: ([info](http://ricostacruz.com/til/use-macvim-with-lua.html)) 62 | 63 | ``` 64 | brew install macvim --with-cscope --with-lua --override-system-vim \ 65 | --with-luajit --with-python3 --with-python 66 | ``` 67 | 68 |
69 | 70 | ## Options 71 | * To generate statements with no colons in Stylus, set `let g:hyperstyle_use_colon=0`. 72 | 73 | ## Caveats 74 | 75 | * Stylus is assumed to be in indented syntax (no braces). 76 | 77 |
78 | 79 | ## Thanks 80 | 81 | **vim-hyperstyle** © 2015+, Rico Sta. Cruz. Released under the [MIT] License.
82 | Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]). 83 | 84 | > [ricostacruz.com](http://ricostacruz.com)  ·  85 | > GitHub [@rstacruz](https://github.com/rstacruz)  ·  86 | > Twitter [@rstacruz](https://twitter.com/rstacruz) 87 | 88 | [MIT]: http://mit-license.org/ 89 | [contributors]: http://github.com/rstacruz/vim-hyperstyle/contributors 90 | [vim-plug]: https://github.com/junegunn/vim-plug 91 | [emmet]: http://emmet.io/ 92 | -------------------------------------------------------------------------------- /plugin/hyperstyle.vim: -------------------------------------------------------------------------------- 1 | " Typing `(hyperstyle-tab)` will trigger Hyperstyle. 2 | " These will be mapped to actual keystrokes later on. 3 | inoremap (hyperstyle-cr) =hyperstyle#expand_cr() 4 | imap