Skip to content

Vim

Commands

NORMAL

CommandDescription
ggGo to top of document
SHIFT+gGo to end of document
uUndo
:qQuit
:q!Force quit
:qwWrite buffer and quit
:xWrite buffer and quit
:hHelp
:h <keyword>Show specific help for keyword
:nohRemove highlighting
:g/<regex>/dDelete all lines with regex pattern
:s/<regex>/<replace>/gReplace regex pattern on line
:%s/<regex>/<replace>/gReplace regex pattern full document
/<search pattern>Search for specific pattern
vStarts VISUAL mode, single character
VStarts VISUAL mode, linewise
gdHighlights all instances of word cursor is pointing at
gg=GFix indentation in the document

Cursor Movement

CommandDescription
hGo left
jGo down
kGo up
lGo right
HMove to top of viewport
MMove to middle of viewport
LMove to bottom of viewport
wMove forward to start of word
WMove forward to start of word, including punctuation
eMove forward to end of word
EMove forward to end of word, including punctuation
bMove backward to start of word
BMove backward to start of word, including punctuation
0Move to beginning of line
$Move to end of line
%Move to matching character e.g. { -> }

VISUAL

This mode is enabled by command: v or V

CommandDescription
oMove to other end of marked area
awMark a word
abA block with ()
aBA block with {}
atA block with <>
ibInner block with ()
iBInner block with {}
itInner block with <>
<lineX>GV<lineY>GHighlights from lineX to lineY

Tabs & Split

CommandDescription
:tabnewCreates a new tab
CTRL+w TMove current pane into its own tab
gtNext tab
gTPrevious tab
1gtMove to first tab, swap [Int] for another tab
tabm 2Move tab to location 2 (indexed from 0)
taboClose all tabs except active
:spSplit up/down (horizontal split)
:vsSplit left/right (vertical split)
CTRL+w =Reset panes size
`CTRL+w`
CTRL+w _Expand active pane to maximal height
CTRL+w <Reduce the width of current pane
CTRL+w >Increase the width of current pane
CTRL+w 10<Reduce the width of current pane, by [Int] size
CTRL+w 10>Increase the width of current pane, by [Int] size

Project Config

  1. In project root folder create a file with name .project.vim
  2. Inside this file, add the overwrite configs
  3. Inside $HOME/.vimrc add a command to load config like the following example
command Pf4b :cd /developer/flex4business/flex4b/|:source .project.vim

Commands

Normal mode

  • :saveas [path] save file at specified path
  • :set nu Set number or unset number (force with :set nu!)

Nice commands

  • caw change in whole word with whitespace
  • ciw change in whole word
  • diw change in whole word
  • yi yank all the text inside ()
  • dt delete untill character
  • va will delete everything including char like va" deletes quotes

Enable edit mode

  • i insert mode where cursor is
  • o insert mode on next line
  • O insert mode on previous line
  • x delete single character and stay in normal mode
  • r swap a single chracter
  • dd enable delete mode
  • d -> SHIFT+g delete from cursor to end of file

Copy paste

  • v select text
  • y copy text (yank text)
  • p paste yanked text

^E Scroll window down ^Y Scroll window up ^F Scroll down one page ^B Scroll up one page gg Go to top of file


Things to structure

Text objecgt and motions

w - words s - sentences p - paragraphs t - tags

Motions

a - all i - in t - ´til f - find forward F - find backward

Commands

d delete (also cut) c - change (delete, then place in insert mode) y - yank (copy) v - visually select

Examples

Additional command

dd / yy delete/yank the current line D / C Delete/change until end of line ^ / $ move to the beginning/end of line I / A move to the beginning/end of and insert o / O Insert new line below/above current line and insert

.vimrc

set shell=/bin/bash
set noswapfile
set number "Show line numbes
set linebreak "Enable line breasks
set showmatch
set hlsearch "Highlight searches
set autoindent "Automatically indent
set shiftwidth=2 "Indent level
set smartindent
set smarttab "Enable automatic tabbing to right location
set softtabstop=2
set ruler
set expandtab "Ensure tab is space based
set showtabline=2 "Show tabline
let g:netrw_bufsettings = 'noma nomod nu nowrap ro nobl'