Jan 11, 2022

Plugins for VI or VIM Editor

Here's my note on learning how to configure plugins for my VIM.

VIM is extensible through plugins. There are 2 ways to install VIM plugins, either by manually or with a package manager.

VIM plugins provide extra features for typing text. With the right mix of plugins, we can take control of VIM and forge our unique VIM experience. Such as:

  • Customize theme color
  • syntax highlight
  • code linting

 

Install Plugins Manually (for vim 8.x and above)

1.0 Create the directory structure for storing plugins.

$ mkdir -p ~/.vim/pack/vendor/start

$ mkdir ~/.vim/pack/vendor/opt

2.0 Install a plugin NERDTree, text-based file manager for VIM, so that it will be loaded automatic.

$ git clone --depth 1 \
  https://github.com/preservim/nerdtree.git \
  ~/.vim/pack/vendor/start/nerdtree

 2.1 Launch VIM and strt NERDTree.

:NERDTree

3.0 You also can add a plugin but only load it when you need the plugin.

$ git clone --depth 1 \
  https://github.com/preservim/nerdtree.git \
  ~/.vim/pack/vendor/opt/nerdtree

3.1 To load the plugin into memory, for current session.

:packadd NERDTree

4.0  Note for organizing each plugin in directory.

$ mkdir -p ~/.vim/pack/NERDTree/start/
$ git clone --depth 1 \
  https://github.com/preservim/nerdtree.git \
  ~/.vim/pack/NERDTree/start/NERDTree
$ mkdir -p ~/.vim/pack/foo/start/
$ git clone --depth 1 \
  https://notabug.org/foo/foo.git \
  ~/.vim/pack/foo/start/foo


Using VIM Package Manager (any vim version)

1. Install vim-plug with:

$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

2. Create ~/.vimrc file and enter this text:

call plug#begin()
Plug 'preservim/NERDTree'
call plug#end()

3. Install the plugins (listed in ~/.vimrc), and wait for it finishes:

:PlugInstall

4. Update all plugins with vim-plug.

:PlugUpdate

:PlugUpdate NERDTree

5. Restore plugins. vim-plug has this command to generate a script restoring all the current plugins.

:PlugSnapshot ~/vim-plug.list


Below is my current ~/.vimrc configuration.

~/.vimrc

Links: