From 6ef2556ae020a8d04ee6e3b75d6df82bb2d9f6e1 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Sat, 9 Oct 2021 23:14:43 +0200 Subject: Initial release. --- README.md | 33 +++++++++++++++++++++++ doc/vim-under-the-cursor.txt | 12 +++++++++ plugin/vim-under-the-cursor.vim | 57 ++++++++++++++++++++++++++++++++++++++++ screenshot.png | Bin 0 -> 82527 bytes 4 files changed, 102 insertions(+) create mode 100644 README.md create mode 100644 doc/vim-under-the-cursor.txt create mode 100644 plugin/vim-under-the-cursor.vim create mode 100644 screenshot.png diff --git a/README.md b/README.md new file mode 100644 index 0000000..56bd82a --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# vim-under-the-cursor + +Underlines all occurances of the word under the cursor and additionally +displays the color under the cursor if it is written as a hex value. The +alpha-channel (#rgba colors) is also supported and changes the brightness of +colors. + +![screenshot](/screenshot.png) + +## Installation + +This should be sufficient: + + git clone https://git.entwicklerseite.de/vim-under-the-cursor \ + ~/.vim/pack/coderonline/start/vim-under-the-cursor + +Or as submodule: + + git submodule add https://git.entwicklerseite.de/vim-under-the-cursor \ + ~/.vim/pack/coderonline/start/vim-under-the-cursor + +Or download the zip file and extract it under `~/.vim/pack/coderonline/start/`. + +## Installation using plugin managers + +### vim-plug + + Plug 'coderonline/vim-under-the-cursor' + +### dein.vim + + call dein#add('coderonline/vim-under-the-cursor') + diff --git a/doc/vim-under-the-cursor.txt b/doc/vim-under-the-cursor.txt new file mode 100644 index 0000000..a799d82 --- /dev/null +++ b/doc/vim-under-the-cursor.txt @@ -0,0 +1,12 @@ +*vim-under-the-cursor.txt* Highlight the word under the cursor and colors + +============================================================================== +USAGE INSTRUCTIONS *vim-under-the-cursor* + +This plugin should work out of the box and does not require dedicated +configuration, however your Vim must use GUI colors for it to work. These +can be activated with + + :set termguicolors + +vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/vim-under-the-cursor.vim b/plugin/vim-under-the-cursor.vim new file mode 100644 index 0000000..403164a --- /dev/null +++ b/plugin/vim-under-the-cursor.vim @@ -0,0 +1,57 @@ +"======================================================================================================================= +" HIGHLIGHT_WORD_UNDER_CURSOR: +"======================================================================================================================= + +let w:m1 = 0 +function! HighlightWordUnderCursor() + if(exists('w:m1') && w:m1 > 0) + silent! call matchdelete(w:m1) + let w:m1 = 0 + endif + let l:currentword = escape(expand(''), '.') + if(strlen(l:currentword) > 0) + let w:m1=100 + + " match rgba... + let l:q = matchstr(expand(''), '\x\{8\}') + if(l:q == "") " without alpha + let l:q = matchstr(expand(''), '\x\{6\}') + let l:a = 255 + else " with alpha... + let l:a = str2nr(strpart(l:q, 6, 2), 16) + endif + + if(l:q != "") + let l:r = str2nr(strpart(l:q, 0, 2), 16) * (l:a / 255.0) + let l:g = str2nr(strpart(l:q, 2, 2), 16) * (l:a / 255.0) + let l:b = str2nr(strpart(l:q, 4, 2), 16) * (l:a / 255.0) + let l:color = + \ printf('%02x', float2nr(l:r)) + \ . printf('%02x', float2nr(l:g)) + \ . printf('%02x', float2nr(l:b)) + \ . printf('%02x', float2nr(l:a)) + + let l:brightness = (l:r / 3) + (l:g / 1) + (l:b / 8) + + " echo 'q:'. l:q . ' r:' . l:r . ' g:' . l:g . ' b:' . l:b . ' a:' . l:a . ' / ' . + " \ (str2nr(l:a, 16) / 255.0) . ' brightness: ' . l:brightness . ' / color:' . l:color + + if(l:brightness > 240) + exec 'highlight! ' . l:color . ' guibg=#' . strpart(l:color, 0, 6) . ' guifg=#000000' + else + exec 'highlight! ' . l:color . ' guibg=#' . strpart(l:color, 0, 6) . ' guifg=#ffffff' + endif + + exec 'syntax clear ' . l:color + exec 'syntax match ' . l:color . ' /\#' . l:q . '/' + else + silent! call matchadd('Underline', '\<'.l:currentword.'\>', -1, w:m1) + endif + endif +endfunction + +" set updatetime=100 +highlight! Underline cterm=underline gui=underline +autocmd CursorMoved,InsertLeave,TextChanged * call HighlightWordUnderCursor() + +" vim: expandtab tabstop=4 sw=4 diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..4205374 Binary files /dev/null and b/screenshot.png differ -- cgit v1.2.3