Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 939384a5819da8fc934cf9a48ead687bae0b2213 @itchyny committed Jan 25, 2015
Showing with 153 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +21 −0 LICENSE
  3. +12 −0 README.md
  4. +40 −0 autoload/cursorword.vim
  5. +56 −0 doc/cursorword.txt
  6. +23 −0 plugin/cursorword.vim
@@ -0,0 +1 @@
+/doc/tags
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 itchyny
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
@@ -0,0 +1,12 @@
+# vim-cursorword
+## Underlines the word under the cursor
+![vim-cursorword](https://raw.githubusercontent.com/wiki/itchyny/vim-cursorword/image/image.gif)
+
+## Installation
+Install with your favorite plugin manager.
+
+## Author
+itchyny (https://github.com/itchyny)
+
+## License
+This software is released under the MIT License, see LICENSE.
@@ -0,0 +1,40 @@
+" =============================================================================
+" Filename: autoload/cursorword.vim
+" Author: itchyny
+" License: MIT License
+" Last Change: 2015/01/24 16:31:03.
+" =============================================================================
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+function! cursorword#highlight() abort
+ if !get(g:, 'cursorword_highlight', 1) | return | endif
+ highlight CursorWord0 term=underline cterm=underline gui=underline
+ redir => out
+ silent! highlight CursorLine
+ redir END
+ let highlight = 'highlight CursorWord1 term=underline cterm=underline gui=underline'
+ execute highlight matchstr(out, 'ctermbg=#\?\w\+') matchstr(out, 'guibg=#\?\w\+')
+endfunction
+
+function! cursorword#matchadd() abort
+ let enable = get(b:, 'cursorword', get(g:, 'cursorword', 1))
+ if !enable && !get(w:, 'cursorword_match') | return | endif
+ let line = getline('.')
+ let linenr = line('.')
+ let word = matchstr(line[:(col('.')-1)], '\k*$')[:-2] . matchstr(line[(col('.')-1):], '^\k*')
+ if get(w:, 'cursorword_state', []) ==# [ linenr, word, enable ] | return | endif
+ let w:cursorword_state = [ linenr, word, enable ]
+ silent! call matchdelete(w:cursorword_id0)
+ silent! call matchdelete(w:cursorword_id1)
+ let w:cursorword_match = 0
+ if !enable || !len(word) || len(word) !=# strchars(word) | return | endif
+ let pattern = '\<' . escape(word, '~"\.^$[]*') . '\>'
+ let w:cursorword_id0 = matchadd('CursorWord0', pattern, -1)
+ let w:cursorword_id1 = matchadd('CursorWord' . &l:cursorline, '\%' . line('.') . 'l' . pattern, -1)
+ let w:cursorword_match = 1
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
@@ -0,0 +1,56 @@
+*cursorword.txt* Underlines the word under the cursor
+
+Version: 0.0
+Author: itchyny (https://github.com/itchyny)
+License: MIT License
+Repository: https://github.com/itchyny/vim-cursorword
+Last Change: 2015/01/24 14:34:50.
+
+CONTENTS *cursorword-contents*
+
+Introduction |cursorword-introduction|
+Changelog |cursorword-changelog|
+
+==============================================================================
+INTRODUCTION *cursorword-introduction*
+This *cursorword* plugin underlines the word under the cursor. That's it.
+
+While we are coding, we always take attention to the variable under the
+cursor. Where did we define the variable? In which statement do we use the
+variable? Searching the variable using |star| or |#| is a simple solution to
+highlight all the places the variable is used. However, it costs too much time
+to highlight a word, move around to check the places and clear the highlight.
+This plugin |cursorword| provides you the modest underlines for the variables
+under the cursor to let you know all the places the variable is used at a
+glance without stopping coding.
+
+The brightest plugin (https://github.com/osyo-manga/vim-brightest) is a nice
+plugin to fulfill highlights of the word under the cursor. However, it uses
+too long codes and is too slow. I had being using the plugin for a while but I
+could not bear the slowness caused by brightest on the cursor motions. This is
+why I created |cursorword|. I think that a plugin which is running all the time
+should be coded with the performance efficiency in mind. When we publish a
+plugin which stays running in all buffers, we should be aware that it will use
+much resource of all the users.
+
+The code of |cursorword| is very tiny. It's very tiny that |cursorword| runs ten
+times faster than brightest. Instead of its efficiency, |cursorword| is totally
+unconfigurable. But you will find this plugin just comfortable; the modest
+underlines are enough for us. A good configurable plugin would have many
+options that users can configure almost all the features. But be relaxed and
+imagine, do we need such a lot of options for a plugin to highlight the word
+under the cursor? Most people would never need such a lot of options. We
+should not implement features for a few power users at the sacrifice of the
+performance of the software. Keep your software small for the happiness of
+most users. Too much configurability makes your software dirty and causes
+unwanted slowness on many users. We have to rethink what good configurability
+is and for what kind of software such configurability is required.
+
+==============================================================================
+CHANGELOG *cursorword-changelog*
+
+0.0 2014-01-25
+ - Initial commit.
+
+==============================================================================
+vim:tw=78:sw=4:ts=8:ft=help:norl:noet:
@@ -0,0 +1,23 @@
+" =============================================================================
+" Filename: plugin/cursorword.vim
+" Author: itchyny
+" License: MIT License
+" Last Change: 2015/01/24 13:02:48.
+" =============================================================================
+
+if exists('g:loaded_cursorword') || v:version < 703
+ finish
+endif
+let g:loaded_cursorword = 1
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+augroup cursorword
+ autocmd!
+ autocmd VimEnter,ColorScheme * call cursorword#highlight()
+ autocmd VimEnter,WinEnter,BufEnter,CursorMoved,CursorMovedI * call cursorword#matchadd()
+augroup END
+
+let &cpo = s:save_cpo
+unlet s:save_cpo

0 comments on commit 939384a

Please sign in to comment.