Monday, May 31, 2021

VIM

You wanna learn Vim.

Why vim?

Let's start by asking why do you want to learn vim? Probably you've realized the efficiency of the editor and make your daily life faster or may be you've seen a YouTube video or you're friend may have suggested you to take a look or you just wanna look cool among your friends. Anyway learning vim is one of the most useful things if you're an engineering students rather than learning about how a Transformer in your second semester. I can assure you this. If you have any doubts about wasting time about this weird command based editor which is alienatic to vs code or sublime users, don't think about it, because it's worth it. Let me just tell you this if you've learned at least vim basics, you feel stupid you feel you've wasted a lot of time, why? because you ask yourself why didn't I learn this before? If you've read till here chances are you wanna learn vim, lets continue. Learn with practice, open a file and try executing these commands, they'll become almost second nature to you if you spent decent amount of time on it.


Basics

I hope you've installed vim in your computer. Just open your command prompt and navigate to a directory and create a simple text file. Then type the following command

vim test.txt

Vim is a command based editor. There are different types of modes in vim.

Modality -
    insert - enables you to insert the text into the file
    normal - this mode is for navigation and one should spend most of the time 
                 in normal mode.
    command - enables you to use commands when necessary

Motions in Vim:
    i - Enter insert mode at cursor
    I - Enter insert mode at the first non blank character
    s - Delete character under cursor and enter insert mode
    S - Delete line and begin insert at beginning of same line
    a - Enter insert mode after the cursor (basically append)
    A - Enter insert mode at the end of the line
    o - Enter insert mode on the next line
    O - Enter insert mode on the previous or above line
    C - Delete from cursor to end of line and begin insert

Switching Modes:
    normal -> insert = i or a (anything from the above mentioned motions)
    insert -> normal = ESC
    normal -> command = : (colon)
    insert -> command = insert -> normal -> command

Moving the Cursor
    
                k
                ^
h<                                >l
                v
                j

one must h, j, k, l because they are on the home row and you doesn't have to move your hands to the arrow keys and come back again which is basically using mouse on the keyboard.  

So you want to edit a word on the line, so you are not gonna press l until you reach that word that's a heavy process, instead you wanna move faster.
The commands below are for you.

Basics: wWbBeE
  
    word - separated by non-alphabets
    WORD - separated by whitespaces
    w - Forward to the beginning of the next word
    W - Forward to the beginning of the next WORD
    b - Backward to the next beginning of a word
    B - Backward to the next beginning of a WORD
    e - Forward to the next end of word
    E - Forward to the next end of WORD    



Searching in Vim
      
    You want to search a word in a large file and edit that, you cannot waste your 
    time navigating and searching for that word.
    Lets see what else you can do?
            
    / - Forward
    ? - Backward
    * - Word under cursor - forward(bounded)
    g* - Word under cursor - forward (unbounded)
    # - Word under cursor - backward (bounded)
    g# - Word under cursor - backward (unbounded)
    n - next result forward
    N - next result backward
        
    For example: open a file and go to normal mode and type "/" you should see
    cursor waiting for you at the bottom of your screen and type the text you want     to search it will highlight the text and press n for the next result forward and 
    press N for the next result backward.




What is .vimrc?

So this is basically a settings file for vim. You are not gonna have a gui settings for vim like vs code. Add this basic vimrc file to you vimrc file. How do you do that?
So open this downloaded file and copy all the text and open your vimrc file by typing: vim ~\.vimrc (~ represents home directory), and paste all the content to the file and save it.


This should be enough for you to get started with vim. There are a lot more, a lot more, you're never gonna touch the ceiling neither am I. So let's start with basics and extend it from there when needed.








    



Best PDF Reader you probably never heard of

 MuPDF What is MuPDF? Its a pdf reader. If you have to work with PDFs frequently on day to day basis, well this blog post is for you. Well y...