Skip to content

Instantly share code, notes, and snippets.

@nzjames
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzjames/125b8ccf9b1b8b64ec24 to your computer and use it in GitHub Desktop.
Save nzjames/125b8ccf9b1b8b64ec24 to your computer and use it in GitHub Desktop.
Vim Presentation
________ ++ ________
/VVVVVVVV\++++ /VVVVVVVV\
\VVVVVVVV/++++++\VVVVVVVV/
|VVVVVV|++++++++/VVVVV/'
|VVVVVV|++++++/VVVVV/'
+|VVVVVV|++++/VVVVV/'+
+++|VVVVVV|++/VVVVV/'+++++
+++++|VVVVVV|/VVV___++++++++++
+++|VVVVVVVVVV/##/ +_+_+_+_
+|VVVVVVVVV___ +/#_#,#_#,\
|VVVVVVV//##/+/#/+/#/'/#/
|VVVVV/'+/#/+/#/+/#/ /#/
|VVV/'++/#/+/#/ /#/ /#/
'V/' /##//##//##//###/
++
@nzjames
@xero
`7MMF' `7MMF' db mm
MM MM MM
MM MM `7MM ,pP"Ybd mmMMmm ,pW"Wq. `7Mb,od8 `7M' `MF'
MMmmmmmmMM MM 8I `" MM 6W' `Wb MM' "' VA ,V
MM MM MM `YMMMa. MM 8M M8 MM VA ,V
MM MM MM L. I8 MM YA. ,A9 MM VVV
.JMML. .JMML..JMML.M9mmmP' `Mbmo `Ybmd9' .JMML. ,V
,V
OOb"
vi released 1976
vim released 1991
`7MM"""Yp, db
MM Yb
MM dP ,6"Yb. ,pP"Ybd `7MM ,p6"bo ,pP"Ybd
MM"""bg. 8) MM 8I `" MM 6M' OO 8I `"
MM `Y ,pm9MM `YMMMa. MM 8M `YMMMa.
MM ,9 8M MM L. I8 MM YM. , L. I8
.JMMmmmd9 `Moo9^Yo.M9mmmP' .JMML. YMbmd' M9mmmP'
Comand mode, move around, envoke actions.
Visual mode, select stuff.
Insert mode, write text normal.
Esc exits insert mode or abandons a command
i I a A o O s
All different methods of entering insert mode a different one for each
different scenario.
Use the arrow keys and mouse to move around or
h j k l
0 $ w e b
^d ^u
gg G
u ^r
.g8"""bgd mm `7MM
.dP' `M MM MM
dM' ` ,pW"Wq. `7MMpMMMb.pMMMb. `7MMpMMMb.pMMMb. ,pW"Wq. `7MMpMMMb. mmMMmm ,6"Yb. ,pP"Ybd MM ,MP',pP"Ybd
MM 6W' `Wb MM MM MM MM MM MM 6W' `Wb MM MM MM 8) MM 8I `" MM ;Y 8I `"
MM. 8M M8 MM MM MM MM MM MM 8M M8 MM MM MM ,pm9MM `YMMMa. MM;Mm `YMMMa.
`Mb. ,' YA. ,A9 MM MM MM MM MM MM YA. ,A9 MM MM MM 8M MM L. I8 MM `Mb. L. I8
`"bmmmd' `Ybmd9' .JMML JMML JMML..JMML JMML JMML. `Ybmd9' .JMML JMML. `Mbmo `Moo9^Yo.M9mmmP' .JMML. YA.M9mmmP'
Search, select, cut, copy
/ slash to search
v to enter visual mode all move commands select text
yy copies a line
p pastes a line below P pastes line above
yw copies forward to the end of the work
repeat commands by prefixing with a number
all cut/delete commands copy text to a global register
"a preceeding a cut saves the text to a registered named a
. to repeat a previous command
`7MMM. ,MMF'
MMMb dPMM
M YM ,M MM ,6"Yb. ,p6"bo `7Mb,od8 ,pW"Wq. ,pP"Ybd
M Mb M' MM 8) MM 6M' OO MM' "' 6W' `Wb 8I `"
M YM.P' MM ,pm9MM 8M MM 8M M8 `YMMMa.
M `YM' MM 8M MM YM. , MM YA. ,A9 L. I8
.JML. `' .JMML.`Moo9^Yo. YMbmd' .JMML. `Ybmd9' M9mmmP'
qq to record a macro into register q
@q to replay macro into register q
,, ,, ,, ,... ,...
`7MM"""YMM db `7MM *MM .d' "" .d' ""
MM `7 MM MM dM` dM`
MM d `7MM MM .gP"Ya ,pP"Ybd MM,dMMb. `7MM `7MM mMMmm mMMmm .gP"Ya `7Mb,od8 ,pP"Ybd
MM""MM MM MM ,M' Yb 8I `" MM `Mb MM MM MM MM ,M' Yb MM' "' 8I `"
MM Y MM MM 8M"""""" `YMMMa. MM M8 MM MM MM MM 8M"""""" MM `YMMMa.
MM MM MM YM. , L. I8 MM. ,M9 MM MM MM MM YM. , MM L. I8
.JMML. .JMML..JMML. `Mbmmd' M9mmmP' P^YbmdP' `Mbod"YML..JMML. .JMML. `Mbmmd' .JMML. M9mmmP'
:e edit file
:w write file
:q quit
! force
,, ,, ,,
`7MM"""Mq. `7MM db mm db
MM `MM. MM MM
MM ,M9 .gP"Ya `7Mb,od8 ,pP"Ybd ,pW"Wq. `7MMpMMMb. ,6"Yb. MM `7MM ,pP"Ybd ,6"Yb. mmMMmm `7MM ,pW"Wq. `7MMpMMMb.
MMmmdM9 ,M' Yb MM' "' 8I `" 6W' `Wb MM MM 8) MM MM MM 8I `" 8) MM MM MM 6W' `Wb MM MM
MM 8M"""""" MM `YMMMa. 8M M8 MM MM ,pm9MM MM MM `YMMMa. ,pm9MM MM MM 8M M8 MM MM
MM YM. , MM L. I8 YA. ,A9 MM MM 8M MM MM MM L. I8 8M MM MM MM YA. ,A9 MM MM
.JMML. `Mbmmd' .JMML. M9mmmP' `Ybmd9' .JMML JMML.`Moo9^Yo..JMML..JMML.M9mmmP' `Moo9^Yo. `Mbmo .JMML. `Ybmd9' .JMML JMML.
:set nu
:colorscheme solarized
,ev to edit config
.rv to reload config
,, ,,
`7MM"""Mq. `7MM db
MM `MM. MM
MM ,M9 MM `7MM `7MM .P"Ybmmm `7MM `7MMpMMMb. ,pP"Ybd
MMmmdM9 MM MM MM :MI I8 MM MM MM 8I `"
MM MM MM MM WmmmP" MM MM MM `YMMMa.
MM MM MM MM 8M MM MM MM L. I8
.JMML. .JMML. `Mbod"YML. YMMMMMb .JMML..JMML JMML.M9mmmP'
6' dP
Ybmmmd'
pathogen
editorconfig
nerdtree
syntastic
fugitive
colorschemes
,, ,,
`7MMF' A `7MF'`7MM `7MMF' `7MF' db ,M"""b.
`MA ,MA ,V MM `MA ,V 89' `Mg
VM: ,VVM: ,V MMpMMMb. `7M' `MF' `7MM `7MM ,pP"Ybd .gP"Ya VM: ,V `7MM `7MMpMMMb.pMMMb. ,M9
MM. M' MM. M' MM MM VA ,V MM MM 8I `" ,M' Yb MM. M' MM MM MM MM mMMY'
`MM A' `MM A' MM MM VA ,V MM MM `YMMMa. 8M"""""" `MM A' MM MM MM MM MM
:MM; :MM; MM MM VVV MM MM L. I8 YM. , :MM; MM MM MM MM ,,
VF VF .JMML JMML. ,V `Mbod"YML.M9mmmP' `Mbmmd' VF .JMML..JMML JMML JMML. db
Programming is not about typing it is about thinking and problem solving.
Thinking is treated as a first class citizen.
The smartest developers I know are the ones who change or delete code, not
the ones who add more.
Vim doesn't do things for you, it gives you surgical control over your code.
Vim works close to the metal, works equally well from the terminal or GUI.
Keep calm and make changes in production
,,
MMP""MM""YMM db
P' MM `7
MM `7MM `7MMpdMAo. ,pP"Ybd
MM MM MM `Wb 8I `"
MM MM MM M8 `YMMMa.
MM MM MM ,AP L. I8
.JMML. .JMML. MMbmmd' M9mmmP'
MM
.JMML.
Learning Vim takes time - a long time
Don't try and learn if you're in a hurry modifying production
configurations during an outage is not the best time to learn a few
new commands.
Learn a few commands at a time
:q! Is always a good start. :e! Is another.
Then a few inserts and appends.
Understand copying and pasting
Using registers to stash and paste things
Configure your editor.
Enjoy
Vim zen is only pressing ESC once
Favourite/daily commands
===========================================
:q quit
:q! quit and abandon changes
:w write to file
:w! overwrite existing file
:e edit (open) file name
:wq/ZZ save and quit
esc exit insert mode
esc cancel visual command
i insert at cursor
a append after cursor
I insert begining of line
A append end of line
o insert on new line below
O insert on new line above
0 navigate to the begining of the line
$ navigate to the end of the line
w jump to next begining of word
e jump to next end of word
b jump to previous begining of word
h left
j down
k up
l right
(or just use arrow keys, or mouse)
H first line of screen
L last line of screen
gg line 0
G EOF
yy yank (copy) current line
p paste buffer line below
P paste buffer line aboveith all above
dd delete (cut) current line
x delete char under cursor
X delete prevous charr
r replace char
R replace mode
s delete char and insert mode
S truncate line and insert mode
c delete selected text and insert mode
C delete from cursor to end of line and insert mode
J join two lines
v visual mode, allow selecting of text with the above move commands
u undo last command
CTRL+R redo last command
CTRL+D partial page down
CTRL+u partial page up
"ayw yank word and store in named register a
% jump to matching parens
v% highlight block
qq start recording macro to register q
@q replay macro in register q
5@q replay acro in register q 5 times.
Environment configuration
=========================
:set nu line numbers
:syntax on syntax highlighting
:newtab newtab
:new/vnew new split window
:ls list buffers
:b1 open buffer 1
:colorscheme set colourscheme
:set colorcolumn=80 vertical line at 8- characters
set hlsearch highlight search terms
set incsearch incremental search
" Start Pathogen
call pathogen#infect()
" change the mapleader from \ to ,
let mapleader = ","
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>rv :so $MYVIMRC<CR>
set enc=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf8,prc
"set guifont=anonymous_pro:h12
set nowrap " don't wrap lines
set tabstop=4 " a tab is four spaces
set backspace=indent,eol,start
" allow backspacing over everything in insert mode
set expandtab
"set autoindent " always set autoindenting on
"set copyindent " copy the previous indentation on autoindenting
set number " always show line numbers
set shiftwidth=4 " number of spaces to use for autoindenting
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set showmatch " set show matching parenthesis
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,
" case-sensitive otherwise
"set smarttab " insert tabs on the start of a line according to
" shiftwidth, not tabstop
set hlsearch " highlight search terms
set incsearch " show search matches as you type
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title " change the terminal's title
set visualbell " don't beep
set vb
set noerrorbells " don't beep
set nobackup
set nowritebackup
set noswapfile
filetype plugin indent on
let g:JSHintHighlightErrorLine = 0
if has('autocmd')
autocmd filetype python set expandtab
autocmd filetype javascript set expandtab
endif
if &t_Co > 2 || has("gui_running")
" switch syntax highlighting on, when the terminal has colors
syntax on
colorscheme desert
endif
if &t_Co > 256 || has("gui_running")
colorscheme solarized
endif
" Highlight whitespace
set list
set listchars=tab:› ,trail:¤,extends:.,nbsp:.
:highlight SpecialKey ctermfg=7
:highlight NonText ctermfg=7
:highlight LineNr term=bold ctermfg=7
highlight Search ctermfg=4 ctermbg=7 cterm=NONE
autocmd filetype html,xml set listchars-=tab:>.
"highlight 80 columns wide
set colorcolumn=80
" Paste toggle should fix the busted pasting from the autoindent
:set pastetoggle=F2
" clear search highlighting with ',/'
nmap <silent> ,/ :nohlsearch<CR>
" PLAYing with buffers
" window
nmap <leader>nw<left> :topleft vnew<CR>
nmap <leader>nw<right> :botright vnew<CR>
nmap <leader>nw<up> :topleft new<CR>
nmap <leader>nw<down> :botright new<CR>
" buffer
nmap <leader>n<left> :leftabove vnew<CR>
nmap <leader>n<right> :rightbelow vnew<CR>
nmap <leader>n<up> :leftabove new<CR>
nmap <leader>n<down> :rightbelow new<CR>
" TABS
" Map CTRL-N to create a new tab
:map <C-n> <ESC>:tabnew<RETURN>
" Map Tab and CTRL-Tab to move between tabs
:map <Tab> <ESC>:tabn<RETURN>
:map <C-Tab> <ESC>:tabp<RETURN>
" Always show tab bar (help with a silly resizing bug/issue
set showtabline=2
" Replace tabs and remove extra whitespace
nmap <silent> <leader>k :retab<CR>:%s/\s\+$//<CR>
" I think this fixes windows line endings.
nmap <silent> <leader>l :%s/\r//g<CR>
" Clipboard
nmap <C-V> "+gP
imap <C-V> <ESC><C-V>i
vmap <C-C> "+y
" Directories and files
:set autochdir
:set wildmenu
" NerdTree Config
let mapleader = ","
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
map <Leader>a :wincmd W<CR>
map <Leader>s :wincmd w<CR>
" Single click mouse for GVIM
let NERDTreeMouseMode=2
" These dont do what I want them to yet
let NERDTreeShowBookmarks=1
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
" configure javascript linting
let g:syntastic_javascript_checkers = ['eslint']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment