About

Swaroop C H is 29 years of age. He is a coder and startupper. He has previously worked at Yahoo!, Adobe, his own startup and Infibeam.

Read more about him

Views
COLLECTION
Collection

Vim hu:Introduction

From Notes

Jump to: navigation, search

Mi is az a Vim?

Egy szövegszerkesztő program, amivel bármit írhatsz: jegyzetet, könyvet vagy programkódot.

Egyszerű és hatékony. Ez emeli ki a hasonló programok közül.

Miért egyszerű? A felhasználói felület nincs túlzsúfolva. Szinte csak a szöveget látod, amit írsz. Egyszerű, mert néhány alapelv elsajátítása után elkezdhetsz dolgozni. Később ezeket alapul véve elmélyülhetsz a Vim rejtelmeibe.

Miért hatékony? Gyorsabban, jobban és könnyebben dolgozhatsz benne. Bonyolultabb szerkesztési műveletek is rövid parancsokkal megoldhatók. Kevés gépeléssel nagy hatékonyságot érhetsz el.

Mit is tud a Vim?

Hallom, ahogy mondod: - Ez csak egy szövegszerkesztő, és akkor mi van?

Rendben.

Lássunk néhány példát, hogy összehasonlítsuk a Vim-et az aktuális szövegszerkesztőddel. Ennek a gyakorlatnak az a lényege, hogy válaszolhass arra a kérdésre: Az én szövegszerkesztőmben hogy csinálom megy ugyanezeket?

Megjegyzés
Ne aggódj túl sokat a Vim parancsok részletei miatt, csak az a cél hogy rámutassunk a lehetőségekre, és nem az, hogy megértsük a működés részleteit. Erről szól a könyv hátralévő része.

Kérdés

Megoldás Vim-el

Hogy mozgatom a kurzort lefele hét sorral?

7j - Üsd be a billentyűzeten a karaktereket egymás után.

Hogyan törlök egy szót?

dw

Szeretnék keresni a szóra a fájlban, amin a kurzor áll. Hogyan?

*

Miként cseréljek le szövegrészeket a fájl egy adott részén, az 50-ik és 100-dik sorok között?

:50,100s/old/new/g

Kettéoszthatom-e a képernyőt, hogy ugyanazon fájl két részletét egyszerre lássam?

:sp

A kurzor egy szó felett villog, ami történetesen egy fájl neve. Hogyan tudom gyorsan megnyitni?

gf Jelentése: 'g'o, 'f'ile (Menj a fájlhoz)

Választhatok-e más színösszeállítást a szövegek kiemeléséhez?

:colorscheme desert - A 'desert' színösszeállítás kiválasztása.

A ctrl-s gyorsbillentyűt hozzárendelhetem-e a fájl mentéséhez?

:nmap <c-s> :w<CR> - A <CR> jelentése: 'c'arriage 'r'eturn, (enter leütése)

El tudom-e menteni a szövegszerkesztő aktuális állapotát, hogy a most megnyitott fájlokat és beállításokat látva tudjam folytatni a munkát?

:mksession ~/latest_session.vim
Következő alkalommal így indítsd a Vim-et parancssorból:
vim -S ~/latest_session.vim

What if you wanted to see colors for different parts of your code?

Run :syntax on. If it doesn't recognize the language properly, use :set filetype=Wikipedia, for example.

What if you wanted different parts of your file to be folded so that you can concentrate on only one part at a time?

Run :set foldmethod=indent assuming your file is properly indented. There are other methods of folding as well.

What if you wanted to open multiple files in tabs?

Use :tabedit <file> to open multiple files in "tabs" (just like browser tabs), and use ctrl-pgup/ctrl-pgdn to switch between the tabs.

You use some words frequently in your document and wish there was a way that it could be quickly filled in the next time you use the same word?

Press ctrl-n and see the list of "completions" for the current word, based on all the words that you have used in the current document. Alternatively, use :ab mas Maslow's hierarchy of needs to expand the abbreviation automatically when you type m a s <space>.

You have some data where only the first 10 characters in each line are useful and the rest is no longer useful for you. How do you get only that data?

Press ctrl-v, select the text and press y to copy the selected rows and columns of text.

What if you received a document from someone which is in all caps, find it irritating and want to convert it to lower case?

In Vim, run the following:

:for i in range(0, line('$'))
:    call setline(i, tolower(getline(i)))
:endfor

Don't worry, other details will be explored in later chapters. A more succinct way of doing this would be to run :%s#\\(.\\)#\\l\\1#g but then again, it's easier to think of the above way of doing it.

There is an even simpler method of selecting all the text (ggVG) and using the u operator to convert to lowercase, but then again that's too easy, and isn't as cool as showing off the above way of making Vim do steps of actions.

Phew. Are you convinced yet?

In these examples, you can see the power of Vim in action. Any other editor would make it insanely hard to achieve the same level of functionality. And yet, amazingly, all this power is made as understandable as possible.

Notice that we didn't use the mouse even once during these examples! This is a good thing. Count how many times you shift your hand between the keyboard and the mouse in a single day, and you'll realize why it is good to avoid it when possible.

Don't be overwhelmed by the features here. The best part of Vim is that you don't need to know all of these features to be productive with it, you just need to know a few basic concepts. After learning those basic concepts, all the other features can be easily learned when you need them.


</div>

Please add your comments by clicking on the 'Discussion' link in the left sidebar.