My vim setup on Raspberry Pi

Make vim your default editor on your raspberry pi and find out how to add some custom plugins.

My vim setup on Raspberry Pi

I use vim in a lot of these tutorials on this blog (probably most of them) so I thought I'd let you know how I set it up quickly. It's well worth the learning curve and it's super lightweight and very extendable. Vim is a basic terminal based editor and it was released in 1991 as an improved version of vi, hence it's name vi improved = vim.

Vim is rock stable and is continuously being developed to become even better. Among its features are:

  • persistent, multi-level undo tree
  • extensive plugin system
  • support for hundreds of programming languages and file formats
  • powerful search and replace
  • integrates with many tools

Setup

First lets install the full version of vim open up your terminal and run the following commands:

sudo apt update
sudo apt install vim

Make vim default

Now we have it installed we need to make it the default editor on the system so you don't get things like nano popping up when you edit the sudoers file for example!

In the command prompt again, run the following command:

sudo update-alternatives --config editor

You'll now be faced with a menu in the terminal that looks like the following:

There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    15        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Here you want to choose /usr/bin/vim.basic as your option, for me I press 3 and then Enter. The response on the terminal should say:

update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode

Now when you run commands such as visudo it'll use the vim editor and not the default of nano. Same goes for when you type vi it'll actually now run vim.

Custom plugins for vim

If you want to make vim a little more exciting as an editor you could follow this awesome guide https://github.com/amix/vimrc which will help you add some cool features, I personally switch on syntax highlighting and line numbers on all my configs.

💡
Remember to quit vim just press ESC followed by :wq and then Enter this will Write and Quit vim for you. If you don't want to save your changes type :q!

If you want more tips and trick on how to use the editor check out vim tips on fandom https://vim.fandom.com/wiki/Vim_Tips_Wiki

Conclusion

I'm biased here and love vim, I've learned the shortcuts over many years and it's natural now, from search and replace commands :1,$ s/Find/Replace/g to advanced file manipulation. It's also fun that you can always be shown a new trick and learn something.

Pro's

  • super light weight (it's not emacs size!)
  • available for every system
  • fun to learn all the commands, and then learn even more

Con's

  • steep learning curve

PiSource Score

Ease of Setup Features Ease of Use Extendability Total
9 10 5 10 34/40

In reality I score this 1000/40 ;)