├── LICENSE ├── README.md ├── plugin └── vim-prismo.vim └── resources └── screencapture.gif /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Guy Waldman 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prismo for Vim 2 | 3 | ![Screencapture](/resources/screencapture.gif?raw=true "Screencapture") 4 | 5 | Decorate section titles and separators in your code with ease using vim-prismo. This vim plugin centers your title beautifully and finally gives your OCD a well-deserved break. 6 | 7 | # Current state 8 | 9 | `vim-prismo` was originally designed for much more, but for right now I'm settling for beautifying my inline comments. It is inspired by my previous plugin for Atom, [AutoSect](https://github.com/guywald1/auto-sect). I am a _vim-script_ beginner and would be very open and excited for ideas and pull requests. 10 | 11 | # TODO 12 | 13 | - [ ] General improvements + proper documentation 14 | 15 | - [ ] Indentation-aware 16 | 17 | - [ ] Decoration pattern explicit declaration 18 | 19 | (meaning you would write: `// ~ title`, and it would expand to `// ~~~~ TITLE ~~~~` 20 | 21 | # Installation 22 | 23 | ## Pathogen 24 | 25 | ```bash 26 | $ cd ~/.vim/bundle 27 | $ git clone https://github.com/guywald1/vim-prismo/ 28 | ``` 29 | > Alternatively, `$ cd ~/.janus` if you're using [vim-janus](https://github.com/carlhuda/janus) like me (you totally should). 30 | 31 | ## Vundle 32 | 33 | Add... 34 | 35 | ```vim-script 36 | Plugin 'guywald1/vim-prismo' 37 | ``` 38 | 39 | ...between `call vundle#begin()` and `call vundle#end()` in your `.vimrc`. 40 | 41 | # Usage 42 | 43 | Type the beginning of your inline comment, followed by a space, followed by your desired title. i.e. `// your title here.` 44 | 45 | Call `:Prismo` and it will then become: `// ------------- YOUR TITLE HERE -------------` (but spanning 80 characters wide - this is only for demonstration purposes). 46 | 47 | > **Note**: The inline comment style does not have to be `//`. As long as it a continuous sequence of characters, any inline comment style will do. For example, for BASH: `# title` will transform to `# ------ TITLE ------`. 48 | 49 | The plugin will, by default, convert the title to uppercase. 50 | 51 | # Customization 52 | 53 | Recommended mapping: 54 | 55 | ```vim-script 56 | :nnoremap pr :Prismo 57 | ``` 58 | 59 | ## Settings 60 | 61 | These are all customizable inside of your `.vimrc`: 62 | 63 | ```vim-script 64 | let g:prismo_dash = '-' " the character to pad the title (dash by default) 65 | let g:prismo_ruler = 80 " the rightmost edge to span your title 66 | let g:prismo_toupper = 1 " whether to transform the title to uppercase 67 | ``` 68 | # Contributions 69 | 70 | ...are absolutely welcome! 😊 71 | -------------------------------------------------------------------------------- /plugin/vim-prismo.vim: -------------------------------------------------------------------------------- 1 | let g:prismo_dash = '-' " the character to pad the title (dash by default) 2 | let g:prismo_ruler = 80 " the rightmost edge to span your title 3 | let g:prismo_toupper = 1 " whether to transform the title to uppercase 4 | 5 | " inspired by: @https://vi.stackexchange.com/a/421 6 | function! s:center_aux(width, leading, word) 7 | let a:inserted_word = ' ' . a:word . ' ' 8 | let a:word_width = strlen(a:inserted_word) 9 | let a:leading_length = strlen(a:leading) 10 | let a:length_before = (a:width - a:leading_length - a:word_width) / 2 11 | let a:hashes_before = repeat(g:prismo_dash, a:length_before) 12 | let a:hashes_after = repeat(g:prismo_dash, a:width - a:leading_length - (a:word_width + a:length_before) - 1) 13 | let a:word_line = a:leading . a:hashes_before . a:inserted_word . a:hashes_after 14 | :put = a:word_line 15 | normal! kdd 16 | " uncomment next line to insert newline after title 17 | " :put = '' 18 | endfunction 19 | 20 | function! s:center() 21 | normal! ^viwy 22 | let a:leading = @0 . ' ' 23 | normal! ^f lvg_y 24 | if g:prismo_toupper 25 | let a:word = toupper (@0) 26 | else 27 | let a:word = @0 28 | endif 29 | call s:center_aux(g:prismo_ruler, a:leading, a:word) 30 | endfunction 31 | 32 | command! Prismo call s:center() 33 | -------------------------------------------------------------------------------- /resources/screencapture.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guywaldman/vim-prismo/7abd9dcd9d551fa0a0431ecd9dc67c6c8c36dbbf/resources/screencapture.gif --------------------------------------------------------------------------------