What was your first text editor when you started using Linux/Unix? Mine was pico. It was very easy to get started with and quite similar to nano. Then I moved to emacs and sticked with it for a long while. Eventually, I’ve switched to vim (or neovim), and that’s what I have been using until now.

Well, the thing about text editor or may be this also applies to many other things, you’re only familiar with features that you constantly use. This means I only know a small subsets of what vim can do.

Today I came across a problem (or a feature) in vim running on FreeBSD. The issue with the automatic string replacement - everytime I type or copy string contains 256, it’s automatically replaced by <t_CO>.

For example, in the following text file AES256 is replaced by AES<t_CO>.

zabbix_agent_psk_key: !vault |

I didn’t know why! I tried to search for helps on Google a few times with hit and miss. Then, the last search pointed me to the right direction.

The problem was caused by a variable defined in vim configuration: ~/.vimrc. This can be confirmed by searching for t_CO in that file.

❯❯❯ rg t_CO ~/.vimrc
31:set t_CO=256                         "Use 256 colors. This is useful for Terminal Vim.

According to brammool, the name of the variable to be set in ~/.vimrc should be t_Co not t_CO!

Let’s fix this by updating the variable in .vimrc to t_Co.

On FreeBSD, sed command is slightly different to sed on Linux. I have to pass an empty string ('') after -i to indicate that I don’t want to make a backup file for the original one.

❯❯❯ sed -i '' 's/t_CO/t_Co/g' ~/.vimrc

Let’s verify this:

❯❯❯ rg 't_C[o|o]' ~/.vimrc 
31:set t_Co=256                         "Use 256 colors. This is useful for Terminal Vim.

Restart vim and 256 no longer gets replaced by <t_CO>!

Read more: