Using autocomplete function in Vim

Zhihau Shiu
2 min readApr 25, 2022
photo from Pexels

When I edit a markdown file, there are some keywords have to create links. I have to open Chrome browser and search every word on Google. Coping the URL from the location bar. Pasting to my editor. It’s so boring. If I find a keyword once, and record the keyword and URL pair to a text file. Next time I come across the same keyword. Can I press a key to bring URL string to the file? Yes, I can. Vim editor has an autocomplete function can do that.

Using abbr command. We can define a key value pair. Every time I type the key string with or key. It will bring the value to the file. It's really cool. For instance, I type :abbr vlang https://vlang.io/ on command mode. Then when you edit the file, type vlang to bring string https://vlang.io/ to the file. If you want to be stricter, you can format the key to start with a capital letter.

:abbr Vlang https://vlang.io/

How to keep the setting permanently? Let’s add something to the vimrc file. Open vimrc via the command e $MYVIMRC.

--

--

Zhihau Shiu

Hi! My name is Zhihau Shiu. I am a developer. I like to build some useful tool for myself. You can find them at Github.Zhihau.