aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Christian Pohle2021-10-09 23:14:43 +0200
committerMax Christian Pohle2021-10-09 23:14:43 +0200
commit6ef2556ae020a8d04ee6e3b75d6df82bb2d9f6e1 (patch)
tree2d436e3c4a5772abc4093fd324a87b1713920bca
downloadvim-under-the-cursor-6ef2556ae020a8d04ee6e3b75d6df82bb2d9f6e1.tar.bz2
vim-under-the-cursor-6ef2556ae020a8d04ee6e3b75d6df82bb2d9f6e1.zip
Initial release.
-rw-r--r--README.md33
-rw-r--r--doc/vim-under-the-cursor.txt12
-rw-r--r--plugin/vim-under-the-cursor.vim57
-rw-r--r--screenshot.pngbin0 -> 82527 bytes
4 files changed, 102 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..56bd82a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,33 @@
1# vim-under-the-cursor
2
3Underlines all occurances of the word under the cursor and additionally
4displays the color under the cursor if it is written as a hex value. The
5alpha-channel (#rgba colors) is also supported and changes the brightness of
6colors.
7
8![screenshot](/screenshot.png)
9
10## Installation
11
12This should be sufficient:
13
14 git clone https://git.entwicklerseite.de/vim-under-the-cursor \
15 ~/.vim/pack/coderonline/start/vim-under-the-cursor
16
17Or as submodule:
18
19 git submodule add https://git.entwicklerseite.de/vim-under-the-cursor \
20 ~/.vim/pack/coderonline/start/vim-under-the-cursor
21
22Or download the zip file and extract it under `~/.vim/pack/coderonline/start/`.
23
24## Installation using plugin managers
25
26### vim-plug
27
28 Plug 'coderonline/vim-under-the-cursor'
29
30### dein.vim
31
32 call dein#add('coderonline/vim-under-the-cursor')
33
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 @@
1*vim-under-the-cursor.txt* Highlight the word under the cursor and colors
2
3==============================================================================
4USAGE INSTRUCTIONS *vim-under-the-cursor*
5
6This plugin should work out of the box and does not require dedicated
7configuration, however your Vim must use GUI colors for it to work. These
8can be activated with
9
10 :set termguicolors
11
12vim: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 @@
1"=======================================================================================================================
2" HIGHLIGHT_WORD_UNDER_CURSOR:
3"=======================================================================================================================
4
5let w:m1 = 0
6function! HighlightWordUnderCursor()
7 if(exists('w:m1') && w:m1 > 0)
8 silent! call matchdelete(w:m1)
9 let w:m1 = 0
10 endif
11 let l:currentword = escape(expand('<cword>'), '.')
12 if(strlen(l:currentword) > 0)
13 let w:m1=100
14
15 " match rgba...
16 let l:q = matchstr(expand('<cword>'), '\x\{8\}')
17 if(l:q == "") " without alpha
18 let l:q = matchstr(expand('<cword>'), '\x\{6\}')
19 let l:a = 255
20 else " with alpha...
21 let l:a = str2nr(strpart(l:q, 6, 2), 16)
22 endif
23
24 if(l:q != "")
25 let l:r = str2nr(strpart(l:q, 0, 2), 16) * (l:a / 255.0)
26 let l:g = str2nr(strpart(l:q, 2, 2), 16) * (l:a / 255.0)
27 let l:b = str2nr(strpart(l:q, 4, 2), 16) * (l:a / 255.0)
28 let l:color =
29 \ printf('%02x', float2nr(l:r))
30 \ . printf('%02x', float2nr(l:g))
31 \ . printf('%02x', float2nr(l:b))
32 \ . printf('%02x', float2nr(l:a))
33
34 let l:brightness = (l:r / 3) + (l:g / 1) + (l:b / 8)
35
36 " echo 'q:'. l:q . ' r:' . l:r . ' g:' . l:g . ' b:' . l:b . ' a:' . l:a . ' / ' .
37 " \ (str2nr(l:a, 16) / 255.0) . ' brightness: ' . l:brightness . ' / color:' . l:color
38
39 if(l:brightness > 240)
40 exec 'highlight! ' . l:color . ' guibg=#' . strpart(l:color, 0, 6) . ' guifg=#000000'
41 else
42 exec 'highlight! ' . l:color . ' guibg=#' . strpart(l:color, 0, 6) . ' guifg=#ffffff'
43 endif
44
45 exec 'syntax clear ' . l:color
46 exec 'syntax match ' . l:color . ' /\#' . l:q . '/'
47 else
48 silent! call matchadd('Underline', '\<'.l:currentword.'\>', -1, w:m1)
49 endif
50 endif
51endfunction
52
53" set updatetime=100
54highlight! Underline cterm=underline gui=underline
55autocmd CursorMoved,InsertLeave,TextChanged * call HighlightWordUnderCursor()
56
57" vim: expandtab tabstop=4 sw=4
diff --git a/screenshot.png b/screenshot.png
new file mode 100644
index 0000000..4205374
--- /dev/null
+++ b/screenshot.png
Binary files differ
..