├── .gitattributes ├── .gitignore ├── README.md ├── autoload └── auto_cursorline.vim ├── doc └── auto_cursorline.txt └── plugin └── auto_cursorline.vim /.gitattributes: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # vim:fenc=utf-8 ff=unix 3 | 4 | # git system files 5 | .gitattributes eol=lf 6 | # gitignore contains Icon^M <- CRLF end 7 | # skip autocrlf,diff enable -> not binary, set -text 8 | .gitignore -text 9 | 10 | # EOF 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### https://raw.github.com/github/gitignore/c1b7904af6689bd01646f008b0561d4f19a0e972/Global/macOS.gitignore 2 | 3 | # General 4 | .DS_Store 5 | .AppleDouble 6 | .LSOverride 7 | 8 | # Icon must end with two \r 9 | Icon 10 | 11 | # Thumbnails 12 | ._* 13 | 14 | # Files that might appear in the root of a volume 15 | .DocumentRevisions-V100 16 | .fseventsd 17 | .Spotlight-V100 18 | .TemporaryItems 19 | .Trashes 20 | .VolumeIcon.icns 21 | .com.apple.timemachine.donotpresent 22 | 23 | # Directories potentially created on remote AFP share 24 | .AppleDB 25 | .AppleDesktop 26 | Network Trash Folder 27 | Temporary Items 28 | .apdisk 29 | 30 | 31 | ### https://raw.github.com/github/gitignore/c1b7904af6689bd01646f008b0561d4f19a0e972/Global/Vim.gitignore 32 | 33 | # Swap 34 | [._]*.s[a-v][a-z] 35 | [._]*.sw[a-p] 36 | [._]s[a-rt-v][a-z] 37 | [._]ss[a-gi-z] 38 | [._]sw[a-p] 39 | 40 | # Session 41 | Session.vim 42 | 43 | # Temporary 44 | .netrwhist 45 | *~ 46 | # Auto-generated tag files 47 | tags 48 | # Persistent undo 49 | [._]*.un~ 50 | 51 | 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-auto-cursorline 2 | 3 | ![demo](https://user-images.githubusercontent.com/1239245/56327655-4c169000-61b6-11e9-8cb8-23d3ca1773a7.gif) 4 | 5 | Show / hide cursorline in connection with cursor moving. 6 | 7 | ## What's this? 8 | 9 | This plugin manages the `'cursorline'` option to show only when you need. 10 | 11 | NOTE: For Neovim (>=0.7.0) users, you may use a Lua version of this instead. 12 | See [delphinus/auto-cursorline.nvim][]. 13 | 14 | [delphinus/auto-cursorline.nvim]: https://github.com/delphinus/auto-cursorline.nvim 15 | 16 | ## Install 17 | 18 | Clone the repository to your `'packpath'` …… that's all! 19 | 20 | For usage and other settings, see the [doc][]. 21 | 22 | [doc]: doc/auto_cursorline.txt 23 | -------------------------------------------------------------------------------- /autoload/auto_cursorline.vim: -------------------------------------------------------------------------------- 1 | " When CursorMoved,CursorMovedI occurs, it substitutes s:cursor into s:status. 2 | " And when WinEnter, it substitutes s:window into s:status. 3 | " 4 | " NOTE: When you enter in a new window, WinEnter AND CursorMoved events occur 5 | " some time. So cursor_moved() does nothing when s:status == s:window, that 6 | " is, win_enter() has been called. When you move the cursor after that, it 7 | " sets 'nocursorline' at the first time. 8 | 9 | let s:disabled = 0 10 | let s:cursor = 1 11 | let s:window = 2 12 | let s:status = s:disabled 13 | let s:timer_id = 0 14 | 15 | function! auto_cursorline#cursor_moved() abort 16 | if auto_cursorline#is_disabled() 17 | return 18 | endif 19 | if s:status == s:window 20 | let s:status = s:cursor 21 | return 22 | endif 23 | call auto_cursorline#timer_stop() 24 | call auto_cursorline#timer_start() 25 | if s:status == s:cursor 26 | setlocal nocursorline 27 | let s:status = s:disabled 28 | endif 29 | endfunction 30 | 31 | function! auto_cursorline#win_enter() abort 32 | if auto_cursorline#is_disabled() 33 | return 34 | endif 35 | setlocal cursorline 36 | let s:status = s:window 37 | call auto_cursorline#timer_stop() 38 | endfunction 39 | 40 | function! auto_cursorline#win_leave() abort 41 | if auto_cursorline#is_disabled() 42 | return 43 | endif 44 | setlocal nocursorline 45 | call auto_cursorline#timer_stop() 46 | endfunction 47 | 48 | function! auto_cursorline#timer_start() abort 49 | let s:timer_id = timer_start(g:auto_cursorline_wait_ms, 'auto_cursorline#enable') 50 | endfunction 51 | 52 | function! auto_cursorline#timer_stop() abort 53 | if s:timer_id 54 | call timer_stop(s:timer_id) 55 | let s:timer_id = 0 56 | endif 57 | endfunction 58 | 59 | function! auto_cursorline#enable(timer_id) abort 60 | setlocal cursorline 61 | let s:status = s:cursor 62 | let s:timer_id = 0 63 | endfunction 64 | 65 | function! auto_cursorline#is_disabled() abort 66 | return &buftype ==# 'terminal' || get(b:, 'auto_cursorline_disabled', 0) 67 | endfunction 68 | -------------------------------------------------------------------------------- /doc/auto_cursorline.txt: -------------------------------------------------------------------------------- 1 | *auto_cursorline.txt* enable/disable cursorline automatically 2 | 3 | Author: delphinus 4 | Licence: MIT 5 | 6 | CONTENTS *auto_cursorline-contents* 7 | 8 | Introduction |auto_cursorline-introduction| 9 | Install |auto_cursorline-install| 10 | Configuration |auto_cursorline-configuration| 11 | Functions |auto_cursorline-functions| 12 | Variables |auto_cursorline-variables| 13 | Information |auto_cursorline-information| 14 | 15 | 16 | ============================================================================== 17 | INTRODUCTION *auto_cursorline-introduction* 18 | 19 | This plugin manages the |'cursorline'| option to show only when you need. It 20 | shows / hides in these cases below. 21 | 22 | * When it shows 23 | - opening buffers 24 | - moving into another window 25 | - holding the cursor in a certain wait (customizable) 26 | 27 | * When it hides 28 | - moving the cursor 29 | 30 | NOTE: For Neovim (>=0.7.0) users, you may use a Lua version of this instead. 31 | See https://github.com/delphinus/auto-cursorline.nvim 32 | 33 | 34 | ============================================================================== 35 | INSTALL *auto_cursorline-install* 36 | 37 | Clone the repository to your |packpath| …… that's all! 38 | 39 | 40 | ============================================================================== 41 | CONFIGURATION *auto_cursorline-configuration* 42 | 43 | *auto_cursorline-configuration-g_auto_cursorline_wait_ms* 44 | g:auto_cursorline_wait_ms ~ 45 | 46 | It waits this value milliseconds before hiding |'cursorline'|. Default: `1000` 47 | 48 | *auto_cursorline-configuration-b_auto_cursorline_disabled* 49 | b:auto_cursorline_disabled ~ 50 | 51 | When this value is set to `1`, it disables all features. This is a 52 | buffer-specific value, so you may set this with autocmd. 53 | > 54 | " this disables all features in JSON filetypes. 55 | autocmd FileType json :let b:auto_cursorline_disabled = 1 56 | 57 | In addition to this, all features are already disabled in |terminal| windows. 58 | 59 | 60 | ============================================================================== 61 | INFORMATION *auto_cursorline-information* 62 | 63 | Why is this plugin needed? ~ 64 | 65 | (details in https://qiita.com/delphinus/items/a05f6f21dd494bad9f25 ) 66 | 67 | The |'cursorline'| option takes heavy CPU usage and makes the cursor move 68 | slowly. In addition, you should need |'cursorline'| only when you are missing 69 | the cursor. Hiding |'cursorline'| should make it easy to read characters on the 70 | line. 71 | 72 | 73 | Background ~ 74 | 75 | The idea of this plugin is derived from this entry below: 76 | https://thinca.hatenablog.com/entry/20090530/1243615055 77 | One of the reason why I did “reinventing the wheel” is because the original 78 | one uses the |'updatetime'| option to wait before hiding |'cursorline'|. But other 79 | plugins, such as vim-gitgutter https://github.com/airblade/vim-gitgutter uses 80 | |'updatetime'| for different usages. I made this plugin for setting the 81 | designated value for the time before hiding the |'cursorline'|. 82 | 83 | 84 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 85 | -------------------------------------------------------------------------------- /plugin/auto_cursorline.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_auto_cursorline') 2 | finish 3 | endif 4 | let g:loaded_auto_cursorline = 1 5 | 6 | let s:save_cpo = &cpoptions 7 | set cpoptions&vim 8 | 9 | let g:auto_cursorline_wait_ms = get(g:, 'auto_cursorline_wait_ms', 1000) 10 | 11 | augroup auto-cursorline 12 | autocmd! 13 | autocmd CursorMoved,CursorMovedI * call auto_cursorline#cursor_moved() 14 | autocmd WinEnter * call auto_cursorline#win_enter() 15 | autocmd WinLeave * call auto_cursorline#win_leave() 16 | augroup END 17 | 18 | let &cpoptions = s:save_cpo 19 | unlet s:save_cpo 20 | --------------------------------------------------------------------------------