sponsor Vim development Vim logo Vim Book Ad

vim-airline-stopwatch : a vim-airline extension that implements a stopwatch

 script karma  Rating 9/3, Downloaded by 785  Comments, bugs, improvements  Vim wiki

created by
Fan Zhang
 
script type
utility
 
description
vim-airline-stopwatch
- a vim-airline extension that implements a stopwatch. One of the things this is designed for is training to improve coding speed and tracking amount of time spent on reading/thinking/coding/debugging. There might be other use cases you might find this useful. Have fun :p

Requirements
- vim 8.0
- vim-airline plugin
- vim compiled with the following features, this means when you type
    vim --version, the following features will show up
    - +reltime
    - +timers
- optional vim with python support if you want to add test cases :)

Usage

:call airline#extensions#stopwatch#run()<CR>
:call airline#extensions#stopwatch#split()<CR>
:call airline#extensions#stopwatch#stop()<CR>
:call airline#extensions#stopwatch#reset()<CR>
:call airline#extensions#stopwatch#summary()<CR>

viewing splits
- each time split will create an entry on the status line. If there are
too many splits that could overflow the status line, type :messges in vim to view
the splits. Note the final stop time is not included in messages. The
rationale is stop() is actually pause() in disguise :) Also note you can
disable messages by setting let g:airline#extensions#stopwatch#save_to_messages = 0

```
:messages
```
- v0.1.0 and after, we have a more comprehensive summary of split times and
  stop times opened in a new buffer.
```
:call airline#extensions#stopwatch#summary()<CR>
```

Customization
To be placed in your .vimrc
- (optional) polling_period controls the amount of time between
each status line update, the bigger the number the slower it is.
The default number is 50ms. If we want to make it bigger, we can set it to
100ms for example.
```
let g:airline#extensions#stopwatch#polling_period = 100
```
- (optional) if we have too many split items,  saving to :messages
will disrupt us by prompting press enter to continue, to disable this
default behavior, we can set save_to messages = 0. This also means that if you
set this to 0, :messages no longer works.
```
let g:airline#extensions#stopwatch#save_to_messages = 0
```
- (optional) also if we have too many split items, it's sometimes desirable to
    limit the max number of extra items on the status line.
    -1 means no limit
    0 means just the timer itself.
```
let g:airline#extensions#stopwatch#max_extra_items = 5
```
- setting up shortcut keys so that we don't have to manually type the
calls every time.
```
map VIM_KEY_SEQUENCE :call airline#extensions#stopwatch#run()<CR>
map VIM_KEY_SEQUENCE :call airline#extensions#stopwatch#split()<CR>
map VIM_KEY_SEQUENCE :call airline#extensions#stopwatch#stop()<CR>
map VIM_KEY_SEQUENCE :call airline#extensions#stopwatch#reset()<CR>
map VIM_KEY_SEQUENCE :call airline#extensions#stopwatch#summary()<CR>
```
- example 1:
```
map <F4> :call airline#extensions#stopwatch#run()<CR>
map <F5> :call airline#extensions#stopwatch#split()<CR>
map <F6> :call airline#extensions#stopwatch#stop()<CR>
map <F7> :call airline#extensions#stopwatch#reset()<CR>
map <F8> :call airline#extensions#stopwatch#summary()<CR>
```
- example 2:
```
map tr :call airline#extensions#stopwatch#run()<CR>
map tp :call airline#extensions#stopwatch#split()<CR>
map ts :call airline#extensions#stopwatch#stop()<CR>
map tt :call airline#extensions#stopwatch#reset()<CR>
map ty :call airline#extensions#stopwatch#summary()<CR>
```

Caveats
- Since this plugin is updating the status line pretty frequently, expect heavy
  CPU usage. One thing we can do to decrease CPU usage is to slow down polling by increasing g:airline#extensions#stopwatch#polling_period.
- This plugin is only designed to time things within a few minutes, we might
  expect memory leak if running for a prolonged period of time.
 
install details
Pathogen
git clone https://github.com/ffanzhang/vim-airline-stopwatch ~/.vim/bundle/vim-airline-stopwatch

Alternatively, we can also unzip everything under ~/.vim/bundle, so
  the directory will look like ~/.vim/bundle/vim-airline-stopwatch/..

Vundle
Plugin 'ffanzhang/vim-airline-stopwatch'
:source %
:PluginInstall

vim-plug
Plug 'ffanzhang/vim-airline-stopwatch'
:source %
:PlugInstall

NeoBundle
NeoBundle 'ffanzhang/vim-airline-stopwatch'
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-airline-stopwatch-1.0.0.zip 1.0.0 2019-09-24 8.0 Fan Zhang - added lots of test cases in python. In theory, the code should still work if no python is compiled with vim.
  If python requirements break usability, just remove everything after the huge divider.
- removed usage of s:elapsed_time variable, was not a good decision to use it in the first place, should not break anything, fingers crossed.
- used vim's builtin string join() instead of my own.
- one extra call of get_elapsed_time() when calling stop().
- should be better thought out because I spent a few hours thinking about it.
vim-airline-stopwatch-0.1.1.zip 0.1.1 2019-09-03 8.0 Fan Zhang Fixed a bug where Vim 8.0 will generate an E488 Error interpreting time_to_string().
vim-airline-stopwatch-0.1.0.zip 0.1.0 2019-07-27 8.0 Fan Zhang - added a summary() function that opens a new buffer and displays split times and pause times.
- added a configurable variable that disables echom to messages.
- added a configurable variable that limits the number of split time entries.
- tested with Neobundle.
vim-airline-stopwatch-0.0.3.zip 0.0.3 2019-07-25 8.0 Fan Zhang - a bit of refactoring and testing
- tested installing with vim-plug
vim-airline-stopwatch-0.0.2.zip 0.0.2 2019-07-24 8.0 Fan Zhang - formatted time into h:m:s.xx format instead of s.xx format in 0.0.1.
- stop() no longer creates an extra entry on the statusline.
vim-airline-stopwatch-master.zip 0.0.1 2019-07-23 8.0 Fan Zhang Initial upload
ip used for rating: 52.14.221.113

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github