|
introductionbasics |
advancedextras |
text editor
/vɪm/
a contraction of Vi IMproved
first release in 1991
efficiency
highly configurable
ubiquity
scriptable
Debian/Ubuntu
apt-get install vim
CentOS/Fedora
yum install vim
Mac
brew install macvim --override-system-vim
Windows (?)
ftp://ftp.vim.org/pub/vim/pc/gvim81.exe
Normal: navigate the scructure of the file.
Insert: edit the file.
Visual: highlight portions of the file to manipulate at once.
Command: command line mode, searches, …
| key | action |
| h | left |
| j | down |
| k | up |
| l | right |
| title | url |
| VIM adventures | https://vim-adventures.com/ |
| Interactive Vim tutorial | http://openvim.com/ |
| key | action |
| ^e | scroll down a line |
| ^y | scroll up a line |
| ^f | scroll down a page |
| ^b | scroll up a page |
| H | move cursor to the top of the window |
| M | move cursor to the middle of the window |
| L | move cursor to the bottom of the window |
| gg | go to the top of file |
| G | go to the bottom of file |
| key | meaning |
| w | word |
| s | sentence |
| p | paragraph |
| t | tag |
| key | action |
| d | delete |
| c | change |
| y | yank |
| v | visual select |
| key | action |
| :set number | show line numbers |
| :<number> | go to line number <number> |
| <C-p> | auto complete word |
| /text | find text on the document |
| :nohlsearch | stop the highlighting for the 'hlsearch' option |
| <C-z> | send vim to background |
| fg | send vim to foreground again |
| <C-a> | increment the next number |
| <C-x> | decrement the next number |
| zz | scrolls to the middle |
| command | action |
| :ls | list of open buffers |
| :bp | move to previous buffer |
| :bn | move to next buffer |
| :b<n> | move to <n>'th buffer |
| :b <filename-part> | move to buffer matchin name with <filename-part> |
| :bw <n> | wipe current or <n>'th buffer |
| <n><C-6> | edit alternate file |
| command | action |
| :sp(lit) <filename> | split window and load <filename> |
| :vs(plit) <filename> | vertical split window and load <filename> |
| :only | keep only this window open |
| <C-w> <direction> | move cursor to window placed at <direction> |
| <number> <C-w> + | increase window size by <number> lines |
| <number> <C-w> − | decrease window size by <number> lines |
| <C-w> > | increase window size by <number> columns |
| <C-w> < | decrease window size by <number> columns |
| <C-w> _ | set the current window to maximum height |
| <C-w> | | set the current window to maximum width |
| <C-w> = | set all windows equal size |
Open [n] files in horizontal splits
vim -o[n] *.php
Open [n] files in vertical splits
vim -O[n] *.php
Make a session to remember windows placement
:mksession ~/.vim/sessions/example.vim
Restore vim saved session
vim -S ~/.vim/sessions/example.vim
:source ~/.vim/sessions/example.vim
Manual: manually define folds.
Indent: more indent means a higher fold level.
Syntax: folds defined by syntax highlighting.
Expr, diff, marker, …
Download
~ / Zinio / app / core / base / RESTService.js
After open the file set this Vim configuration
:set foldmethod=indent
:set foldlevel=1
| key | action |
| zj | moves the cursor to the next fold |
| zk | moves the cursor to the previous fold |
| zo | opens a fold at the cursor |
| zc | closes a fold under cursor |
| za | toggle a fold at the cursor |
| zR | decreases the foldlevel to zero (all folds will be open) |
| zM | closes all open folds |
| zr | decreases the foldlevel by one |
| zm | increases the foldlevel by one |
:help fold-methods
:help folding
:help folds
Sequence of commands recorded to a register
| Record a macro | Play a macro | |
|
q<register> (do the things) q |
@<register> |
Download
~ / Zinio / app / core / base / RESTService2.js
| command | action |
| dp | diffput: puts changes under the cursor into the other file |
| do | diffobtain: The change under the cursor is replaced by the content of the other file |
| ]c | jump to the next diff |
| [c | jump to the previous diff |
use and share your .vimrc!
colo desert
syntax on
set number
set showcmd
set ruler
set showmode
set hlsearch
set incsearch
set autoindent
set cindent
set ignorecase
set nocompatible
set backspace=2
set ts=4
set shiftwidth=4
set nowrap
set showmatch
"set completeopt=menu,preview
set completeopt=preview
cab Q q
cab W w
Is a way to define vim settings in the source file
example from vim help:
vi:noai:sw=3 ts=6
example from any apache configuration file:
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
'.
Regarding vim marks: http://vim.wikia.com/wiki/Using_marks