Skip to content

nilbus/VIMinar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basics

Open a file

vim [filename/directory]

vim filename +123

or inside vim

:e [filename]
:edit [filename]

Modes

Essentials

u undo

<ctrl>r redo

search

/regex search
?search backwards
/\(TODO\|FIXME\)
/\v(TODO|FIXME)
/todo/i

see :help regex and :help magic

search & replace

:%s/old/new/g

copy paste

y<motion> yank (copy)

d<motion> delete (cut)

yy yank a line

dd delete a line

5dd delete 5 lines

P paste (before cursor)

p paste (after cursor)

save & quit

:write
:w
:quit
:q
:q!
:wq
ZZ

Efficient Editing

Single-line Movement

w Forward a word (non-alpha)

W Forward a word (space)

b Back a word (non-alpha)

B Back a word (space)

e End of word (non-alpha)

E End of word (space)

^ Home (1st character on line)

0 Home (beginning of line)

$ End (end of line)

<enter> Down + Home (1st character)

- Up + Home (1st character)

t☐ Go up to the character you type next, ex: t( to the next (

T☐ Go up to the character you type next, backward

f☐ Find the character you type next

F☐ Find the character you type next, backward

; Next t or f match

, Previous t or f match

<number><command> Repeat any movement or edit number times

The new arrow keys

j down

k up

h left

l right

Moving to other lines

H Highest line on screen

M Medium line on screen

L Lowest line on screen

:100 Jump to line 100

* Search for the word under the cursor (forward)

# Search for the word under the cursor (backward)

Editing

i Insert mode (before cursor)

I Insert mode (beginning of line)

a Append (insert after cursor)

A Append (insert after cursor)

o Open a new line (before cursor)

O Open a new line (after cursor)

r☐ Replace the character under the cursor with ☐

R Replace in insert mode - type over characters

J Join lines with a space

gJ Join lines

d<motion> Delete (cut) to wherever you move next

D Delete to the end of the line

c<motion> Cchange to wherever you move next (delete + insert)

C Cchange to the end of the line

x Delete key

X Backspace key

s Swap the current character (x + insert)

S Swap the current line (cc + insert)

xp transpose teh-like typo (delete and paste-after)

. Repeat the last edit

Scrolling

^E Scroll down

^Y Scroll up

^F Forward a page (page down)

^B Back a page (page up)

^U Up 1/2 page

^D Down 1/2 page

z<enter> Scroll so cursor is at top of screen

zz or z. Scroll so cursor is at middle of screen

z- Scroll so cursor is at bottom of screen

Window Basics

^W n New window

^W s Split window

^W k or ^W <up> Move cursor up a window

^W j or ^W <down> Move cursor down a window

^W c or :q Close window

:help ^W

Buffers

:buffers buffer list

:b partOfFilename switch to buffer (tab-completable)

Opening a ton of files for use with buffers:

vi $(find . -type f)

vi * $(find rails_app/app -type f)

If you started vim with several files on the command line:

vim src/*

:next or :n next file

:prev or :N next file

Spell Checking

:set spell :help spell

Macros

qa start recording macro a. Can use any letter

q stop recording

@a replay macro a

qA append to macro a

Caveat: u undo during recording won't act the same when played back, because playback acts as a single undo action. Don't use undo when recording.

Examples:

  • adding --- to markdown
  • restructuring html tables

Indentation

== Fix indentation on current line

>> Indent current line

5>> Indent 5 lines

>> Indent current line

:set autoindent or :set ai

:set cindent

Other Stuff

Configuration

My ~/.vimrc

Set config values in vim with :set foo=bar

Ex: :set tabstop=4 # make tabs 4 characters wide :set ts=4 # make tabs 4 characters wide :set paste # don't autoindent :set paste! # same as :set nopaste

Shell commands

!rm oldfile
:w !sudo tee %
:!javac %

Help

About

Accompanying material for Nilbus' seminar on learning the VIM text editor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published