andrew's guide to vim

45
LOGO Vi iMproved 入

Upload: andrew-yi

Post on 30-Jun-2015

167 views

Category:

Technology


8 download

DESCRIPTION

vim trial. Introduced the basic info

TRANSCRIPT

Page 1: andrew's guide to vim

LOGO

Vi iMproved入门

Page 2: andrew's guide to vim

Contents

Basics1

Vim as notepad2

Vim as IDE4

miscellaneous5

Advanced concepts3

Page 3: andrew's guide to vim

Contents

Basics1

Page 4: andrew's guide to vim

Basic – background info

Vim means Vi Improved

first released publicly in 1991

license is compatible with GPL

Popular with GNU/Linux

Page 5: andrew's guide to vim

Basic – give up it

Learning vim is difficult

Page 6: andrew's guide to vim

Basic – version

Latest release: 7.4

Please update to latest version Plugins Tab edit mode :help version7

Page 7: andrew's guide to vim

Basic – platform

gVim

Page 8: andrew's guide to vim

Basic – mode

Normal

CommandInsert

I/O/A…

Esc/Ctrl+C Q/:

Visual/Esc

Page 9: andrew's guide to vim

Contents

Vim as notepad2

Page 10: andrew's guide to vim

Vim as notepad – Insert

Ctrl-y/e: copy chars from prev/next line

Ctrl-n/p:auto complete word

Page 11: andrew's guide to vim

Vim as notepad – Normal

Begin to Insert:I: insert at the beginning of line

A: insert at the end of line a: insert after cursor O: start new line upon current line o: start new line below

Page 12: andrew's guide to vim

Vim as notepad – Normal

Move within line:$: move to the end0: move to the beginning of linew: move a word forwardb: move a word backwardf+char: move to next charF+char: move to prev char

Page 13: andrew's guide to vim

Vim as notepad – Normal

Move within page:H: high / on topM: middle / in them middleL: low / at bottom

Move within file:Ctrl-f: forward by pageCtrl-b: backward by page

Page 14: andrew's guide to vim

Vim as notepad – Normal

Move globally:G: to the end of filegg: to the start of tilenumber+gg: to specified line% on {[()]}: the mapping bracket

Page 15: andrew's guide to vim

Vim as notepad – Normal

Find word when cursor on word:

*: forward#: backward

Find word with input word:/: forward?: backward

n to repeat and N to reverse repeat

Page 16: andrew's guide to vim

Vim as notepad – Normal

selection(also visual)shift+v: select linectrl+v: select blockv: select char sequences

And then?y: copyp: pasted:delete

Page 17: andrew's guide to vim

Vim as notepad – command

set nuset hlsearchset ignorecaseset tabstop=4set wrap……

Page 18: andrew's guide to vim

Vim as notepad – window

:edit filename:tabedit filename:split filename:vsplit filename

Ctrl-w + Ctrl-w/hjkl: jump between windows

Page 19: andrew's guide to vim

Contents

Advanced concepts3

Page 20: andrew's guide to vim

Advanced – get help

use :help xxx

Just google it

Page 21: andrew's guide to vim

Advanced – encoding

:set fileencodings?

:set encoding?

:set fileencoding?

Page 22: andrew's guide to vim

Advanced – scripts

Put the commands into a file then we get a script:

Script can:customize vimenhance functions

Page 23: andrew's guide to vim

Advanced – scripts

Customize:File location:

File Name:

Page 24: andrew's guide to vim

Advanced – scripts

:scriptnames<CR>

A bundle of script(s) set up a plugin

Page 25: andrew's guide to vim

Advanced – buffer

:buffers

Window:

Tab:

Page 26: andrew's guide to vim

Advanced – buffer

buffers and tab:Eclpse: (Ctrl-e)

vim buffexplorer:

Page 27: andrew's guide to vim

Advanced – register

Registers:

Use “ to call them

Page 28: andrew's guide to vim

Advanced – record/macros

q start record, q again to stop

It’s programmer’s way of thinking!

But there is no ‘if’

Use @ to loop

Page 29: andrew's guide to vim

Contents

Vim as IDE4

Page 30: andrew's guide to vim

Vim as IDE – preview

What IDE provides us with:1, project management2, file explorer3, multiple file editor4, auto-completion5, reference/jump to definition6, project compilation

Page 31: andrew's guide to vim

Vim as IDE – preview

Project Mangement: Project

Page 32: andrew's guide to vim

Vim as IDE – preview

File explorer: NERDTree

Page 33: andrew's guide to vim

Vim as IDE – preview

Multiple file edit:bufexplorer/airline

Page 34: andrew's guide to vim

Vim as IDE – preview

Auto-completion:omnicppcomplete

Page 35: andrew's guide to vim

Vim as IDE – preview

reference/jump to definition:Taglist/Ctags

Page 36: andrew's guide to vim

Vim as IDE – preview

Compilation:make: compilecc: show you current infocl: show you info listcw: open info windowcn: bring you to next err/warningcp: brin gyou to previous

Page 37: andrew's guide to vim

Vim as IDE – scripts

Scripts used:ProjectBufexplorerNERDTreeOmnicppcompleteTaglistAirlineKolor.vimandrew’s vim – mine vimrc …

Page 38: andrew's guide to vim

Vim as IDE – give it up

Too much labor work

Not as fast as you may expect

Not so intelligent

How to debug?

Page 39: andrew's guide to vim

Vim as IDE – give it up

Life is short, use python.

Life is short, use an IDE.

Page 40: andrew's guide to vim

Contents

miscellaneous5

Page 41: andrew's guide to vim

Miscellaneous – websites

Official:http://www.vim.org/

Wiki:http://vim.wikia.com/wiki/Vim_Tips_Wiki

Page 42: andrew's guide to vim

Miscellaneous – downloads

Download:http://www.vim.org/download.php

Sources:ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2

For windows:ftp://ftp.vim.org/pub/vim/pc/gvim74.exe

Page 43: andrew's guide to vim

Miscellaneous – build

1, mkdir ${HOME}/personal_tools2, cd ${HOME}/personal_tools3, wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz24, tar xf vim-74.tar.bz25, cd vim74 && ./configure --with-features=huge --

prefix=${home}/personal_tools && make && make install

6, export PATH=${HOME}/personal_tools/bin:${PATH}7, vim

Page 44: andrew's guide to vim

Miscellaneous – andrew

.vimrc vim.tar

Page 45: andrew's guide to vim

LOGO