< Back

How to Setup Vim for Software Development

  1. System Package Update
  2. Vim Installation
  3. Vim Basic Configuration
  4. Plugin Management with Vim Plug
  5. Git Integration
  6. NERDTree Installation and Configuration
  7. Codeium Setup for Vim
  8. Golang Environment Setup
  9. Vim-Go Plugin for Golang Development
  10. Perl Development Environment
  11. Node.js Installation
  12. AutoCompletion with CoC.nvim
  13. Additional Vim Customizations
  14. Tab Management in Vim

Introduction

Setting up your development environment is crucial for efficient and comfortable coding. Vim, being a highly configurable text editor, allows you to tailor your environment specifically to your needs. This guide will help you set up Vim for a robust software development setup on both Ubuntu and macOS systems.

1. Update System Packages

Ubuntu

To ensure that you have the latest versions of packages and their dependencies, update your system's package list. This step helps prevent compatibility issues and ensures your system is secure.

sudo apt update sudo apt install -y software-properties-common

2. Install Vim

Ubuntu

Installing Vim from a PPA (Personal Package Archive) ensures you get the latest version with all new features and patches.

sudo add-apt-repository ppa:jonathonf/vim sudo apt install -y vim

macOS

Vim comes pre-installed on macOS, but you can install the latest version using Homebrew.

brew install vim

3. Configure Vim Settings

This step involves setting up Vim to behave in a way that enhances your development experience. These settings include indentation, tab size, and other essential editing features.

filetype plugin indent on set autoindent expandtab tabstop=4 shiftwidth=4 set expandtab set tabstop=4 set shiftwidth=4 set nu set noswapfile set hlsearch set autowrite filetype plugin indent on

4. Install Vim Plug

Vim Plug is a plugin manager for Vim. It makes installing and managing Vim plugins easy and efficient.

Ubuntu

sudo apt install -y curl curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

macOS

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

5. Install Git

Git is essential for version control and managing code changes.

Ubuntu

Install the latest version of Git

sudo add-apt-repository ppa:git-core/ppa sudo apt install -y git

macOS

brew install git

6. Install and Configure NERDTree for Vim

NERDTree is a file system explorer that provides a visual way to navigate directories and files.

Common Steps for Ubuntu and macOS

call plug#begin() Plug 'preservim/nerdtree' call plug#end() map <C-z> :NERDTreeToggle<CR>10<C-w>x map <C-t> :term<CR><C-w>r<C-w>-<C-w>-<C-w>-<C-w>-<C-w>-<C-w>-<C-w>-<C-w>-<C-w>-<C-w>-<C-w>-<C-w>- let g:NERDTreeDirArrowExpandable = '▸' let g:NERDTreeDirArrowCollapsible = '▾' """ Show hidden files let NERDTreeShowHidden=1

7. Install Golang

Ubuntu

sudo add-apt-repository ppa:longsleep/golang-backports sudo apt-get install -y golang

macOS

brew install go

8. Install Vim Go Plugin

This plugin provides Go language support for Vim.

Common Steps for Ubuntu and macOS

git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go

Add these lines in ~/.vimrc:

call plug#begin() Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' } call plug#end() """ Go syntax highlighting let g:go_highlight_fields = 1 let g:go_highlight_functions = 1 let g:go_highlight_function_calls = 1 let g:go_highlight_extra_types = 1 let g:go_highlight_operators = 1 """ Auto formatting and importing let g:go_fmt_autosave = 1 let g:go_fmt_command = "goimports" """ Status line types/signatures let g:go_auto_type_info = 1 """ Run :GoBuild or :GoTestCompile based on the go file function! s:build_go_files() let l:file = expand('%') if l:file =~# '^\f\+_test\.go$' call go#test#Test(0, 1) elseif l:file =~# '^\f\+\.go$' call go#cmd#Build(0) endif endfunction """ Map keys for most used commands. """ Ex: `\b` for building, `\r` for running and `\b` for running test. autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR> autocmd FileType go nmap <leader>r <Plug>(go-run) autocmd FileType go nmap <leader>t <Plug>(go-test) autocmd FileType go inoremap <buffer> . .<C-x><C-o>

Run this in vim :PlugInstall

9. Install Codeium AI for Vim (Like Github Copilot)

Codeium is an AI-powered coding assistant that integrates with Vim, providing intelligent code completions and suggestions to enhance your coding workflow.

Common Steps for Ubuntu and macOS

To install Codeium for Vim, you'll need to use Vim Plug, which you've already set up in a previous step. Follow these commands:

call plug#begin() Plug 'Exafunction/codeium.vim', { 'branch': 'main' } call plug#end()

After adding these lines to your Vim configuration, run the following commands inside Vim:

:PlugInstall :Codeium Auth

This will complete the installation process and require you to authenticate for accessing Codeium's features.

10. Install Perl and Toolchains

For Perl development, installing these packages ensures a robust environment.

Ubuntu

sudo apt install -y build-essential cpanminus perltidy libperl-critic-perl exuberant-ctags

macOS

brew install cpanminus brew install perltidy brew install ctags`

11. Install NodeJS

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine and is essential for modern web development.

Ubuntu

curl -sL install-node.vercel.app/lts | bash

macOS

brew install node

12. Install AutoCompletion with CoC.nvim

CoC (Conquer of Completion) is an intellisense engine for Vim.

Common Steps for Ubuntu and macOS

call plug#begin() Plug 'neoclide/coc.nvim', {'branch': 'release'} call plug#end() nmap <silent> gd <Plug>(coc-definition) nmap <silent> gD <Plug>(coc-implementation) nmap <silent> gr <Plug>(coc-references)

13. Additional Vim Customizations

These customizations include setting the filename and branch name in the status bar.

Common Steps for Ubuntu and macOS

Add this to your ~/.vimrc:

call plug#begin() Plug 'tpope/vim-fugitive' call plug#end() set laststatus=2 set statusline=%F%m%r%h%w\ [%{&fileformat}]\ [%Y]\ %{fugitive#Head()}

14. Setting Up Tabs in Vim

Managing tabs efficiently in Vim can significantly enhance your coding workflow, allowing you to switch between different files and projects seamlessly.

Common Steps for Ubuntu and macOS

First, install fzf, a general-purpose command-line fuzzy finder, which is a powerful tool for file searching and tab management.

Ubuntu

sudo apt-get install fzf

macOS

brew install fzf

Then, set up the tabline and integrate fzf with Vim for enhanced tab management:

call plug#begin() Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' call plug#end() set showtabline=2 " Always show the tabline set tabline=%!MyTabLine() function! MyTabLine() let s = '' for i in range(tabpagenr('$')) " Select the highlighting if i + 1 == tabpagenr() let s .= '%#TabLineSel#' else let s .= '%#TabLine#' endif " Set the tab page number (i + 1) let s .= '%' . (i + 1) . 'T' " Add the tab number let s .= ' ' . (i + 1) . '.' " Get the buffer name for each tab let buflist = tabpagebuflist(i + 1) let bufnr = buflist[0] let bufname = bufname(bufnr) " Add the buffer name let s .= ' ' . fnamemodify(bufname, ':t') . ' ' " Close the tab page label let s .= '%T' endfor " After the last tab fill with TabLineFill and reset tab page nr let s .= '%#TabLineFill#%T' return s endfunction


< Back