Calling eh
from vim
I use vim, and I occasionally write Elixir code.
Vim has built-in support for looking up documentation, keywordprg
.
So since I wanted to be able to look up Elixir documentation from vim,
I wrote an elixir package called eh
, which is available on hex.
To call eh
from vim, add the following to your .vimrc:
au FileType elixir setlocal keywordprg=mix\ eh
This tells vim to use mix eh
for looking up keywords.
Vim and keywords
There is however a small caveat here, in how vim chooses what is a
keyword. By default, vim does not consider periods (.) to be part of a
keyword, and in Elixir, you will most likely want to look up
documentation using mix eh MyModule.my_function
.
There are a few ways of solving this:
-
Use my vim-eh-docs plugin, that uses some of the below techniques to look up module or function documentation using
<leader>k
. -
Add
.
toiskeyword
:au FileType elixir setlocal iskeyword+=.
This will likely mess up your syntax highlighting, and possibly cause other issues.
-
Add a new mapping to your .vimrc:
au FileType elixir noremap <Leader>k eBvt(K
This will make
\k
visually select from the start of the current word to the next instance of(
on that line, and then hitK
to look up documentation usingmix eh
.It will not work if you are not always using parentheses when calling functions, or when omitting parentheses because the function called takes no arguments.
-
Overload
K
:au FileType elixir noremap K eBvt(K
This line overloads
K
to select what is most likely the keyword under the cursor. It selects the keyword you are currently on, and then hitsK
.Like the above above, new mapping, this will not work when there are no parentheses.
Also, this will render it impossible to manually select those corner cases using
eBvt K
oreBvt$K
instead.If anyone has a better way of automatically selecting these, please let me know.