Staging Hunks

Usually, we stage files before committing them:

$ git add vimrc
$ git commit -m 'Update vimrc'
[master f4efe1d] Update vimrc
 1 file changed, 1 insertion(+)

However, we can also stage individual hunks in a file if we only want to commit part of the changes in that file:

$ git add --patch vimrc
diff --git a/vimrc b/vimrc
index c493cca..8a95218 100644
--- a/vimrc
+++ b/vimrc
@@ -56,7 +56,7 @@ endif
 " Git
 " -----------------------------------------------------------------------------
 Plug 'tpope/vim-fugitive'
-Plug 'airblade/vim-gitgutter'
+" Plug 'airblade/vim-gitgutter'
 Plug 'rhysd/conflict-marker.vim'

 " -----------------------------------------------------------------------------
Stage this hunk [y,n,q,a,d,/,e,?]?

The git add --patch or git add -p command allows us to select hunks interactively for staging. You can type ? during the process to print the help message to understand what each letter means:

y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

Tags: git

Managing Links in Markdown

Quite often, we find ourselves inlining links in Markdown like so:

This is a [link](https://www.example.com). I really like links like
[this](https://www.example.com).

Actually, we can use reference-style links to reduce the clutter effectively. This is when we define all our links at the bottom:

This is a [link][1]. I really like links like [this][1].

[1]: https://www.example.com

Note the usage of [] instead of ().

Comparing Two Branches

To compare two branches, just do git diff feature..develop.

Tags: git

Go to File in Vim

Even if you have tags configured, sometimes, ctrl-] might not bring you to the source of the keyword. So, it might be useful to use gf to go to the file directly.

import HeaderActions from '../../redux/HeaderRedux'
                                  ^ (gf)

Tags: vim

Deleting Words in Insert Mode

While typing in Insert Mode, you can use Ctrl-W to delete one word to the left of the cursor, or use Ctrl-U to delete everything to the left.

hello world and goodbye
           ^ (Ctrl-W)
hello and goodbye
hello world and goodbye
               ^ (Ctrl-U)
goodbye

Tags: vim