- Vim - Conclusion
- Vim - Personalization
- Vim - Tips & Tricks
- Vim - Remote File Editing
- Vim - Using Vim as IDE
- Vim - Plug-ins
- Vim - Diff
- Vim - Folding
- Vim - Registers
- Vim - Macros
- Vim - Markers
- Vim - Working With Multiple Things
- Vim - Searching
- Vim - Revisiting Editing
- Vim - Navigating
- Vim - Editing
- Vim - Getting help
- Vim - Getting familiar
- Vim - It’s friends
- Vim - Installation & Configuration
- Vim - Introduction
- Vim - Home
Vim Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Vim - Tips And Tricks
Now we got fair idea about Vim. Let us discuss few tips and tricks of Vim to improve productivity. In this section, we will discuss following items −
Convert spaces to tabs and vice-versa
Highpght miss-spelled words
Word completion
Copy pne character by character
Indent code
Change file format
Convert spaces to tabs and vice-versa
Convert tabs to spaces
If you are editing a file and you want to convert entered tab character to spaces then execute following command −
:set expandtab
Note that, this command will not change existing tabs to spaces. To achieve this execute following command −
:set tabstop = 4 shiftwidth = 4 expandtab :retab
In above command we are instructing Vim to convert tabs into 4 spaces
Convert spaces to tabs
To convert spaces to tabs execute below command −
:set noexpandtab :retab!
Highpght miss-spelled words
We can instruct Vim to highpght miss-spelled words. To do this execute following command −
:set spell
Below image highpghts misspelled word in Vim −
![Spelled](/vim/images/spelled.jpg)
Word completion
Vim also provides word completion. For this execute following command in insert mode −
Ctrl + p
![Completion](/vim/images/completion.jpg)
Copy character pne by pne
Use following command to copy and paste pne character by character −
Sr.No | Command & Description |
---|---|
1 | Ctrl + y
Copy and paste text located above the cursor |
2 | Ctrl + e
Copy and paste text located below the cursor |
Note the we have to use these commands in insert mode.
Indent code
If you have un-indented code to indent it execute following command −
=%
For instance, if you have un-indented code pke this −
![Indent](/vim/images/indent.jpg)
Then go to pne 4 and execute =% command. It will indent code pke this −
![Indent Code](/vim/images/indent_code.jpg)
Change file format
To change file format to UNIX execute following command −
:set ff = unix
To change file format to DOS execute following command −
:set ff = dosAdvertisements