I'd like to add commands in my
.vimrc programmatically in a function. For example, instead of hardcoding commands like this
command! MyCommand echom "My command"
I'd prefer to add them in a simple function like this
function! AddCommands() for commandName in ["One", "Two", "Three"] " TODO: Add a command with the given name that prints something endfor endfunction
How can I add the commands
Three using the for loop above?
Once I got that working, I want to read a file containing file paths and automatically create commands that open those files. I call that file "bookmarks file".
A line in the bookmarks file looks like this:
Here's what I got so far:
" Read file paths from our bookmark file " and create a command for each bookmark that, when executed, opens the " file in a new tab. function! ReadBookmarks() let bookmarks = readfile(fnameescape($BOOKMARKS_FILE)) let bookmarkSeparator = ": " for bookmark in bookmarks let nameAndPath = split(bookmark, bookmarkSeparator) let name = nameAndPath let path = nameAndPath " TODO: Add a command that opens the file in a new tab endfor endfunction