Vim is fantastic. It doesn’t crash, its full of features, it’s lightweight, it’s customizable with plugins and extensions and it runs from the command prompt.
In this tutorial we will try to walk you from zero to proficiently using VIM to write and edit solely in VIM in a few minutes.
Provided by HolyPython.com
- Creating Code
- Editing Code
- Allows editing from Command Prompt
- Can be very useful in systems where nothing’s installed and only command line is available
VIM Installation is pretty simple and straightforward but there are a few points you need to pay attention to, to ensure a 100% successful installation.
You can find appropriate installation find for your system in this link.
Vim is available for Many operating systems such as Windows, Linux and Mac. You can also install the 64-bit version for Windows.
Most importantly make sure you save the installation file first and then run it as an administrator.
If you ignore this step VIM will likely fail to make the necessary adjustments and you won’t be able to open files with VIM from Command Prompt.
vimfrom any command prompt in your computer and proceed to initiate a brand new file. Below, launching vim to open a specific Python file (or any other code or text file) is also explained.
Launching VIM (From command prompt)
- First launch a Command Prompt you prefer. It can be:
- Windows Command Prompt
- Anaconda Command Prompt
- Navigate to the directory you want to edit files at. Using cd and/or cd..
- Open Python file with following command:
vim pythonfile.py, just replace filename with your file’s real name.
First time in VIM (Main modes and functions)
Now you’ve already installed VIM and managed to enter the program. You’re pretty much there with starting to use VIM as you wish. However, there are a few concepts that might seem confusing if it’s your first time with VIM.
First of all you won’t be able to type or edit anything when you first launch VIM. Don’t worry it’s easy to get there. This is because there are 2 modes in VIM:
- Command Mode
- Editor Mode
You’ll know you’re in command mode if it doesn’t say –INSERT– at the bottom or if the cursor is blinking at full character height.
You’ll know you’re in editor mode if it says –INSERT– at the bottom or if the cursor is blinking only as a little underscore.
- You can switch to Editor Mode by pressing “
- You can switch back to Command Mode by pressing “
You need to be in Editor Mode to be able to type code or modify existing code.
VIM Basic Commands
You can switch to Command Mode to be able to type commands such as “Save”, “Quit”, “Save and Quit” etc. Commands always start with colon “:” Here are some examples:
:q >>> Quits
:w >>> Saves
:wq >>> Saves and Quits
Below, you can find more useful commands.
VIM Shortcut Keys
Here are some basic Shortcut Keys and VIM commands. These are crucial to know to use VIM since VIM is not a GUI application. These are only the basic commands and should get you up to speed with VIM. There is much more to VIM if you become more interested.
We have already discussed i and Esc keys to switch between Editing and Command Modes. Here are some more shortcuts that can be very useful while editing code with Vim.
h j k l : moves cursor left, down, up and right
A : Appends at the end of the line
o : New line
u : undo
x : deletes character
dw : deletes until the next word
dd : deletes line (also saves to clipboard)
p : pastes
:wq : writes and quits
:x : writes and quits
:w filename : writes a copy of the file as filename
:q! : quits without saving even if changes were made!
:help : display help
: Tab completion, shows all commands, use right-left keys to navigate once bottom menu pops up.
/someword : searches (replace someword with your query)
- If you press “*” key while on a word, it will search for the word under the cursor in the entire document and highlight the results. (# key can also be used for same purpose)
- n or N can be used to navigate through the search results (backwards and forwards)
- You can also type “/” in command line to initiate a search by typing your query.
Key Takeaway Points:
- VIM is preferred by many for being lightweight and crash-free
- It also allows you to write code in command prompt
- As soon as you learn a few tricks, keys and shortcuts VIM becomes a breeze.
- VIM is open-source
- Vim is a great alternative to IDEs and regular text editors.
- Once you get used to coding in VIM, you won’t believe how light it feels sometimes. If you are a big fan of glitchless applications Vim will feel really good.
You can check out VIM’s homepage here for updates, notes, documentation, more info and showing support.