├── .gitignore ├── LICENSE ├── README.md ├── autoload └── syntaxinfo.vim ├── doc └── syntaxinfo.txt ├── images └── demo.gif └── plugin └── syntaxinfo.vim /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/macos,windows 3 | # Edit at https://www.gitignore.io/?templates=macos,windows 4 | 5 | ### macOS ### 6 | # General 7 | .DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | 11 | # Icon must end with two \r 12 | Icon 13 | 14 | # Thumbnails 15 | ._* 16 | 17 | # Files that might appear in the root of a volume 18 | .DocumentRevisions-V100 19 | .fseventsd 20 | .Spotlight-V100 21 | .TemporaryItems 22 | .Trashes 23 | .VolumeIcon.icns 24 | .com.apple.timemachine.donotpresent 25 | 26 | # Directories potentially created on remote AFP share 27 | .AppleDB 28 | .AppleDesktop 29 | Network Trash Folder 30 | Temporary Items 31 | .apdisk 32 | 33 | ### Windows ### 34 | # Windows thumbnail cache files 35 | Thumbs.db 36 | Thumbs.db:encryptable 37 | ehthumbs.db 38 | ehthumbs_vista.db 39 | 40 | # Dump file 41 | *.stackdump 42 | 43 | # Folder config file 44 | [Dd]esktop.ini 45 | 46 | # Recycle Bin used on file shares 47 | $RECYCLE.BIN/ 48 | 49 | # Windows Installer files 50 | *.cab 51 | *.msi 52 | *.msix 53 | *.msm 54 | *.msp 55 | 56 | # Windows shortcuts 57 | *.lnk 58 | 59 | # End of https://www.gitignore.io/api/macos,windows 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 wadackel 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 copies 9 | of the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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 IMPLIED, 16 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 17 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 20 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nvim-syntax-info 2 | 3 | ![DEMO](./images/demo.gif) 4 | 5 | **nvim-syntax-info** is a plugin that displays syntax information (highlight-groups) with `nvim_buf_set_virtual_text`. 6 | 7 | Displays the highlight group at the cursor position as shown below. 8 | 9 | ``` 10 | return synIDattr(a:synid, 'name') base=vimNotFunc, linked=Statement 11 | |__ cursor here. |_______________________________| 12 | virtual text 13 | ``` 14 | 15 | It will help you customize your colorscheme and make your own colorscheme! 16 | 17 | ## Installation 18 | 19 | Follow the package manager installation method you are using. 20 | Here is an example with [vim-plug](https://github.com/junegunn/vim-plug). 21 | 22 | ```vim 23 | Plug 'wadackel/nvim-syntax-info' 24 | ``` 25 | 26 | ## Usage 27 | 28 | See also [:h nvim-syntax-info](./doc/syntaxinfo.txt). 29 | 30 | ### Commands 31 | 32 | #### `:SyntaxInfo` 33 | 34 | Displays syntax information (virtual text) at the cursor position. 35 | 36 | #### `:SyntaxInfoClear` 37 | 38 | Clear syntax information (virtual text) at the cursor position. 39 | 40 | #### `:SyntaxInfoEnable` 41 | 42 | Syntax information is displayed automatically when the cursor is moved. 43 | 44 | #### `:SyntaxInfoDisable` 45 | 46 | Disables display with cursor movement. 47 | 48 | #### `:SyntaxInfoToggle` 49 | 50 | Switch whether to display syntax information by moving the cursor. 51 | 52 | ### Mappings 53 | 54 | It does not provide a default mapping. 55 | Let's set your mapping using the following keys. 56 | 57 | - `(syntax-info)` 58 | - `(syntax-info-clear)` 59 | - `(syntax-info-enable)` 60 | - `(syntax-info-disable)` 61 | - `(syntax-info-toggle)` 62 | 63 | **For example:** 64 | 65 | ```vim 66 | nmap si (syntax-info-toggle) 67 | ``` 68 | 69 | ### Variables 70 | 71 | #### `g:syntaxinfo_format` (Default: `"base=%base%, linked=%linked%"`) 72 | 73 | You can specify the content to be displayed in virtual text in the format of `%KEY_NAME%`. 74 | 75 | | Key | Description | 76 | | :----- | :------------------------------------- | 77 | | base | Directly applied highlight group name. | 78 | | linked | Linked highlight group name. | 79 | 80 | #### `g:syntaxinfo_delay` (Default: 250) 81 | 82 | Specify the delay millisecond when displaying by moving the cursor. 83 | 84 | ### Highlights 85 | 86 | #### `SyntaxInfo` 87 | 88 | The highlight for syntax infomation in virtual text. 89 | 90 | **Default:** 91 | 92 | ```vim 93 | highlight link SyntaxInfo Comment 94 | ``` 95 | 96 | ## License 97 | 98 | [MIT License © wadackel](./LICENSE) 99 | -------------------------------------------------------------------------------- /autoload/syntaxinfo.vim: -------------------------------------------------------------------------------- 1 | let g:syntaxinfo_enabled = get(g:, 'syntaxinfo_enabled', v:false) 2 | 3 | let s:format = get(g:, 'syntaxinfo_format', 'base=%base%, linked=%linked%') 4 | let s:delay = get(g:, 'syntaxinfo_delay', 250) 5 | 6 | let s:ns = nvim_create_namespace('syntaxinfo') 7 | let s:timer_id = -1 8 | 9 | function! s:get_syn_id(transparent) 10 | let synid = synID(line('.'), col('.'), 1) 11 | if a:transparent 12 | return synIDtrans(synid) 13 | else 14 | return synid 15 | endif 16 | endfunction 17 | 18 | function! s:get_syn_attr(synid) 19 | return synIDattr(a:synid, 'name') 20 | endfunction 21 | 22 | function! syntaxinfo#show() abort 23 | let base = s:get_syn_attr(s:get_syn_id(0)) 24 | let linked = s:get_syn_attr(s:get_syn_id(1)) 25 | let msg = substitute(s:format, '%base%', base != '' ? base : 'Normal', 'g') 26 | let msg = substitute(msg, '%linked%', linked != '' ? linked : 'Normal', 'g') 27 | let line = line('.') 28 | let bufnr = bufnr('') 29 | 30 | call nvim_buf_set_virtual_text(bufnr, s:ns, line - 1, [[msg, 'SyntaxInfo']], {}) 31 | endfunction 32 | 33 | function! syntaxinfo#clear() abort 34 | let bufnr = bufnr('') 35 | call nvim_buf_clear_namespace(bufnr, s:ns, 0, -1) 36 | endfunction 37 | 38 | function! syntaxinfo#refresh() abort 39 | if !g:syntaxinfo_enabled 40 | return 41 | endif 42 | 43 | call timer_stop(s:timer_id) 44 | call syntaxinfo#clear() 45 | 46 | let s:timer_id = timer_start(s:delay, { id -> syntaxinfo#show() }) 47 | endfunction 48 | 49 | function! syntaxinfo#enable() abort 50 | if g:syntaxinfo_enabled 51 | return 52 | endif 53 | 54 | let g:syntaxinfo_enabled = v:true 55 | 56 | call syntaxinfo#init() 57 | call syntaxinfo#show() 58 | endfunction 59 | 60 | function! syntaxinfo#disable() abort 61 | if !g:syntaxinfo_enabled 62 | return 63 | endif 64 | 65 | autocmd! syntaxinfo 66 | call timer_stop(s:timer_id) 67 | call syntaxinfo#clear() 68 | 69 | let g:syntaxinfo_enabled = v:false 70 | let s:timer_id = -1 71 | endfunction 72 | 73 | function! syntaxinfo#toggle() abort 74 | if g:syntaxinfo_enabled 75 | call syntaxinfo#disable() 76 | call syntaxinfo#clear() 77 | else 78 | call syntaxinfo#enable() 79 | call syntaxinfo#show() 80 | endif 81 | endfunction 82 | 83 | function! syntaxinfo#init() abort 84 | if !g:syntaxinfo_enabled 85 | return 86 | endif 87 | 88 | augroup syntaxinfo 89 | autocmd! 90 | autocmd BufEnter,BufWritePost,CursorMoved * :call syntaxinfo#refresh() 91 | augroup END 92 | endfunction 93 | -------------------------------------------------------------------------------- /doc/syntaxinfo.txt: -------------------------------------------------------------------------------- 1 | *nvim-syntax-info.txt* A plugin that displays 2 | syntax information (highlight-groups) with 3 | Neovim virtual text. 4 | 5 | Author: wadackel 6 | 7 | CONTENTS *nvim-syntax-info-contents* 8 | 9 | Introduction |nvim-syntax-info-introduction| 10 | Install |nvim-syntax-info-install| 11 | Commands |nvim-syntax-info-commands| 12 | Mappings |nvim-syntax-info-mappings| 13 | Variables |nvim-syntax-info-variables| 14 | Highlights |nvim-syntax-info-highlights| 15 | License |nvim-syntax-info-license| 16 | 17 | 18 | ============================================================================== 19 | Introduction *nvim-syntax-info-introduction* 20 | 21 | nvim-syntax-info is a plugin that displays syntax information 22 | with |nvim_buf_set_virtual_text|. 23 | 24 | Displays the highlight group at the cursor position as shown below. 25 | > 26 | return synIDattr(a:synid, 'name') base=vimNotFunc, linked=Statement 27 | |__ cursor here. |_______________________________| 28 | virtual text 29 | < 30 | It will help you customize your colorscheme and make your own colorscheme! 31 | 32 | 33 | ============================================================================== 34 | Install *nvim-syntax-info-install* 35 | 36 | Follow the package manager installation method you are using. 37 | Here is an example with vim-plug. 38 | > 39 | Plug 'wadackel/nvim-syntax-info' 40 | < 41 | vim-plug: https://github.com/junegunn/vim-plug 42 | 43 | 44 | ============================================================================== 45 | Commands *nvim-syntax-info-commands* 46 | 47 | :SyntaxInfo *SyntaxInfo* 48 | 49 | Displays syntax information (virtual text) at the cursor position. 50 | 51 | :SyntaxInfoClear *SyntaxInfoClear* 52 | 53 | Clear syntax information (virtual text) at the cursor position. 54 | 55 | :SyntaxInfoEnable *SyntaxInfoEnable* 56 | 57 | Syntax information is displayed automatically when the cursor is moved. 58 | 59 | :SyntaxInfoDisable *SyntaxInfoDisable* 60 | 61 | Disables display with cursor movement. 62 | 63 | :SyntaxInfoToggle *SyntaxInfoToggle* 64 | 65 | Switch whether to display syntax information by moving the cursor. 66 | 67 | ============================================================================== 68 | Mappings *nvim-syntax-info-mappings* 69 | 70 | It does not provide a default mapping. 71 | Let's set your mapping using the following keys. 72 | 73 | (syntax-info) *(syntax-info)* 74 | (syntax-info-clear) *(syntax-info-clear)* 75 | (syntax-info-enable) *(syntax-info-enable)* 76 | (syntax-info-disable) *(syntax-info-disable)* 77 | (syntax-info-toggle) *(syntax-info-toggle)* 78 | 79 | For example: 80 | > 81 | nmap si (syntax-info-toggle) 82 | < 83 | 84 | ============================================================================== 85 | Variables *nvim-syntax-info-variables* 86 | 87 | g:syntaxinfo_format *g:syntaxinfo_format* 88 | 89 | Type : |String| 90 | Default: `"base=%base%, linked=%linked%"` 91 | 92 | You can specify the content to be displayed in virtual text in 93 | the format of `%KEY_NAME%`. 94 | 95 | | Key | Description | 96 | | ------ | -------------------------------------- | 97 | | base | Directly applied highlight group name. | 98 | | linked | Linked highlight group name. | 99 | 100 | g:syntaxinfo_delay *g:syntaxinfo_delay* 101 | 102 | Type : |Number| 103 | Default: `250` 104 | 105 | Specify the delay millisecond when displaying by moving the cursor. 106 | 107 | 108 | ============================================================================== 109 | Highlights *nvim-syntax-info-highlights* 110 | 111 | SyntaxInfo *hl-SyntaxInfo* 112 | 113 | Default: `highlight link SyntaxInfo Comment` 114 | 115 | The highlight for syntax infomation in virtual text. 116 | 117 | 118 | ============================================================================== 119 | LICENSE *nvim-syntax-info-license* 120 | 121 | MIT License 122 | 123 | Copyright (c) 2020 wadackel 124 | 125 | Permission is hereby granted, free of charge, to any person obtaining a copy 126 | of this software and associated documentation files (the "Software"), to deal 127 | in the Software without restriction, including without limitation the rights 128 | to use, copy, modify, merge, publish, distribute, sublicense, 129 | and/or sell copies of the Software, and to permit persons to 130 | whom the Software is furnished to do so, subject to the following conditions: 131 | 132 | The above copyright notice and this permission notice 133 | shall be included in all copies or substantial portions of the Software. 134 | 135 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 136 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 137 | THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 138 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 139 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 140 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 141 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 142 | IN THE SOFTWARE. 143 | 144 | 145 | ============================================================================== 146 | vim:tw=78:colorcolumn=78:ts=8:ft=help:norl:et:fen:fdl=0: 147 | -------------------------------------------------------------------------------- /images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wadackel/nvim-syntax-info/6a18e2583c8e21004dbd6cc43122101ec65fcf45/images/demo.gif -------------------------------------------------------------------------------- /plugin/syntaxinfo.vim: -------------------------------------------------------------------------------- 1 | if exists('g:syntaxinfo_loaded') 2 | finish 3 | endif 4 | let g:syntaxinfo_loaded = 1 5 | 6 | command! -nargs=0 -bar SyntaxInfo call syntaxinfo#show() 7 | command! -nargs=0 -bar SyntaxInfoClear call syntaxinfo#clear() 8 | command! -nargs=0 -bar SyntaxInfoEnable call syntaxinfo#enable() 9 | command! -nargs=0 -bar SyntaxInfoDisable call syntaxinfo#disable() 10 | command! -nargs=0 -bar SyntaxInfoToggle call syntaxinfo#toggle() 11 | 12 | nnoremap (syntax-info) :SyntaxInfo 13 | nnoremap (syntax-info-clear) :SyntaxInfoClear 14 | nnoremap (syntax-info-enable) :SyntaxInfoEnable 15 | nnoremap (syntax-info-disable) :SyntaxInfoDisable 16 | nnoremap (syntax-info-toggle) :SyntaxInfoToggle 17 | 18 | highlight link SyntaxInfo Comment 19 | --------------------------------------------------------------------------------