Skip to content

Instantly share code, notes, and snippets.

@Sanix-Darker
Created May 15, 2023 08:46
Show Gist options
  • Save Sanix-Darker/defeec3509778bdc06b2c034050f9840 to your computer and use it in GitHub Desktop.
Save Sanix-Darker/defeec3509778bdc06b2c034050f9840 to your computer and use it in GitHub Desktop.
random pick name from buffer with vimScript on vim
" vimScript
" -- On dailies, for random choice on given buffer with names
function! StringInLine(line_number, search_string)
let line_text = getline(a:line_number)
let match_position = match(line_text, a:search_string)
return match_position >= 0
endfunction
function! Raffle()
let total_lines = line('$')
let random_line = (RandLine() % total_lines) + 1
let line_text = getline(random_line)
if StringInLine(random_line, '>> ')
:call Raffle()
else
let line_text = '>> ' . line_text
call setline(random_line, line_text)
endif
endfunction
function! RandLine()
return str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:])
endfunction
" -- run it with -> :call Raffle()
" by d4rk3r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment