VIM
Intro
Vim is a powerful and highly configurable text editor that is popular among developers, system administrators, and anyone who works extensively with text. Renowned for its efficiency, Vim allows users to perform complex editing tasks with minimal keystrokes, making it an essential tool for productivity once mastered. Though its interface may seem intimidating at first, Vim’s modal editing system—where different modes like insert, command, and visual are used for specific tasks—provides unparalleled control over text manipulation. Whether you’re editing code, writing documentation, or simply taking notes, Vim is designed to adapt to your needs and help you work faster. While the learning curve may be steep, Vim’s rewards are well worth the effort.
History
ed
ed
is one of the earliest text editors, developed by Ken Thompson in 1971 as part of the original UNIX operating system. It is a line editor, meaning users edit text line-by-line, which was practical for the teletype terminals of the time. Despite its simplicity, ed
introduced concepts like regular expressions and became the foundation for many subsequent editors.
Key Features 🔑
Operates in a command-line interface.
Supports regular expressions for search and replace.
Basis for ex
, the precursor to vi
.
Learn more: ed (Wikipedia)
vi
vi
, short for visual editor, was developed by Bill Joy in 1976 for the Berkeley Software Distribution (BSD) of UNIX. It expanded on ex
by introducing a visual mode, allowing users to see the text being edited in real-time. vi
quickly became the default text editor in many UNIX systems due to its powerful modal editing capabilities.
Key Features 🔑
Modal editing: command mode, insert mode, and visual mode. Highly efficient for keyboard-based navigation and text manipulation. Portable and lightweight, available on nearly every UNIX-based system. Learn more: vi (Wikipedia)
vim
vim
(Vi IMproved) was created by Bram Moolenaar in 1991 as an extended version of vi
. Written for the Amiga computer, vim
was designed to provide more features while maintaining compatibility with vi
. Over time, vim
became the de facto standard for advanced text editing, with extensive customization options and support for plugins.
Key Features 🔑
Syntax highlighting, multiple buffers, and tabbed editing. Extensible through plugins and scripting (via Vimscript). Cross-platform and widely adopted for programming and system administration. Learn more: vim (Wikipedia)
neovim
neovim
is a modern fork of vim
, launched in 2014 by Thiago de Arruda. It aims to refactor vim
's codebase to improve maintainability and enable new features. neovim
introduces modern integration, asynchronous processing, and an enhanced user experience, making it particularly appealing for developers.
Key Features 🔑
Built-in support for asynchronous plugins and language servers (LSP). Improved user interface capabilities (e.g., external GUI frontends). Configuration through Lua in addition to Vimscript. Focus on extensibility and community-driven development. Learn more: neovim (Wikipedia)
Timeline Summary
- 1971:
ed
introduced as the original UNIX editor. - 1976:
vi
adds a visual mode toed
andex
. - 1991:
vim
improves onvi
with modern features. - 2014:
neovim
modernizesvim
for enhanced extensibility and performance.
Resources
OpenVim: An interactive tutorial that teaches how to use Vim with a context-aware help menu. OpenVim
Vim Genius: A flashcard-styled game designed to enhance your Vim-writing skills by increasing speed and strengthening muscle memory. Vim Genius
Vim Hero: An interactive platform that teaches you how to edit code using Vim with examples, challenges, and games. Vim Hero
Vim Tutor: A built-in tutorial that comes with Vim, providing a hands-on introduction to its features. Access it by typing vimtutor
in your terminal.
VIM Commands
Basics
# by default in command mode
# i insert mode
# v visual mode
# a append mode (insert after curser)
# A append mode at end of line (shift + a)
# o open new blank line below curser and switch to insert mode
# O open new blank line above curser and switch to insert mode (shift + o)
# :q! quite without save
# :wq save and exit
# :x save and exit
# ZZ save and exit (shift + z + z)
# :w save
# :wq FILE_NAME saves as new file
# ctrl + g print current file status and curser location
# :f print current file status and curser location
# :! CMD execute externam terminal command CMD
# :r FILENAME retrieves disk file FILENAME and puts it below the cursor position
# :r !CMD reads the output of the command and puts it below the cursor position
# :syntax off turn off syntax highlighting
# :set nu show line numbers (:set nonu to hide line numbers)
Movement
# Typing a number before a motion repeats it that many times example: 2w, 3e,
# h,j,k,l to move curser by char
# w,b,e to move curser by word
# % jump to matching (,{,[ or ],},)
# (also can use W,B,E which jump only on spaces, not _ , - )
# :LINE_NO jumps to line number
# 0 jumps at start of of line = home
# $ jumps to end of line = end
# G jump to last line (shift + g)
# gg jump to first line
# ctrl + f page down
# ctrl + b page up
delete text
# x delete char under curser like Delete key
# X delete char before curser like back space (shift + x)
# dw delete word from curser until next word
# de delete word from curser until last char of current word
# D white the line from curser to end of line (shift + d)
# dd delete current line
# Number + dd delete some lines from current line to down count number
# dG deletes entire lines below (d + shift+g)
Replace text
# r + New_char replace current char with new_char
# cw delete current word and go to insert mode
# R switch to replace mode (shft + r), replace inserted char until esc
History
# u undo one step (:undo)
# U undo total chages of current line (shift + u)
# ctrl + r redo one step (:redo)
Copy, paste
# yy copy current line
# yw copy one word,
# Number + yw copy Number of words (also can press y+Number+w)
# Number + yy copy number of lines below curent curser
# p paste after current line
# P paste befor current line (shift + p)
Visual Mode
# all movement keys also work in this mode
# v switch to visual mode
# y copy selected text
# d copy and delete selected text (cut)
# :w after selecting press :w FILENAME to save selected part as new FILENAME
Search & Replace
# /WORD search forward
# ?WORD search backward
# / + enter jump to next word found (also can press n)
# ? + enter jump to previous found (also can press N)
# :s/old/new/g to substitute 'new' for 'old' in current line (delete g to apply for first word found)
# :#,#s/old/new/g #,# are the range of lines where the substitution is to be done.
# :%s/old/new/g to change every occurrence in the whole file.
# :%s/old/new/gc to find every occurrence in the whole file, with a prompt to substitute or not
# :set xxx sets the option "xxx". Some options are:
# 'ic' 'ignorecase' ignore upper/lower case when searching
# 'is' 'incsearch' show partial matches for a search phrase
# 'hls' 'hlsearch' highlight all matching phrases
# 'no+xxx' disables xxx option
VIM Config File
VIM is configured using an 'RC' file called '.vimrc'
My Config
" vim-plug plugin manager settings
call plug#begin('~/.vim/plugged')
" Go related plugins
Plug 'fatih/vim-go' " A Go development plugin for Vim
Plug 'junegunn/fzf.vim' " Fuzzy finder plugin (optional but useful)
Plug 'preservim/nerdtree' " File explorer (optional)
" Multi-language support and autoformatting
Plug 'sbdchd/neoformat' " Autoformatter for multiple languages
Plug 'sheerun/vim-polyglot' " Syntax highlighting for many languages
" Git integration
Plug 'tpope/vim-fugitive' " Git commands within Vim
call plug#end()
" Enable vim-go features
let g:go_fmt_command = "gopls" " Use gopls for formatting
let g:go_auto_type_info = 1 " Show Go type info on hover
let g:go_highlight_fields = 1 " Highlight struct fields
" NERDTree configuration
nnoremap <C-n> :NERDTreeToggle<CR> " Toggle NERDTree with Ctrl-n
" Enable line numbers
set number
" Highlight the current line
set cursorline
" Enable syntax highlighting
syntax on
" Set color scheme (choose your favorite or install custom themes)
colorscheme desert
" Use spaces instead of tabs
set expandtab
" Set the number of spaces per tab
set tabstop=4
" Set the number of spaces used for auto-indenting
set shiftwidth=4
" Enable smart indentation
set smartindent
" Enable auto-indentation
set autoindent
" Highlight matching parentheses
set showmatch
" Enable line wrapping
set wrap
" Display line wrap characters
set list
set listchars=tab:»·,trail:·,extends:>,precedes:<
" Enable mouse support
set mouse=a
" Show the status line
set laststatus=2
" Enable line numbers relative to the cursor
set relativenumber
" Highlight search results
set hlsearch
" Incremental search
set incsearch
" Ignore case in search patterns
set ignorecase
set smartcase
" Enable persistent undo
set undofile
set undodir=~/.vim/undodir
" Enable clipboard integration
set clipboard=unnamedplus
" Set a better command line height for displaying messages
set cmdheight=2
" Show line and column numbers in the status line
set ruler
" Enable filetype plugins and indentation
filetype plugin indent on
" Automatically reload files changed outside of Vim
set autoread
" Disable audible bell
set noerrorbells
set visualbell
" Prevent accidental closing of unsaved files
set confirm
" Better scrolling experience
set scrolloff=8
set sidescrolloff=8
" Automatically save and source this file after editing
autocmd BufWritePost ~/.vimrc source ~/.vimrc
" Neoformat configuration for autoformatting
let g:neoformat_enabled_rust = ['rustfmt']
let g:neoformat_enabled_python = ['black']
let g:neoformat_enabled_go = ['gofmt']
let g:neoformat_enabled_php = ['php-cs-fixer']
let g:neoformat_enabled_sql = ['sqlformat']
let g:neoformat_enabled_html = ['tidy']
let g:neoformat_enabled_css = ['tidy']
let g:neoformat_enabled_tailwind = ['prettier']
let g:neoformat_enabled_c = ['clang-format']
let g:neoformat_enabled_cpp = ['clang-format']
let g:neoformat_enabled_yaml = ['yamlfmt']
let g:neoformat_enabled_toml = ['taplo']
let g:neoformat_enabled_xml = ['xmllint']
let g:neoformat_enabled_ansible = ['ansible-lint']
let g:neoformat_enabled_terraform = ['terraform']
let g:neoformat_enabled_markdown = ['mdformat']
let g:neoformat_enabled_ini = ['configparser']
" Autoformat on save
autocmd BufWritePre *.rs,*.py,*.go,*.php,*.sql,*.html,*.css,*.c,*.cpp,*.yaml,*.toml,*.xml,*.yml,*.tf,*.md,*.ini Neoformat
This is a demonstration of the compilation process.