This is for people who love VIM and also for people who hate VIM.



Some of you may be wondering what VIM is. Let me find the expansion, honestly I don't know.



Here you go:



Vim was created as an extended version of the vi editor, with many additional features designed to be helpful in editing program source code. Its full name is Vi IMproved.

- AND -

vi is a screen-oriented text editor written by Bill Joy in 1976 for an early BSD release. The name vi is derived from the shortest unambiguous abbreviation for the command visual in ex, the command in question switches the line editor ex to visual mode.



That is with the origin...



Ok, this is going to be a multipart series on various tips in using VIM Effectively.

- For VIM Experts, there may be some insights.

- For Novices, this will make you like VIM.



The Effective Use of VIM Series...



» » Effective Use of VIM - Part 1



» Effective Use of VIM - Part 2



» Effective Use of VIM - Part 3



» Effective Use of VIM - Part 4



» Effective Use of VIM - Part 5



== PART 1 ==

vim

alias vi=”vim”

.bash_profile

.vimrc

~

.vimrc



Exiting VIM



Lot of you may not know how to exit VIM. Here are some methods...



[ When you type ESC , you will get to Normal mode. The commands starting with : (colon) are given there. ]



:q - Exits VIM, if no changes yet to be saved.

:q! - Exits VIM, discarding unsaved changes.

ZZ (Just hold SHIFT and press z twice) - Save changes and Exit.

:wq - Save changes and Exit.

:x - Save changes if any and Exit.

CTRL + w, q (While holding CTRL, press w and then q, while pressing q, CTRL is not a must) - Exits VIM, if no changes yet to be saved.



Kill VIM !!! (why would I need that?)



Multiple Windows



VIM supports multiple windows inside the VIM window.



CTRL + w, s – Split Horizontally, reopen the same file in the new window.

CTRL + w, v – Split Vertically

CTRL + w, n – Opens a Blank Window

CTRL + w, c – Close active window

CTRL + w, o – Close all windows except the active one.



[ Closing window occurs only if there is no unsaved changes ]



Match Pairs - %



% is used to match paired characters.

If the cursor is at a starting brace, pressing % will take cursor to the matching closing brace, and vice versa.

This works for () (parantheses), /**/ (block comments) etc.



This is handy, can be used extensively with other commands like d (cut), y (copy) etc.



If you need to delete an entire function block, place cursor at either one of the braces and d% will delete that full block.



Abbreviations



You can use abbreviations for the most commonly used commands snippets.



Define:



iab <key> <expansion>

<key> is the string which should be expanded to <expansion>



You can either add in .vimrc file or give while editing.



Use:



<key><SPACE> will expand to <expansion><SPACE>



You can also use <key><CTRL + ]>



Eg. : iab #i #include

- replace #i with #include



( I dont know a way to disable expanding for a particular instance only, you will have to manually edit that. )



Lot of you may not know how to exit VIM. Here are some methods...[ When you type, you will get to Normal mode. The commands starting with(colon) are given there. ]- Exits VIM, if no changes yet to be saved.- Exits VIM, discarding unsaved changes.(Just hold SHIFT and press z twice) - Save changes and Exit.- Save changes and Exit.- Save changes if any and Exit.(While holding CTRL, press w and then q, while pressing q, CTRL is not a must) - Exits VIM, if no changes yet to be saved.Kill VIM !!! (why would I need that?)VIM supports multiple windows inside the VIM window.– Split Horizontally, reopen the same file in the new window.– Split Vertically– Opens a Blank Window– Close active window– Close all windows except the active one.[ Closing window occurs only if there is no unsaved changes ]is used to match paired characters.If the cursor is at a starting brace, pressing % will take cursor to the matching closing brace, and vice versa.This works for () (parantheses), /**/ (block comments) etc.This is handy, can be used extensively with other commands like d (cut), y (copy) etc.If you need to delete an entire function block, place cursor at either one of the braces andwill delete that full block.You can use abbreviations for the most commonly used commands snippets.Define: is the string which should be expanded to You can either add infile or give while editing.Use:will expand to You can also useEg. : iab #i #include( I dont know a way to disable expanding for a particular instance only, you will have to manually edit that. ) To be continued... Like it? Subscribe via RSS

You may have found out unique ways of doing things in VIM, pls share...



See also... » Adding File Banner to Multiple Files



» Replace Tab using Sed



» 10.1 Linux Commands I Can't Live Without



» Linux Commands I Hardly Knew - Reloaded



» Linux Commands I Hardly Knew



» Unlock a PC on Windiows XP ???

You can execute VIM by the commandIt is better to use VIM than vi. You can just define,and put it in yourThere isfile which stores all the options for VIM, it is in your home directory (). When VIM starts, it will get options from. You can also set options while inside VIM, but they will be lost once you exit VIM.