The documentation files are stored are text files in $VIMRUNTIME/doc
. You can start the documentation by just calling one of the filesnames, eg: :help usr_41.txt
You can get a list of these files with the glob()
function:
:echo glob("$VIMRUNTIME/doc/*.txt", '', 1)
['/usr/share/vim/vim74/doc/arabic.txt', '/usr/share/vim/vim74/doc/autocmd.txt', ...]
However, as far as I know there is no straight-forward way of getting a random item of a list, but How to generate random numbers? lists a number of work-arounds. All them use an external tool to do so.
Since we're using an external tool (I used Python here) , we might as well use that for getting the files:
:py import glob, random; print(random.choice(glob.glob(vim.eval("$VIMRUNTIME") + '/doc/*.txt'))
/usr/share/vim/vim74/doc/indent.txt
And to open a help page:
:py import vim, glob, random, os; vim.command (':help ' + os.path.basename(random.choice(glob.glob(vim.eval("$VIMRUNTIME") + '/doc/*.txt'))))
As a one-liner it's a bit unreadable, so here's a script which does the same, but more readable:
fun! RandomHelp()
python << EOF
import vim, glob, random, os
all_pages = glob.glob(vim.eval("$VIMRUNTIME") + '/doc/*.txt')
random_page = os.path.basename(random.choice(all_pages))
vim.command(':help ' + random_page)
EOF
endfun
Or if you don't have Python, you could use the shell:
:execute ':help ' . system("ls $VIMRUNTIME/doc/ | shuf -n1")
Note that shuf
is a non-standard tool, and may not be available on your system.