├── LICENSE ├── README.markdown ├── doc └── numbertoggle.txt └── plugin └── number_toggle.vim /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jeff Kreeftmeijer 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 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, 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 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # numbertoggle 2 | 3 | 4 | In a buffer with "hybrid" line numbers (`:set number relativenumber`), 5 | numbertoggle switches to absolute line numbers (`:set number norelativenumber`) 6 | automatically when relative numbers don't make sense. 7 | 8 | ![vim-numbertoggle toggles between "hybrid" and absolute line numbers automatically](https://raw.githubusercontent.com/jeffkreeftmeijer/vim-numbertoggle/cast/toggle.gif) 9 | 10 | Relative numbers are used in a buffer that has focus, and is in normal 11 | mode, since that's where you move around. They're turned off when you switch 12 | out of Vim, switch to another split, or when you go into insert mode. 13 | 14 | ## Installation 15 | 16 | Using Vim's package manager: 17 | 18 | 1. `$ git clone --branch main git@github.com:jeffkreeftmeijer/vim-numbertoggle.git ~/.vim/pack/plugins/start/vim-numbertoggle` 19 | 2. `:set number` 20 | 21 | Once help tags are generated, you can view the manual with `:help numbertoggle`. 22 | 23 | ## tmux 24 | 25 | If you use tmux, add `set-option -g focus-events on` to your tmux config (`~/.tmux.conf`) (https://github.com/jeffkreeftmeijer/vim-numbertoggle/issues/45). 26 | -------------------------------------------------------------------------------- /doc/numbertoggle.txt: -------------------------------------------------------------------------------- 1 | *numbertoggle.txt* Automatic toggling between "hybrid" and absolute line numbers 2 | 3 | Author: Jeff Kreeftmeijer 4 | License: MIT 5 | 6 | INTRODUCTION *numbertoggle* 7 | 8 | In a buffer with "hybrid" line numbers (`:set number relativenumber`), 9 | numbertoggle switches to absolute line numbers (`:set number norelativenumber`) 10 | automatically when relative numbers don't make sense. 11 | 12 | Relative numbers are only used in a buffer that has focus, and is in normal 13 | mode, since that's where you move around. They're turned off when you switch 14 | out of Vim, switch to another split, or when you go into insert mode. 15 | 16 | LEGACY SUPPORT *numbertoggle-legacy* 17 | 18 | Since version 2.0, numbertoggle dropped support for Vim < 7.3, and removed its 19 | configuration options in favor of a simple implementation with sensible 20 | defaults. If that doesn't work for you or your setup, you can switch to the 21 | legacy version by installing it from the legacy branch at 22 | . 23 | 24 | Also, numbertoggle doesn't set up a trigger to switch between line number 25 | modes anymore. To set one up yourself using , use: 26 | > 27 | :nnoremap :set relativenumber! 28 | < 29 | ABOUT *numbertoggle-about* 30 | 31 | Grab the latest version or report a bug on GitHub: 32 | 33 | http://github.com/jeffkreeftmeijer/vim-numbertoggle 34 | 35 | vim:tw=78:et:ft=help:norl: 36 | -------------------------------------------------------------------------------- /plugin/number_toggle.vim: -------------------------------------------------------------------------------- 1 | " vim-numbertoggle - Automatic toggling between 'hybrid' and absolute line numbers 2 | " Maintainer: 3 | " Version: 2.1.2 4 | 5 | augroup numbertoggle 6 | autocmd! 7 | autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu | endif 8 | autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif 9 | augroup END 10 | --------------------------------------------------------------------------------