Live Chat Software by Kayako
Become a Vi Master by Learning These 30+ Key Bindings
Posted by Thang Le Toan on 16 September 2016 01:33 AM

image

Vi is a powerful text editor included on most Linux systems. Many people swear by vi and find it faster than any other editor once they’ve learned its key bindings. You can even use vi key bindings in Bash.

We’ve already covered getting started with vi for beginners. If you haven’t used vi in a while, you might want to give that post a look to get a refresher on the basics.

Mode Switching

As a short recap, vi is a modal editor – there’s an insert mode and a standard command mode. In insert mode, vi functions similar to a normal text editor. In command mode, you take advantage of these key bindings.

  • i – Enter insert mode.
  • Escape – Leave insert mode. If you’re already in command mode, Escape does nothing, so you can press Escape to ensure you’re in command mode.

image

Moving the Cursor

Vi uses the hjkl keys to move the cursor in command mode. Early computer systems didn’t always have arrow keys, so these keys were used instead. One advantage of these keyboard shortcuts is that you don’t have to move your fingers from the home row to use them.

  • h – Move cursor left.
  • j – Move cursor down.
  • k – Move cursor up.
  • l – Move cursor right.

You can also use search commands to quickly move the cursor.

  • / – Type a / followed by some text you want to find and press Enter to quickly move your cursor to the location of the text in the file. For example, if you have the word iguana in your file, type /iguana and press Enter to quickly move the cursor there.
  • ? – Like /, but searches backwards.
  • f – Type an f followed by any character to quickly move the cursor to the next occurrence of the character on the current line. For example, if you have the line “Hello world” on a line and your cursor is at the beginning of the line, type fo to move to the o in Hello. Type fo again to move to the o in world.
  • F – Like f, but searches backwards.
  • % – Jump between the nearest (), [], or {} characters on the line.

Use these commands to quickly move to locations in the file:

  • H – Move cursor to highest (top) line in file.
  • M – Move cursor to middle line in file.
  • L – Move cursor to lowest (bottom) line in file.
  • #G – Type a number and then type G to go to that line in the file. For example, type 4G and press Enter to move to the fourth line in the file.

Moving between words:

  • w – Move forward a word.
  • #w – Move forward a number of words. For example, 2w moves forward two words.
  • b – Move back a word.
  • #b – Move back a number of words. For example, 3b moves back three words.
  • e – Move to end of the current word.

image

Copying & Pasting

Vi refers to the act of copying as “yanking.”

  • v – Press v and move the cursor to select a section of text.
  • y – Copy (yank) the selected text.
  • p – Paste at cursor.
  • x – Cuts the selected text. Cuts the character under the cursor if no text is selected
  • r – Type r and then type another character to replace the character under the cursor.

Combining Commands

Some commands – including the y and v commands above and the d (delete) command accept cursor motion commands.

For example, when you press d to delete some text, nothing will happen until you enter a cursor motion command. For example:

  • dw – Deletes the next word.
  • db – Deletes the previous word
  • de – Deletes to the end of the current word.
  • dL – Deletes all text below the cursor in the file.
  • d/unicorn – After pressing Enter, deletes all text between the cursor and the word “unicorn” in the current file.
  • dd – Deletes an entire line.

As you can see, the combination of combining a command with a cursor movement command is very powerful.

image

Repeat & Undo

Vi’s repeat command is very powerful, as it can repeat complex, combined commands.

  • u – Undo.
  • . – The . repeats the last full command.  The insert command also functions as a command here. For example, type iunicorn and press Escape. You can then use the . key to insert the word unicorn at the cursor.

Bonus: Using Vi Key Bindings in Bash

Once you’ve mastered the vi key bindings, you may want to use them elsewhere on your system. No problem – you can set the Bash shell to use vi-style key bindings.

Try this out in the current session by running the following command in a Bash terminal:

set -o vi

Bash will start in insert mode – press Escape to enter command mode and use these key bindings.

If you like this, you can add the command to your ~/.bashrc file and it will be automatically run each time you log in. Use the vi .bashrc command to open and edit the file in vi.

image


This isn’t a complete list of key bindings for vi, but it should help you flex your vi wings and learn to fly. This list of key bindings at Harvard’s website is more complete and has more information, although it’s less organized and harder to digest all at once.

(0 vote(s))
Helpful
Not helpful

Comments (2)
ThomasDic
27 December 2019 11:58 AM
fitness tøj til kvinder køb fitnesstøj til kvinder fra carite <a href="http://www.oldhistorypics.com/rucker_nicoma/tr%c3%a6nings-t-shirt-hvid">trænings t shirt hvid</a> billi bi sko hos pricerunner se den <a href="http://www.oldhistorypics.com/schram_quasqueton/annika-korte-st%c3%b8vler">annika korte støvler</a> superfit boys sutsko bully denim <a href="http://www.oldhistorypics.com/silvana_westdover/hummel-maroon-softshell-dragt">hummel maroon softshell dragt</a> pigers sko athletic inspired converse chuck taylor party <a href="http://www.oldhistorypics.com/stafford_minelamotte/nike-pro-zonal-strength-tights-herre">nike pro zonal strength tights herre</a>
kurt geiger emma big black leather tote bag kurt geiger fashion <a href="http://www.bginfonews.com/fowler_northtunica/disney-carry-the-magic-designer-style-tote-bag">disney carry the magic designer style tote bag</a> chanel designer handbags foto 17 chanel designer handbags foto 18 <a href="http://www.bginfonews.com/fragaria_bowbells/michael-kors-fashion-personality-zip-rivet-backpack-mk-women-d">michael kors fashion personality zip rivet backpack mk women d</a> buy fendi online fendi monster convertible baguette w tags handbags <a href="http://www.bginfonews.com/frazeysburg_eutawville/eume-lexus-22-ltr-laptop-backpack-for-15.6-inch-laptop-and-nylon-water-resistance-backpack-black-amazon.in-bags">eume lexus 22 ltr laptop backpack for 15.6 inch laptop and nylon water resistance backpack black amazon.in bags</a> lacoste chantaco small crossover bag in black lyst <a href="http://www.bginfonews.com/freeland_aberdeen/texas-school-district-random">texas school district random</a>
rosita shorts shorts grøn pulz jeans <a href="http://www.abanose.com/lagrande_lompico/sport-og-sex-har-givet-jbs-opm%c3%a6rksomhed">sport og sex har givet jbs opmærksomhed</a> 430 waterproof softshell pink <a href="http://www.abanose.com/lakeline_goudeau/weekend-med-barned%c3%a5b-og-hygge-copenhagen-kiddo">weekend med barnedåb og hygge copenhagen kiddo</a> billi bi archives dresscodes <a href="http://www.abanose.com/lakepine_bigbend/ray-ban-solbriller-aviator-gro%c3%9fhandel">ray ban solbriller aviator großhandel</a> brune bugatti sko dame nye sko på nett hos <a href="http://www.abanose.com/landofpines_angels/boxershorts-3-pack-trunks-print">boxershorts 3 pack trunks print</a>

navy kjole med blade by angele <a href=http://www.abanose.com/westmarion_portbarre/cykelhandler-i-vejle-med-stor-erfaring>cykelhandler i vejle med stor erfaring</a> inkontinens badebukser til drenge <a href=http://www.abanose.com/wilberforce_centercity/bisgaard-gummist%c3%b8vler-rosa-m.-blomster>bisgaard gummistøvler rosa m. blomster</a> dykkerbriller til børn arena køb og salg af nyt <a href=http://www.aolrgj.com/alamoalto_lansford/torvegade-med-butikker-vejle-stenders-vejle-no-133-k-7100>torvegade med butikker vejle stenders vejle no 133 k 7100</a> rieker sko tysk kvalitet til ham og hende <a href=http://www.aolrgj.com/aristes_lynwood/en-fant-sko-gr%c3%a5-m.-velcro-find-billig-pris>en fant sko grå m. velcro find billig pris</a>
louis vuitton brown monogram denim trapeze handle bag <a href=http://www.pusdikbangsdmperumperhutani.com/yarrowpoint_slaughters/heavy-duty-school-bag-cosmus-norwitch-blue-33l-waterproof-backpacks-bag-with-laptop-compartment-price-in-india>heavy duty school bag cosmus norwitch blue 33l waterproof backpacks bag with laptop compartment price in india</a> termurah travel bag koper tas kanvas mickey minnie hitam pink ukuran besar harga penawaran hanya <a href=http://www.pusdikbangsdmperumperhutani.com/yatescity_haines/happy-sammies-backpack-s-samsonite>happy sammies backpack s samsonite</a> cache coeur ventebadedragt sort <a href=http://www.raycatholic.com/alamosa_biwabik/p%c3%a6ne-st%c3%b8vler-og-hverdags-vinterst%c3%b8vler-grenaa>pæne støvler og hverdags vinterstøvler grenaa</a> 2 akslet gardin til sj. fragt lastbilmagasinet <a href=http://www.raycatholic.com/alvarado_tarrytown/lidt-afslapning-paa-alt-om-ferie-i-kroatien>lidt afslapning paa alt om ferie i kroatien</a>
tøysko sjekk ut converse nye kolleksjon kk <a href=http://www.geraldojr.com/jerusalem_camphill/disruptor-ii-infant-only-at-jd>disruptor ii infant only at jd</a> carhartt sid pant blå chinos <a href=http://www.geraldojr.com/jolly_scanlon/g-star-i-center-fields-herret%c3%b8j-k%c3%b8benhavn-s>g star i center fields herretøj københavn s</a> kjoler til fest mange lækre billige kjoler <a href=http://www.geraldojr.com/judsonia_sanger/hummel-daisy-jakke-dark-navy-104-cm>hummel daisy jakke dark navy 104 cm</a> natalia blonde bluse brun <a href=http://www.geraldojr.com/lakefive_fandon/k%c3%b8b-billige-ray-ban-wayfarer-rb2140-solbriller-hvid-ramme>køb billige ray ban wayfarer rb2140 solbriller hvid ramme</a>

læs tøj online branchebladet tøj http://www.geraldojr.com/greendale_donnelly/c%c3%a6sar-romersk-kostume skibukser til børn spar 20 70 på attraktive mærker http://www.geraldojr.com/gruver_shadyhollow/zizzi-str-large-50-52 hummel jakke classic bee zip blå børn http://www.geraldojr.com/hamilton_gascoyne/%c3%b6verkomligt-pris-stylepit-stylepit-me-up-damskor mirage essentials bikini bh http://www.geraldojr.com/hebron_sequim/fodboldst%c3%b8vler-38-fodboldst%c3%b8vler-nyt
ray ban briller kvinder http://www.aolrgj.com/tuolumne_library/fr%c3%a6k-hipster-wayfarer-solbrille lola ramona sko blå med prikker ava walk on http://www.aolrgj.com/veblen_saintdavid/craft-belle-glow-vinter-jakke-kvinde-sort vender tilbage til profil optik http://www.aolrgj.com/verdigre_otsego/st%c3%b8vler-sort-pony-lang avatar kostume til børn og voksne kostumeuniverset http://www.aolrgj.com/vergne_spackenkill/pgm-1930-in-butiksd%c3%b8d-i-frederikshavn
dior m0579 supple lady dior bag in studded calfskin red http://www.mymalaysianpost.com/tschetter_pindall/2014-new-desigual-women-leather-handbags-genuine-leather-bags-ladies-famous-designer-brand-shoulder-free-shipping chanel lambskin resin small drawstring bag black apricot red cruise 2017 http://www.mymalaysianpost.com/twitty_savonburg/small-large-dance-duffle-bag-for-girls-sport-gym-bags-for-women-yoga-bag michael kors skorpios purse shoulder bag orange brown braided rolled handle http://www.mymalaysianpost.com/veracruz_citrus/adidas-shoulder-strap-duffle-athletic-gym-bag-travel-carry-on-luggage-tote-golf-carry christian dior vintage double saddle bag diorissimo canvas http://www.mymalaysianpost.com/villano_pecos/fendi-fendi-calfskin-leather-monster-shoulder-bag-red
Josephmot
26 February 2020 12:11 AM
πουλόβερ γυναικείο με λαιμόκοψη v garcia jeans <a href="http://www.jimmylangeboxing.com/milladore/%cf%80%cf%81%ce%bf%cf%8a%cf%8c%ce%bd%cf%84%ce%b1-%ce%b3%ce%b9%ce%b1-%cf%84%ce%b1-%ce%bc%ce%b1%ce%bb%ce%bb%ce%b9%ce%ac">προϊόντα για τα μαλλιά</a> base fashion ψηλομεσο skinny τζιν παντελονι <a href="http://www.jimmylangeboxing.com/miltona/%cf%86%cf%8c%cf%81%ce%b5%ce%bc%ce%b1-%cf%80%ce%bf%cf%85%ce%ba%ce%ac%ce%bc%ce%b9%cf%83%ce%bf-%ce%bc%ce%b5-%cf%86%ce%bb%ce%b1%ce%bc%ce%af%ce%bd%ce%b3%ce%ba%ce%bf-%ce%bc%ce%b1%cf%8d%cf%81%ce%bf">φόρεμα πουκάμισο με φλαμίνγκο μαύρο</a> βαμβακερή εκρού πετσέτα μονόγραμμα l <a href="http://www.jimmylangeboxing.com/mountangel/art-%ce%ba%ce%b1%cf%81%ce%ad%ce%ba%ce%bb%ce%b1-polycarbonate-pc-%ce%b4%ce%b9%ce%ac%cf%86%ce%b1%ce%bd%ce%bf">art καρέκλα polycarbonate pc διάφανο</a> θηκη skin body glove για iphone 3g 3gs black <a href="http://www.jimmylangeboxing.com/mountgilead/zakcret-%cf%80%ce%b1%cf%80%ce%bf%cf%85%cf%84%cf%83%ce%b9%ce%b1-%ce%bc%cf%80%ce%b1%cf%83%ce%ba%ce%b5%cf%84">zakcret παπουτσια μπασκετ</a>
doog soulder bag green <a href="http://www.citynewsjharkhand.com/elojo_chokio/long-read-crafting-culture-and-commerce-at-burberry">long read crafting culture and commerce at burberry</a> adidas bp classic adicolour tribe yellow <a href="http://www.citynewsjharkhand.com/emerado_fosters/givenchy-infinity-medium-chain-hobo-bag-dark-blue-women-handbags-bags">givenchy infinity medium chain hobo bag dark blue women handbags bags</a> adidas handbags blue and red adidas gym bag small duffel bag <a href="http://www.citynewsjharkhand.com/enoscorner_hilbert/childrens-gym-bags-uk">childrens gym bags uk</a> 10 best smart backpacks with charger 2018 <a href="http://www.citynewsjharkhand.com/flintridge_leonavalley/details-about-mens-travel-duffle-weekend-overnight-bag-waterproof-vintage-canvas-genuine">details about mens travel duffle weekend overnight bag waterproof vintage canvas genuine</a>
sportkläder korta tights newline <a href="http://www.supremenaijanews.com/molinos/angels-tears-diamonds-diamantringar-l%c3%b6sa-diamanter">angels tears diamonds diamantringar lösa diamanter</a> small foot indiantält tepee deluxe <a href="http://www.supremenaijanews.com/mountfern/cgb-loft-ljus-rosa-l%c3%a5da-handtag">cgb loft ljus rosa låda handtag</a> köp rimligt pris jenny känga stövletter kängor grå dam <a href="http://www.supremenaijanews.com/mousie/l%c3%a5gt-pris-dam-korta-halsband-brons-silver-v%c3%a4nskap-friendship">lågt pris dam korta halsband brons silver vänskap friendship</a> soft grey damkläder jackor kappor svart jeansjacka <a href="http://www.supremenaijanews.com/neighbors/new-balance-item-m-vit-bl%c3%a5-new-balance-barn">new balance item m vit blå new balance barn</a>

puma pro training ii medium bag gym bag red best price in india <a href=http://www.nalithazh.com/icard_dorcas/coach-yellow-handbag-for-sale-bags-wallets-for-sale-in>coach yellow handbag for sale bags wallets for sale in</a> mb greene designer vertical essential 2 piece travel bag toiletry timely buys <a href=http://www.nalithazh.com/jolley_lorecity/football-big-net-ball-basketball-bag-buy-at-factory-price-club>football big net ball basketball bag buy at factory price club</a> make today amazing adult <a href=http://www.nalithazh.com/juliet_bluepoint/new-adidas-nmd-r1-lv-logo-black-white-adidas-terrex-boost-indonesia>new adidas nmd r1 lv logo black white adidas terrex boost indonesia</a> best school backpacks reviews 2015 <a href=http://www.nalithazh.com/junoridge_ronneby/nwt-coach-minetta-floral-pink-and-white-bag>nwt coach minetta floral pink and white bag</a>
längd syrafast a4 <a href=http://www.supremenaijanews.com/batavia/active-mode-p%c3%a5-n%c3%a4tet-utlopps-kamouflage-o-nack>active mode på nätet utlopps kamouflage o nack</a> solkräm med betakaroten <a href=http://www.supremenaijanews.com/bellavilla/kort-%c3%a4rml%c3%b6s-cut-out-kl%c3%a4nning-xl-sn%c3%b6r>kort ärmlös cut out klänning xl snör</a> färgläggningbok för barn <a href=http://www.supremenaijanews.com/bigtree/sommarkl%c3%a4nning-med-l%c3%a5ng-%c3%a4rm>sommarklänning med lång ärm</a> nu vill jag göra något riktigt kul bröllopsfotograf skåne <a href=http://www.supremenaijanews.com/birdsville/beyonce-hittar-inte-kl%c3%a4der-som-passar-hennes-rumpa-aftonbladet>beyonce hittar inte kläder som passar hennes rumpa aftonbladet</a>
γυναικεία παπούτσια μποτάκια <a href=http://www.msp-rasd.com/belleterre/shop-shop-patras-%ce%ba%ce%b1%cf%84%ce%ac%cf%83%cf%84%ce%b7%ce%bc%ce%b1-%ce%b3%cf%85%ce%bd%ce%b1%ce%b9%ce%ba%ce%b5%ce%af%cf%89%ce%bd-%cf%81%ce%bf%cf%8d%cf%87%cf%89%ce%bd-%cf%80%ce%ac%cf%84%cf%81%ce%b1>shop shop patras κατάστημα γυναικείων ρούχων πάτρα</a> παιχνιδια στο σπιτι για παιδια 3 ετων <a href=http://www.msp-rasd.com/betsy/%ce%b7-%ce%b4%ce%b9%ce%b1%cf%84%cf%81%ce%bf%cf%86%ce%ae-%cf%84%cf%89%ce%bd-%ce%b1%cf%81%cf%87%ce%b1%ce%af%cf%89%ce%bd-%ce%b5%ce%bb%ce%bb%ce%ae%ce%bd%cf%89%ce%bd>η διατροφή των αρχαίων ελλήνων</a> ανδρικό μαγιό khos γαλάζιο <a href=http://www.msp-rasd.com/bothwell/%ce%b1%ce%bd%cf%84%ce%af%ce%b4%cf%81%ce%b1%cf%83%ce%b7-%cf%84%ce%b7%cf%82-%ce%b5%cf%80%ce%b5%ce%b3%ce%b5-%cf%83%cf%84%ce%b7-%ce%b4%ce%b9%ce%b1%cf%86%ce%ae%ce%bc%ce%b9%cf%83%ce%b7-%ce%b3%ce%b9%ce%b1-%ce%b5%ce%bd%ce%b4%ce%bf%cf%83%ce%ba%ce%bf%cf%80%ce%ae%cf%83%ce%b5%ce%b9%cf%82-%cf%83%ce%b5>αντίδραση της επεγε στη διαφήμιση για ενδοσκοπήσεις σε</a> oxette κολιέ 01x27 γούρι 2019 από ροζ χρυσό ανοξείδωτο ατσάλι <a href=http://www.msp-rasd.com/boxford/%ce%bc%cf%80%ce%bf%cf%85%cf%86%ce%ac%ce%bd-%ce%b1%ce%b4%ce%b9%ce%ac%ce%b2%cf%81%ce%bf%cf%87%ce%bf-%ce%bc%ce%b5-%ce%bb%ce%bf%cf%85%ce%bb%ce%bf%cf%8d%ce%b4%ce%b9%ce%b1>μπουφάν αδιάβροχο με λουλούδια</a>

kvinnors parajumpers dodie vest grön junya watanabe http://www.tracingthetrillions.com/traverse/giftfria-leksaker-h%c3%a5llbart-ekologiskt-och-milj%c3%b6v%c3%a4nligt kläder herr the north face 2016 svart fleece m canyonlands http://www.tracingthetrillions.com/tuthill/silver-kavat-edsbro-xc-baby-skor-barn-utg%c3%a5ng-billiga-skor guldpläterade örhängen kvinnotecken faith http://www.tracingthetrillions.com/vernon/m%c3%a5nadssten-berlock-oktober militärjacka göteborg army gross http://www.tracingthetrillions.com/vidor/tiger-of-sweden-jeans-dam-slender-jeans-i-bl%c3%a5-sverige
6 ιδέες για οικονομική ανακαίνιση σπιτιού http://www.bodybalanz.com/kneohe/%ce%b5%ce%bb%cf%84%ce%b1-%ce%b1%cf%80%ce%bf%cf%83%cf%84%ce%bf%ce%bb%ce%b7-%ce%b4%ce%b5%ce%bc%ce%b1%cf%84%cf%89%ce%bd-%ce%b5%ce%be%cf%89%cf%84%ce%b5%cf%81%ce%b9%ce%ba%ce%bf%cf%85 τρία χρόνια φοράει κορσέ αυτή η 24χρονη αλλά η δακτυλίδι http://www.bodybalanz.com/lafferty/%cf%80%ce%bb%cf%85%ce%bd%cf%84%ce%b7%cf%81%ce%b9%ce%bf-%cf%80%ce%bb%cf%85%ce%bd%cf%84%ce%ae%cf%81%ce%b9%ce%b1-%cf%81%ce%bf%cf%8d%cf%87%cf%89%ce%bd-siemens σακιδια πλατησ πεζοποριασ http://www.bodybalanz.com/lamasco/%cf%84%ce%b6%ce%b9%ce%bd-%cf%80%ce%b1%ce%bd%cf%84%ce%b5%ce%bb%ce%bf%ce%bd%ce%b9%ce%b1-%cf%86%ce%b8%ce%b7%ce%bd%ce%b1-%ce%b1%ce%bd%ce%b4%cf%81%ce%b9%ce%ba%ce%b1 service παππας μαρκας http://www.bodybalanz.com/lazear/nitecore-%cf%86%ce%b1%ce%ba%cf%8c%cf%82-tiny-monster
italy lyst michael michael kors extra small ava leather crossbody bag in white http://www.sieucohoi.com/conneaut_fernley/the-giant-reversible-tote-in-tartan-and-leather-in-tan-pine-green-women givenchy antigona smooth calfskin medium bag http://www.sieucohoi.com/constantine_hudsonville/2019-nike-golf-shoe-bag-tote-black-shoe-bag-065-gray-free-ship brand new polo bag http://www.sieucohoi.com/country_adairsville/replica-givenchy-bags-discount-replica-bags-cheap-replica-handbags herschel mens tour small bum bag black http://www.sieucohoi.com/creedmoor_mamou/ultimate-guide-to-airline-fees
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).

Help Desk Software by Kayako