This repository has been archived by the owner on Dec 29, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vanessa McHale
committed
Mar 1, 2017
0 parents
commit 87bb23e
Showing
4 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Copyright 2017 Vanessa McHale | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
### Installation | ||
|
||
With [Vundle](https://github.com/VundleVim/Vundle.vim) simply add this to your .vimrc: | ||
|
||
``` | ||
Plugin 'vmchale/tokei-vim' | ||
``` | ||
|
||
Of couse, you'll need to install [tokei](https://github.com/Aaronepower/tokei/releases) as well. | ||
|
||
Because it runs tokei in your current working directory, you're probably going to want a plugin to change the root directory appropriately. I use [vim-rooter](https://github.com/airblade/vim-rooter). | ||
|
||
### Usage | ||
|
||
By default, tokei-vim provides a command and a keybinding: | ||
|
||
``` | ||
:Tokei | ||
<silent> co | ||
``` | ||
|
||
You can also set `g_tokei_exlude` to exlude a file or pattern; tokei follows the as a .gitignore. If you wish to exclude two patterns, separate them with a comma with no spaces, e.g. | ||
|
||
``` | ||
let g_tokei_exclude=TODO.md,README.md | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- [ ] generate vim docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
"============================================================================= | ||
" What Is This: Count makeup of a project and display the results on | ||
" a scratch buffer. | ||
" File: tokei.vim | ||
" Author: Vanessa McHale <tmchale@wisc.edu> | ||
" Version: 0.1.0.0 | ||
" ChangeLog: | ||
" 1.0: initial commit. | ||
if exists("g:__TOKEI_VIM__") | ||
finish | ||
endif | ||
let g:__TOKEI_VIM__ = 1 | ||
|
||
if !exists("g:tokei_line_count") | ||
let g:tokei_line_count = 13 | ||
endif | ||
|
||
if !exists("g:tokei_exlude") | ||
let g:tokei_exclude = 'TODO.md' | ||
endif | ||
|
||
let g:tokei_buf_name = 'Tokei' | ||
|
||
if !exists("g:tokei_buf_size") | ||
let g:tokei_buf_size = 13 | ||
endif | ||
|
||
" Mark a buffer as scratch | ||
function! s:ScratchMarkBuffer() | ||
setlocal buftype=nofile | ||
" make sure buffer is deleted when view is closed | ||
setlocal bufhidden=wipe | ||
setlocal noswapfile | ||
setlocal buflisted | ||
setlocal nonumber | ||
setlocal statusline=%F | ||
setlocal nofoldenable | ||
setlocal foldcolumn=0 | ||
setlocal wrap | ||
setlocal linebreak | ||
setlocal nolist | ||
endfunction | ||
|
||
" Return the number of visual lines in the buffer | ||
fun! s:CountVisualLines() | ||
let initcursor = getpos(".") | ||
call cursor(1,1) | ||
let i = 0 | ||
let previouspos = [-1,-1,-1,-1] | ||
" keep moving cursor down one visual line until it stops moving position | ||
while previouspos != getpos(".") | ||
let i += 1 | ||
" store current cursor position BEFORE moving cursor | ||
let previouspos = getpos(".") | ||
normal! gj | ||
endwhile | ||
" restore cursor position | ||
call setpos(".", initcursor) | ||
return i | ||
endfunction | ||
|
||
" return -1 if no windows was open | ||
" >= 0 if cursor is now in the window | ||
fun! s:TokeiGotoWin() "{{{ | ||
let bufnum = bufnr( g:tokei_buf_name ) | ||
if bufnum >= 0 | ||
let win_num = bufwinnr( bufnum ) | ||
" Will return negative for already deleted window | ||
exe win_num . "wincmd w" | ||
return 0 | ||
endif | ||
return -1 | ||
endfunction "}}} | ||
|
||
" Close tokei Buffer | ||
fun! TokeiClose() "{{{ | ||
let last_buffer = bufnr("%") | ||
if s:TokeiGotoWin() >= 0 | ||
close | ||
endif | ||
let win_num = bufwinnr( last_buffer ) | ||
" Will return negative for already deleted window | ||
exe win_num . "wincmd w" | ||
endfunction "}}} | ||
|
||
" Open a scratch buffer or reuse the previous one | ||
fun! TokeiGet() "{{{ | ||
let last_buffer = bufnr("%") | ||
|
||
if s:TokeiGotoWin() < 0 | ||
new | ||
exe 'file ' . g:tokei_buf_name | ||
setl modifiable | ||
else | ||
setl modifiable | ||
normal ggVGd | ||
endif | ||
|
||
call s:ScratchMarkBuffer() | ||
|
||
execute '.!tokei -e' . g:tokei_exclude | ||
setl nomodifiable | ||
|
||
let size = s:CountVisualLines() | ||
|
||
if size > g:tokei_buf_size | ||
let size = g:tokei_buf_size | ||
endif | ||
|
||
execute 'resize ' . size | ||
|
||
nnoremap <silent> <buffer> q <esc>:close<cr> | ||
endfunction "}}} | ||
|
||
command! Tokei call TokeiGet() | ||
map <silent> co :Tokei<CR> | ||
" -nargs=* |