diff options
author | Joey Shi | 2022-10-31 06:29:28 +0000 |
---|---|---|
committer | Joey Shi | 2022-10-31 06:29:28 +0000 |
commit | 307dcac31ed317b9f8439bcb766fa599e6c4efa7 (patch) | |
tree | ec723414b5fd4a1b80e4d33f06f018cf403ef5bd /entries/joeyshi12/vimscript/fib.vim | |
parent | 6f19316d1f4213771cde72ca2fb17c4f8bd4b9f5 (diff) |
very cool vimscript
Diffstat (limited to 'entries/joeyshi12/vimscript/fib.vim')
-rw-r--r-- | entries/joeyshi12/vimscript/fib.vim | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/entries/joeyshi12/vimscript/fib.vim b/entries/joeyshi12/vimscript/fib.vim new file mode 100644 index 0000000..b385049 --- /dev/null +++ b/entries/joeyshi12/vimscript/fib.vim @@ -0,0 +1,28 @@ +" Add me to your .vimrc :] + +function! Fib(n) + if a:n == 0 + return "0" + elseif a:n == 1 + return "0,1" + endif + let sequence = "0,1" + let prev = 0 + let curr = 1 + let iter = 2 + while iter <= a:n + let curr = prev + curr + let prev = curr - prev + let sequence .= "," . curr + let iter += 1 + endwhile + return sequence +endfunction + +function! AppendFib(n) + execute "normal! i" . Fib(a:n) . "\<Esc>" +endfunction + +" Map AppendFib to \fib +:command! -nargs=1 AppendFib :call AppendFib(<q-args>) +nnoremap <Leader>fib :AppendFib<Space> |