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.
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
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
Vim comes pre-installed on macOS, but you can install the latest version using Homebrew.
brew install vim
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
Vim Plug is a plugin manager for Vim. It makes installing and managing Vim plugins easy and efficient.
sudo apt install -y curl
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
brew install curl
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Git is essential for version control and managing code changes.
Install the latest version of Git
sudo add-apt-repository ppa:git-core/ppa
sudo apt install -y git
brew install git
NERDTree is a file system explorer that provides a visual way to navigate directories and files.
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
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get install -y golang
brew install go
This plugin provides Go language support for Vim.
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
Codeium is an AI-powered coding assistant that integrates with Vim, providing intelligent code completions and suggestions to enhance your coding workflow.
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.
For Perl development, installing these packages ensures a robust environment.
sudo apt install -y build-essential cpanminus perltidy libperl-critic-perl exuberant-ctags
brew install cpanminus
brew install perltidy
brew install ctags`
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine and is essential for modern web development.
curl -sL install-node.vercel.app/lts | bash
brew install node
CoC (Conquer of Completion) is an intellisense engine for Vim.
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)
These customizations include setting the filename and branch name in the status bar.
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()}
Managing tabs efficiently in Vim can significantly enhance your coding workflow, allowing you to switch between different files and projects seamlessly.
First, install fzf
, a general-purpose command-line fuzzy finder, which is a powerful tool for file searching and tab management.
sudo apt-get install fzf
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