|$ curl https://forge-ai.dev/api/markdown?path=docs/linux/vim
$cat docs/vim.md
updated Recently·20 min read·published

vim

LinuxvimEditorCLIBeginner to Intermediate🎯Free Tools
Introduction

vim is a modal text editor found on virtually every Unix-like system. Learning the basics lets you edit config files, write code, and fix issues on remote servers where graphical editors are unavailable.

Modes

vim is modal. The same key does different things depending on the current mode.

ModeEnter WithPurpose
NormalEscNavigation and commands
Inserti, a, oTyping text
Visualv or VSelecting text
Command-line:Ex commands like save and quit
Editing
vim-editing.txt
TEXT
1i # insert before cursor
2a # append after cursor
3o # open new line below
4O # open new line above
5x # delete character under cursor
6dd # delete line
7yy # yank (copy) line
8p # paste after cursor
9P # paste before cursor
10u # undo
11Ctrl + r # redo
12r # replace single character
13cw # change word
14ci" # change inside quotes
Saving & Quitting
vim-save.txt
TEXT
1:w # save
2:wq # save and quit
3:x # save and quit
4:q # quit
5:q! # quit without saving
6:w !sudo tee % # save with sudo
A Practical .vimrc
.vimrc
VIM
1" ~/.vimrc
2set number " show line numbers
3set relativenumber " relative line numbers
4set tabstop=2
5set shiftwidth=2
6set expandtab " use spaces instead of tabs
7set smartindent
8set wrap
9set hlsearch " highlight search matches
10set incsearch " incremental search
11set ignorecase " case-insensitive search
12set smartcase " case-sensitive if uppercase used
13set clipboard=unnamedplus " use system clipboard
14set mouse=a " enable mouse in all modes
15syntax on
16filetype plugin indent on

info

Start with vimtutor in your terminal for a 30-minute hands-on introduction.