Index ¦ Archives ¦ Atom ¦ RSS

Advanced Vim Management on Debian: Transitioning to vim-plug and NERDTree

In our previous explorations of the Debian environment, we examined how the system manages the relationship between vi and vim.tiny. While the default minimalist setup is excellent for system recovery, a modern development workflow requires more power. This post guides you through upgrading to vim-nox and implementing vim-plug, the industry standard for high-performance plugin management, alongside the NERDTree file explorer.


The Importance of vim-nox

Before installing a manager, it is essential to ensure you are using the correct Vim binary. Debian's base installations often rely on vim-tiny, which lacks the scripting support required for many modern enhancements.

We recommend installing vim-nox, which is compiled with support for scripting languages like Python 3. This is particularly effective when paired with a plugin manager, as it enables parallel installations and asynchronous updates.

sudo apt update
sudo apt install vim-nox -y

Implementing vim-plug

vim-plug is a beautiful, minimalist manager consisting of a single .vim file. It provides a clean syntax for managing plugins directly within your configuration and offers significant speed advantages through parallel power.

Installation

To set up the manager, download the plug.vim file into your local autoload directory (~/.vim/autoload/) using curl:

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

Configuring ~/.vimrc

With the manager installed, you can now define your plugins. Open your personal ~/.vimrc file and wrap your plugin declarations between the plug#begin() and plug#end() calls:

" --- VIM-PLUG SECTION ---
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')

" List your plugins here
Plug 'preservim/nerdtree'         " File system explorer

" Initialize the plugin system
call plug#end()

Finalizing the Setup

After saving your ~/.vimrc, restart Vim or source the file, then execute the installation command:

:PlugInstall

Automating NERDTree

Once NERDTree is installed, you can configure it to launch automatically whenever Vim is started. This creates a more "IDE-like" experience while retaining the speed of a terminal editor.

Auto-Launch Logic

Add the following block to your ~/.vimrc to automate the explorer startup and ensure the cursor moves to the editing window rather than staying in the sidebar:

" Start NERDTree when Vim is started
autocmd VimEnter * NERDTree

" Move the cursor to the editing window automatically
autocmd VimEnter * wincmd p

" Close Vim if NERDTree is the only window left open
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

" Optional: Map Ctrl+n to toggle NERDTree manually
map <C-n> :NERDTreeToggle<CR>

A Note on the Native Alternative

Modern versions of Vim (Debian 8 and newer) include a native package system. This allows users to manually manage plugins by cloning them into the ~/.vim/pack/vendor/start/ directory.

While this approach avoids third-party managers, it lacks automated functionality for updates, cleaning unused directories, or parallel installation. For a personalized setup that you plan to grow over time, vim-plug remains the superior choice because it automates the "management" aspect of your environment while adhering to a minimalist philosophy.


Finishing Touches

To maintain the 'pure' experience we've previously discussed, ensure your ~/.bash_aliases still includes a shortcut for quick edits without the overhead of your new plugins or the automatic NERDTree sidebar:

# Run vi without loading plugins or user configurations
alias vi="vim -u NONE"

This ensures that while your environment grows in power, you never lose the ability to return to the minimalist roots of the editor when the situation demands it.

© Porfirio Páiz. Built using Pelican. Theme by Giulio Fidente on github.