The most useful regular expression
        " :h non-greedy
        " non-greedy matches, it matches as less as possible
        " *    => match as many as possible
        " \{-} => match as less as possible 
        " e.g. matches all html from open-angle-bracket to close-angle-bracket 
        :%s/<.\{-}> 
        
Vim Tips
        " delete line contain pat1 above one line with pat2
        :g/pat1/ . -1, /pat2/d

        " delete line contain pattern from pat1 to pat2 
        :g/pat1/,/pat2/d

        " delete line DOES contain pattern
        :g/pattern/d

        " delete line DOES NOT contain pattern
        :g!/pattern/d

        " run man page inside vim
        :runtime ftplugin/man.vim
        :Man grep

        " how to append content to register
        :"Ayy    

        " split String to list
        split(str, '\zs')

        " redirect Ex command output to register [h redir]
        :redir @a | ls | redir END 

        " redirect Ex command output to file
        :redir > /tmp/log.txt |ls | redir END

        " redirect Ex command output to variable var
        :redir =>var |g/pattern/p | redir END

        " replace word with current buffer file name [h expand()], [h \=]
        :s/word/\=expand('%')/gc

        " increase number by one [h \=, :h submatch()]
        :s/\d\+/\=submatch(0) + 1/gc

        " select word under cursor
        <C-R><C-W> 

        " select the current character
        /\%#         

        " select the current word under cursor
        /\k*\%#\k*   

        " select the iskeyword character from 0 to 10 column
        /\k*\%10c    

        " redirect shell output to current buffer [h :r] r => read
        :r! ls    

        " move cursor to top/bottom of page                    
        <S-h> <S-l>    

        " add file path to register                   
        :let @a=expand("%:p")    

        " open file inside the register in Ex mode                     
        :exec 'edit ' @a    

        " move lines to different location, move line 2 to line 4 to top                     
        :2, 4 m 0    

        " filter g [match] and v or g! [not match]                    
        move lines contains pat to line 9
        :g/pat/ m 9     

        " move lines doesn't contains pat to line 9
        :v/pat/ m 9    

        " range 2 to 10 contains pat are moved to 9
        :2, 10 g/pat/ m 9     

        " A sequence of optionally matched atoms, 
        " it matches as much of list of atoms it contains as possible.
        \%[] 
        /r\%[ead] match r, re rea read     
        []
        /r[ead] match re ra re     

        " commands that save Vim folding states in vimrc file
        autocmd BufWinLeave *.* mkview
        autocmd BufWinEnter *.* silent loadview
        
        " delete n lines from the pattern matched in all buffers 
        :bufdo! exec "/pattern"  | ".,+n .d" | update
        | is chain two commands

        " stdin to vim  
        ls | vim -
        - vim accepts stdin

        " Vimrc file multiline String  
         let @*='first line \n \ second line'

        " Open URL from Vim  
        gx

        " Open file from Vim  
        gf

        " Start of line [^]  
        :./^\s*\w.*\w$//gc

        " Start of line [\_^], can be used anywhere in the pattern 
        :./^\s*\w.*\w$//gc

        " Vim match negative matching, delete all lines don't contains cat 
        :g!/cat/d

        " Substitute Visual mode, [something] 
        's/\%V.*\%V/[\0]/gc

        " Select from current line to next pattern "foo" 
        v/foo

        " Select current paragraph or all consecutive lines 
        vap

        " Show lines match word under cursor 
        [I

        " Command Line autocomplete 
        :h subs<C-D> and <Tab>

        " Copy Column and Paste
        <C-V> select column and paste it
        
Add undo persistence in Vim
        set undofile                " Save undo's after file closes
        set undodir=$HOME/.vim/undo " where to save undo histories
        set undolevels=1000         " How many undos
        set undoreload=10000        " number of lines to save for undo
        [:h undo-persistene]
        
Operators in Vim
        =       indentation e.g gg=G [h =]
        c		change
        d		delete
        y		yank into register (does not change the text)
        gu		make lowercase
        gU		make uppercase
        !		filter through an external program
        gq		text formatting
        g?		ROT13 encoding
        >		shift right
        <		shift left
        zf		define a fold
        g@		call function set with the 'operatorfunc' option

        Left-right motion
        h       character to the Left
        l       character to the Right
        0       to the first character of the line
        ^       to the first non-bank character of the line
        $       to the end non-bank character of the line
        g_      to the last non-bank character of the line  
        
You need to be a leader, mapleader, localLeader maplocalleader
        :nnoremap <Buffer><Leader>s :%s/dog/cat/g <Esc> 
        Leader is special string that you can use to map character to shortcut key
The default mapping is '\' character When you type \s the shortcut will trigger :%s/dog/cat/g If you want to change the default mapping to different character, then you can type
:let mapleader="," which will map ,s instead of \s and it can trigger :%s/dog/cat/g
LocalLeader is similar to Leader but it is to be used for mapping which are local to a buffer :map <buffer><LocalLeader>A :%s/dog/cat/g <Esc>
How to use command History in Vim
        Today, I just learn something new on how to use Command History in Vim.
        If you are typing a lots in Ex mode, then there are lots repeating commands that you want to call it again and again.
        There are lots of way to do in Vim such as Abbreviation or Map.
        But the quick way to repeating the command is to open the history and search the command, then press Eneter
        1. Open command history q:
        2. Search the command like Normal Mode
        3. Press Enter to execute the command under your cursor. Done
        4. [:h q:] [:h q/] [:h q?]