LunarVim: Tabnine AI Coding Assistant

chris@machine
𝐀𝐈 𝐦𝐨𝐧𝐤𝐬.𝐢𝐨
3 min readMay 7, 2023

--

In this article, we’ll explore the benefits of integrating TabNine’s AI-driven autocompletion with LunarVim. By the end of this article, you’ll understand how to set up and use this combination to enhance your coding experience.

Note: I’ll be taking a look at the free version of tabnine, so this will be accessible for everyone

Installing Tabnine

First we’ll need to install the tabnine extension for cmp. Cmp is the autocomplete plugin that LunarVim uses for autocomplete. We’ll need to run the install.sh after downloading the plugin. So open up your config.lua file under ~/.config/lvim/config.lua and add the following:

lvim.plugins = {
{
"tzachar/cmp-tabnine",
event = "BufRead",
build = "./install.sh",
},
}

After adding the plugin close and restart the editor, it will take a few seconds to install since it needs to run that install.sh script which will download the Tabnine binary.

Sign Up for Tabnine

After the install is complete the plugin should automatically open up your default web browser prompting you to sign up for Tabnine.

Tabnine Login Page

After signing up you will be taken to the Tabnine Hub where you can change your settings and upgrade to the pro model if you want. Also make sure to check you email to verify your account.

Tabnine Hub

Testing Out Completions

Tabnine gives short completions out of the box for free with their starter package. LunarVim does all of the integration for you and will show a little magenta robot next to the completions provided by Tabnine. Above you can see it has enough context to complete the multiply function, but you won’t see multiline completion with their basic package. Still this can be pretty useful.

Tabnine as a Writing Assistant

One area where I think the basic Tabnine plugin shines is as a simple writing assistant. When I’m writing in markdown files often Tabnine is 1 or 2 words ahead of me which can help when you’re trying think about what to say next.

Ignoring Filetypes

You can refer to the plugin repo for all of the configuration options, but I wanted to include this option in case you want to disable Tabnine for a particular filetype. The following will disable tabnine for all lua files.

local tabnine = require('cmp_tabnine.config')

tabnine:setup({
ignored_file_types = {
lua = true
},
})

Commands

This plugin also includes a couple helpful commands as well:

  • The following command will open up your Tabnine hub allowing you do change your tabnine settings.
:CmpTabnineHub
  • The prefetch command will allow Tabnine to process your file before before you invoke any completions. Checkout the repo for more examples on how to use this command.
:CmpTabninePrefetch some_file_path

Note: you can press tab after :CmpTabninePrefetch to get a completion menu for different files. You can also use % for the current file.

Conclusion

With the free version of TabNine, you can enjoy context-aware code suggestions. This seamless integration with LunarVim’s native autocompletion further enhances your workflow, allowing you to focus on writing high-quality code while getting the occasional context aware suggestion.

References

--

--