Technocrazian Hack the Code

CLI#1 : The Vim Editor

Howdy all,
So, as posted earlier, this is my first post on the series of various CLI tools I use.
In this post I'll be discussing about an awesome CLI text editor - The Vi Editor. Well specifically, its modified version - The Vim Editor. Before beginning, I have to make a declaration. I am totally not interested in the editor war and have no grudge against Emacs. When I used Emacs, I found it was a little memory hungry, so I decided to use Vim instead. Emacs is also a pretty good text editor with various features.With that told, let us begin the Vim journey.Vim is a screen-oriented text editor, i.e , it runs in the console. Vi editor will be installed by default in most of the operating systems. To install vim, in debian based OSs, you need to give

sudo apt-get install vim


The following is a screenshot of vim running in my system with a python file.

vim

Vim editor mainly has three modes - the command mode, the text mode and the visual mode. As the name suggests, the command mode is used to punch in commands to alter text and perform operations on the text and the text mode is the one in which you type stuff. Every keystroke in the command mode is a command. It can be to delete stuff, change stuff, cut, copy paste and so on. In text mode, every keystroke places the corresponding keys to the monitor (except control,function and other special keys which doesnot represent any character). The visual mode is a special mode used to perform text selection. It is the only way to select a block of text.

By default, vim starts in command mode. It can be changed to text mode by hitting any of the insertion commands - i, I, a, A, o, O. These commands perform different tasks which can be found here.

To change to visual mode from command mode, press the key v. By moving the cursor using hjkl keys (refer the link above) or arrow keys (Vi editor doesnot support this, but Vim does), you can select parts of text.

To come back to command mode from visual or insert mode you can either press Escape key or the combination Ctrl+c. I prefer the latter because it involves less movement and finger stretching.

I am not gonna explain about all the commands because they are easily available in the link I shared above (and also because I don't know all of them).
There are some other stuff regarding Vim that one must be aware of.
They are
1. Configuration File
2. Plugins
3. Some to-read documents and videos.

First, lets talk about the configuration file. On startup, vim checks for the existence of a special file called configuration file and prepares the environment as specified in that file. The configuration file for a user is placed in his/her home directory under the name ".vimrc". The "." at the beginning makes it hidden file and the "rc" means "run commands"(as the purpose of configuration file is to run specific commands at startup to prepare the environment as per the user's need). vimrc file can be used to specify which all actions to be performed during the startup. My vimrc file can be found here. I have added comments to describe what the various lines wherever possible and whenever I had free time. ;)

Next, we come to plugins. Plugins are used to extend vim's functionality beyond the basic ones. It is used to bring more features that helps us to perform what we need faster. One example will be " a plugin that automatically closes html tags" or "a plugin that provides autocompletion" or "a plugin that provides autocorrect feature". Plugins can be installed using various ways, but I use one using a tool called "pathogen". Pathogenalso is a vim plugin whose function is to manage vim plugins. In usual vim scenario, all plugin files are inside a .vim directory in the user's home directory. However, these are scattered over different directories like bundle, autoload, plugin etc. This creates an ambiguity on which vim file corresponds to which plugin. Pathogen brings a solution to this problem by allowing each plugin to have its own subdirectory, so that, management of the plugin is done inside that directory. If you want to uninstall the plugin, just delete the subdirectory. Get pathogen and know more about it from here. The following are some of the plugins I use (as I am also a programmer, most of them are related to that field)
1. closetag - to close html tags easily
2. ctrlp - file navigator
3. fugitive - git support
4. nerdcommenter - easy commenting and uncommenting - programming
5. nerdtree - tree like file navigator
6. vim-airline - cool status bar
7. vim-autocorrect - autocorrect
8. vim-flake8 - syntax checker
9. vim-rails - rails support
10. jedi-vim - autocomplete - programming

Next, I will listout some references that I used to get interested in Vim. This includes web pages, books, videos etc.
1. http://www.viemu.com/a-why-vi-vim.html
2. https://www.youtube.com/watch?v=YhqsjUUHj6g
3. http://learnvimscriptthehardway.stevelosh.com/ - customizing vim
4. Vim official documentation
5. Surprise, vim has an inbuilt help that can be accessed by the command :help (yes, that colon is there.)

This post was never meant to be an authentic resource for learning vim or about the vim commands. This was just an introduction to vim and the basic concepts. As we can learn swimming only by getting into the pool, use vim and learn vim is the best way. The few advantages I found about using vim are - Less memory than GUI apps, no need of the time-consuming steps of take hand from keyboard-place it on mouse-move mouse-clicl-get hand back to keyboard, get acquainted with configuration files, and last but not least, improve your typing abilities as practice maketh perfect.
Suggestions to make the article are welcome.

PS: Once the series about CLI are finished and I still have the enthusiasm, I'll try to elaborate on this.