├── LICENSE ├── README.md ├── autoload └── inyoface.vim ├── plugin └── inyoface.vim └── test └── test_matches.vader /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 TJ DeVries 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 | # vim-inyoface 2 | Comments that are in your face! 3 | 4 | **I** ntense 5 | **N** egative 6 | **Y** ousage 7 | **O** f 8 | **F** airly 9 | **A** lternate 10 | **C** omment 11 | **E** mphasis 12 | 13 | ## Example 14 | 15 | ![Example Usage](https://share.esdf.io/JKep1fRJbK/toggle.gif) 16 | 17 | ## Usage 18 | 19 | You can make a mapping like: 20 | 21 | ```vim 22 | nmap c (InYoFace_Toggle) 23 | ``` 24 | 25 | ### Credits 26 | 27 | Thanks to @tweekmonster for basically writing the whole thing. He just didn't want those sweet github stars like I do. 28 | -------------------------------------------------------------------------------- /autoload/inyoface.vim: -------------------------------------------------------------------------------- 1 | let s:brightness_changed = get(s:, 'brightness_changed', 0) " Current amount of brightness changed 2 | let s:brightness_diff = get(s:, 'brightness_diff', 0) " Brightness difference per change 3 | let s:brightness_diff = 5 4 | 5 | function! s:change_the_brightness(change) abort 6 | if !exists('g:colorpal_palette') 7 | return 8 | endif 9 | 10 | if a:change ==? 'dark' 11 | let l:modifier = 'dark' 12 | let l:changer = -1 13 | elseif a:change ==? 'bright' 14 | let l:modifier = 'bright' 15 | let l:changer = 1 16 | endif 17 | 18 | " If brightness diff is 5, then you want five modifiers there. 19 | let l:modifier = repeat(l:modifier . ',', s:brightness_diff) 20 | 21 | " TODO: Figure out how to better track what brightness we are at 22 | " I seem to be getting slightly different results at the end of this 23 | 24 | " while s:brightness_changed != 0 25 | execute 'CPHL Comment Comment,' . l:modifier . ' - -' 26 | let s:brightness_changed += l:changer 27 | " endwhile 28 | 29 | endfunction 30 | 31 | function! inyoface#set_brightness_diff(num) abort 32 | let s:brightness_diff = a:num 33 | endfunction 34 | 35 | function! inyoface#get_search_string(comment_string) abort 36 | try 37 | let l:comment_str = split(escape(a:comment_string, '^$.*/"'''), '%s')[0] 38 | catch 39 | " Don't try and do anything if we can't get the comment string 40 | return 41 | endtry 42 | 43 | return '^\%(\s*' . l:comment_str . '\)\@!.*' 44 | endfunction 45 | 46 | " function! inyoface#get_complete_search_string(comment_string) abort 47 | " sO:" -,mO:" ,eO:"",:" 48 | " endfunction 49 | 50 | function! inyoface#toggle_comments() abort 51 | if exists('w:toggle_comments') 52 | " If you've got colorpal, let's do some cool Comment helping 53 | call s:change_the_brightness('dark') 54 | 55 | silent! call matchdelete(w:toggle_comments) 56 | unlet! w:toggle_comments 57 | else 58 | " If you've got colorpal, let's do some cool Comment helping 59 | call s:change_the_brightness('bright') 60 | 61 | let w:toggle_comments = matchadd('NonComment', inyoface#get_search_string(&commentstring)) 62 | 63 | " Testing 64 | " let w:toggle_comments = matchadd('NonComment', '^\%(\s*' . l:comment_str . '\)\@![^' . l:comment_str . ']*') 65 | " let g:split_comment = split(escape(&commentstring, '^$.*/"'''), '%s')[0] 66 | " execute '/^\%(\s*' . g:split_comment . '\)\@!.*\ze\%[' . g:split_comment . ']' 67 | " execute '/^\%(\s*' . g:split_comment . '\)\@!.*\ze' . g:split_comment 68 | " execute '/^\%(\s*' . g:split_comment . '\)\@!.*\(' . g:split_comment . '\)\@!' 69 | " execute '/^\%(\s*#\)\@!.*\ze#' 70 | " execute '/^\(\s*#\)\@!\(#\)\@!$' 71 | " echo split(escape(&commentstring, '^$.*/"'''), '%s')[0] 72 | endif 73 | endfunction 74 | -------------------------------------------------------------------------------- /plugin/inyoface.vim: -------------------------------------------------------------------------------- 1 | if exists(":CPHL") 2 | CPHL NonComment gray2 - - - 3 | else 4 | highlight default NonComment ctermfg=8 ctermbg=none cterm=none guifg=#333333 guibg=none gui=none 5 | endif 6 | 7 | nmap (InYoFace_Toggle) :call inyoface#toggle_comments() 8 | -------------------------------------------------------------------------------- /test/test_matches.vader: -------------------------------------------------------------------------------- 1 | Before (Set some variables): 2 | let g:python_comment_str = '# %s' 3 | let g:viml_comment_str = '"%s' 4 | 5 | 6 | Execute (Test easy python comments): 7 | AssertEqual '', matchstr('# this is a python comment', inyoface#get_search_string(g:python_comment_str)) 8 | AssertEqual '', matchstr(' # whitespace before comment', inyoface#get_search_string(g:python_comment_str)) 9 | 10 | Execute (Test easy python non comments): 11 | AssertEqual 'def this_function():', matchstr('def this_function():', inyoface#get_search_string(g:python_comment_str)) 12 | 13 | Execute (Test viml comments): 14 | AssertEqual '', matchstr('" This is a viml comment', inyoface#get_search_string(g:viml_comment_str)) 15 | AssertEqual '', matchstr(' " This is a viml comment with space', inyoface#get_search_string(g:viml_comment_str)) 16 | 17 | Execute (Test viml non comments): 18 | AssertEqual 'function! test()', matchstr('function! test()', inyoface#get_search_string(g:viml_comment_str)) 19 | AssertEqual 'let g:my_var = "hello"', matchstr('let g:my_var = "hello"', inyoface#get_search_string(g:viml_comment_str)) 20 | 21 | Execute (Test python comments on end of line): 22 | Log 'TODO' 23 | " AssertEqual 'def this_function(): ', matchstr('def this_function(): # A comment here', 24 | " \ inyoface#get_search_string(g:python_comment_str)) 25 | 26 | Execute (Testing with the comments, not comment string): 27 | Log 'TODO' 28 | --------------------------------------------------------------------------------