Editorsway
Everyway ystemsay asktay endsway atway anway editorway — everyway onfigcay ilefay, everyway iptscray, everyway abfstay, everyway authorizedway_eyskay. Otway amesnay anchorway itway: ivay — ethay OSIXpay-andatedmay editorway, esentpray onway everyway Unixway everway — andway imvay, ichwhay isway atwhay ivay actuallyway unsray onway earlynay everyway Inuxlay (ivay-ompatiblecay odemay). OSIXpay ivay isway ethay ecificationspay; imvay isway ethay ogrampray — ethay ‡ arksmay inway ethay ammargray abletay eparatesay emthay. anonay idesray alongway asway ethay indkay efaultday onway ostmay istrosday. Isthay apterchay eachestay ivay uencyflay asway away urvivalsay illskay andway away uencyflay, anonay asway ethay iendlyfray allbackfay, andway enwhay eachway isway ethay ightray ooltay.
ivay — ethay oneway atthay'say alwaysway erethay
Ivay'say orecay icktray: odesmay — iway otay insertway, Escway ackbay otay ormalnay, erewhay everyway eykay isway away ommandcay. Ethay isciplineday eelsfay alienway orfay away ayday, enthay ecomesbay owhay youway inkthay:
ESC — normal mode (the home base)
i / a / o — insert before / after / new line
:w — write · :q — quit · :wq — save+quit · :q! — force-quit
:x — save+quit · ZZ — save+quit
dd — delete line · yy — yank · p — paste · u — undo · Ctrl-R redo
0 / $ — line start/end · gg / G — file start/end
/pattern — search · n — next · ? — search back
:%s/old/new/g — sed inside the editor
:wq — the command every tutorial drills
Ethay erbsvay omposecay: day + otionmay = eleteday (dway ordway, day$ otay endway, day5day ivefay ineslay); yway + otionmay = yankway; cay + otionmay = angechay. 5dday eletesday ivefay ineslay; icay" angeschay insideway uotesqay; vay electssay isuallyvay; . epeatsray ethay astlay ommandcay. Ethay anguagelay isway ammargray — erbvay + otionmay — andway uencyflay isway earninglay otay eakspay itway.
imvay — ivay'say empireway
imvay addsway yntaxsay ighlightinghay, ultiplemay ilesfay, itssplay, uginsplay — onway ostmay Inuxeslay ivay isway imvay inway ompatiblecay odemay. imtutorvay isway ethay uiltbay-inway utorialtay — 20 inutesmay, enuinelygay ufficientsay. Ethay urvivalsay etsay orfay onfigcay orkway: iway/Escway, :wqay, dday, uway, /, :etsay umbernay. Everythingway elseway isway epthday.
anonay — ethay indkay oneway
nano file
Ctrl-O — write out · Ctrl-X — exit · Ctrl-W — find
Ctrl-K — cut line · Ctrl-U — uncut · Ctrl-G — help
Ethay ortcutsshay areway intedpray atway ethay ottombay — ethay editorway atthay explainsway itselfway. Orfay uickqay editsway andway orfay anyoneway otnay ivinglay inway ethay erminaltay, anonay isway orrectcay. /etcway/alternativesway/istroday efaultsday etsay EDITORway/ISUALvay — exportway EDITORway=anonay akesmay itway ethay ystemsay'say efaultday (ichwhay isway atwhay isudovay, ontabcray -eway, itgay ommitcay essagesmay invokeway).
ivay — ethay ompletecay ammargray
(POSIX vi covers the core; rows marked ‡ are vim-only — visual mode, text
objects, splits, redo — present on every Linux `vi`, absent on a true POSIX vi.)
MODES:
Esc — normal i/a/o/O — insert v/V/Ctrl-v — visual‡ : — ex R — replace
Ctrl-o — one normal cmd from insert‡ gv — reselect last visual‡
MOTIONS (verb+motion grammar):
0 $ ^ — line start/end/first-nonblank w b e — word fwd/back/end W B E — WORD
gg‡ G — file start/end :n / nG — line n f F t T — char-target motions, ; , repeat them
{ } — paragraph ( ) — sentence % — matching bracket * # — word under cursor‡
VERBS + MOTIONS — the compositional language:
d — delete y — yank c — change v — select > — indent < — dedent = — reformat
dd yy cc — line forms d3w 3dw — delete 3 words d$ — to end df; — to the ;
ci" ca( ciw — inner/around quoted/paren/word‡ cip — change paragraph‡
d/text — to the pattern yG — to end of file
OPERATORS:
x — char X — before s — substitute char S — line J — join lines
p P — paste after/before . — REPEAT last command — the superpower u U Ctrl-R — undo/line/redo‡
~ — swap case gu gU — lower/upper‡ r — replace char zz zt zb — recenter/top/bottom‡
EX COMMANDS (:):
:w :q :wq :x :q! ZZ ZQ — write/quit combos
:e! — revert to disk
:set number / nonu — line numbers‡
:set paste / nopaste — the paste-mode fix for bracketed pastes‡
:s/old/new/[gc] — sed inside — % = whole file, g = global, c = confirm
:g/pat/d — delete every matching line — global+cmd
:v/pat/d — delete every NON-matching
:r file — read a file in
:r! cmd — insert a command's output
:! cmd — shell out
:w !sudo tee % — save-as-root — the classic fix‡
:split :vsplit :tabnew Ctrl-w— splits + tabs‡
:noh — clear search highlight‡
:history :buffers :ls — the state‡
:mark a, 'a — named marks
:registers — the yank registers‡
:x — like :wq but only writes if changed
imvay — ethay additionsway orthway itway
vim file +20 # open at line 20
vim file +/pat # open at first match
vim -R file # read-only
vim -d a b # vimdiff — side-by-side diff
vim file1 file2 # multiple — :n :prev :args
vim -o/-O/-p a b # splits vs tabs
vimtutor # the tutorial — run it
:set nu rnu # absolute + relative numbers — the motion math
:set list — show tabs/trailing
:set hlsearch incsearch — search behavior
:syntax on/off — highlighting
:retab — tabs→spaces per ts
gg=G — reindent the whole file
q: q/ q? — the command/search history WINDOWS
Ctrl-a Ctrl-x — inc/dec numbers under cursor
anonay — ethay ullfay etsay
Ctrl-O write · Ctrl-X exit · Ctrl-W find · Alt-W next · Ctrl-\ replace
Ctrl-K cut · Ctrl-U uncut · Ctrl-Y prev-page · Ctrl-V next-page
Alt-A mark · Alt-6 copy · Ctrl-_ go-to-line · Ctrl-C cursor pos
Ctrl-T spell · Alt-U undo · Alt-E redo · Ctrl-G help
nano -l -c file # line numbers + cursor pos
edway — ethay ancestorway
ed file
a — append i — insert c — change d — delete
p — print n — numbered print ,p — print all 1,5p — lines
/pat/ — search s/old/new/ — substitute w — write q — quit
edway isway erewhay edsay'say say///, ivay'say : ommandscay, andway epgray'say gay/eray/pay allway escendday omfray — ethay originalway inelay editorway.
Ethay othersway orthway owingknay
- edway — ethay inelay editorway — ancientway, iptablescray, ethay ancestorway ofway
edsayandway ivay'say:ommandscay —edwayurvivessay inway OSIXpay - edsay -iway — editingway ithoutway anway editorway —
edsay -iway.akbay 'say/away/bay/gay'isway ethay iptedscray editway - emacsway — ethay otherway iantgay — away isplay environmentway atthay editsway exttay
- odecay/imnvay/elixhay — ethay odernsmay — Vsay Odecay, Eovimnay, Elixhay
Ethay onfigcay-ilefay aftcray
Ealray editingway isway onfigcay orkway — /etcway/abfstay, sshday_onfigcay, .ashrcbay:
sudoedit /etc/fstab # edits as user, writes as root — safer than sudo vi
vi /etc/ssh/sshd_config # the classic
nano ~/.bashrc
Ethay isciplinesday: ackbay upway eforebay editingway (cpay ilefay ilefay.akbay), earnlay ethay ilefay'say yntaxsay (ommentscay #, abstay vsay acesspay erewhay itway attersmay — /etcway/abfstay itespacewhay, Akefilemay abstay), yntaxsay-eckchay afterway (sshday -tay, isudovay eckschay udoerssay automaticallyway, ountmay -away eststay abfstay). Away okenbray /etcway/abfstay ootsbay otay emergencyway odemay; away okenbray udoerssay ockslay outway udosay — owknay ethay eckchay ommandcay eforebay avingsay.
Erewhay editorsway ogay ongwray
| Ymptomsay | Ausecay |
|---|---|
| Ypingtay oducespray ommandscay, otnay exttay | ivay inway ormalnay odemay — iway |
:wqay idnday'tay uitqay | Illstay inway insertway — Escway irstfay |
udosay ivay ilefay eaveslay ootray-ownedway ilesfay | udoeditsay orway udosay -eway isway eanerclay |
itgay ommitcay opensway anway alienway editorway | exportway EDITORway=anonay |
| ivay'say olorscay unreadableway | :yntaxsay offway, orway ERMtay okenbray |
| Avedsay utbay ethay angechay idnday'tay aketay | Ethay ilefay eedednay away ervicesay estartray / eray-ourcesay |
Exercisesway
imtutorvay— onceway oughthray, onestlyhay.- Editway away atchscray ilefay:
ddayaway inelay,uwayundoway,/earchsay,:%say/xay/yway/gay. exportway EDITORway=anonay; ontabcray -eway— eesay ethay efaultday aketay effectway.edsay -iway.akbay 'say/away/bay/gay'away ilefay — ethay onay-editorway editway.- Openway
/etcway/abfstayinway ivay — eadray-onlyway acticepray,:qay!outway.