Skip to content

Commit 6d151b0

Browse files
committed
Automated commit on 2023-12-03 16:36:38 CST
1 parent 7703b8f commit 6d151b0

16 files changed

+156
-0
lines changed

content/posts/vim-commentary.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
title: "Unleashing the Power of vim-commentary Plug-in"
3+
date: 2023-12-03T16:32:26+08:00
4+
draft: false
5+
author: "King Tam"
6+
summary: "The incredible vim-commentary plug-in developed by [tpope]"
7+
showToc: true
8+
categories:
9+
- Linux
10+
tags:
11+
- vim-commentary
12+
- Plug-in
13+
- vim
14+
ShowLastMod: true
15+
cover:
16+
image: "img/vim-commentary/Cover.jpeg"
17+
---
18+
19+
### Introduction:
20+
21+
The incredible vim-commentary plug-in developed by [tpope](https://github.com/tpope).
22+
23+
As someone who doesn't use vim frequently, I often forget to take advantage of its features. This post serves as a handy memo to remind myself (and others) about the usefulness of this plug-in.
24+
25+
---
26+
27+
### The Basic Concept of Modes in Vim:
28+
29+
Before we delve into the practical usage of the vim-commentary plug-in, it's essential to grasp the concept of modes in Vim. Vim operates in three primary modes that determine how we interact with the text:
30+
31+
| Mode | Description |
32+
| ------------ | ------------------------------------------------------------ |
33+
| Normal | Default; for navigation and delete or duplicate, etc. |
34+
| Insert | For edit text |
35+
| Command Line | For operations like saving, exiting, or work with plug-in, etc. |
36+
37+
---
38+
39+
### Use the vim-commentary Plug-in:
40+
41+
> The different ways to utilize the vim-commentary plug-in in each mode.
42+
43+
### Normal Mode:
44+
45+
1. #### `gcc`:
46+
47+
In normal mode, entering "`gcc`" comments or uncomments a single line. Repeating the command will toggle the comment status.
48+
49+
![2023-12-03_121111](/img/vim-commentary/2023-12-03_121111.png)
50+
51+
comments
52+
53+
![2023-12-03_121121](/img/vim-commentary/2023-12-03_121121.png)
54+
55+
uncomments
56+
57+
58+
59+
The vim-commentary plug-in also allows us to comment multiple lines at once.
60+
61+
By using the command "`gc`" followed by a `digit number` and the up or down arrow keys (`j`/`k`), we can effortlessly comment or uncomment as many lines as we want.
62+
63+
e.g. `gc`+`3`+`j`
64+
65+
![2023-12-03_160908](/img/vim-commentary/2023-12-03_160908.png)
66+
67+
comments
68+
69+
![2023-12-03_160916](/img/vim-commentary/2023-12-03_160916.png)
70+
71+
uncomments
72+
73+
2. #### `gc` + `j`/`k`:
74+
75+
Using "`gc`" followed by the up or down arrow keys (`j` or `k`) allows us to comment or uncomment two lines simultaneously, with the indicator adjusting accordingly.
76+
77+
![2023-12-03_121304](/img/vim-commentary/2023-12-03_121304.png)
78+
79+
comments
80+
81+
![2023-12-03_121317](/img/vim-commentary/2023-12-03_121317.png)
82+
83+
uncomments
84+
85+
3. #### `gcap`:
86+
87+
Typing "`gcap`" in normal mode comments or uncomments an entire paragraph or block of text efficiently.
88+
89+
![2023-12-03_121703](/img/vim-commentary/2023-12-03_121703.png)
90+
91+
comments
92+
93+
![2023-12-03_121710](/img/vim-commentary/2023-12-03_121710.png)
94+
95+
uncomments
96+
97+
### Command Line Mode:
98+
99+
1. #### `:107,113Commentary`:
100+
101+
This command lets us comment or uncomment lines 107 to 113. Executing the command again will undo the action.
102+
103+
![2023-12-03_121851](/img/vim-commentary/2023-12-03_121851.png)
104+
105+
comments
106+
107+
![2023-12-03_121942](/img/vim-commentary/2023-12-03_121942.png)
108+
109+
uncomments
110+
111+
2. #### `:g/alias /Commentary`:
112+
113+
By using this command, we can comment or uncomment lines that match a specific pattern, such as "**alias** " Repeating the command will revert the action.
114+
115+
![2023-12-03_122054](/img/vim-commentary/2023-12-03_122054.png)
116+
117+
comments
118+
119+
![2023-12-03_122102](/img/vim-commentary/2023-12-03_122102.png)
120+
121+
uncomments
122+
123+
### Visual Mode:
124+
125+
The other modes, Vim also offers a Visual Mode. In this mode, we can select lines and use the "`gc`" command to comment or uncomment them effortlessly.
126+
127+
![2023-12-03_122226](/img/vim-commentary/2023-12-03_122226.png)
128+
129+
comments
130+
131+
![2023-12-03_122242](/img/vim-commentary/2023-12-03_122242.png)
132+
133+
uncomments
134+
135+
---
136+
137+
### Conclusion:
138+
139+
The vim-commentary plug-in significantly enhances text editing efficiency.
140+
141+
By familiarizing ourselves with its capabilities, we gain the ability to seamlessly comment on or uncomment lines, paragraphs, and even specific patterns of text.
142+
143+
---
144+
145+
### Reference:
146+
147+
- https://github.com/tpope/vim-commentary
148+
149+
---
150+
151+
### Related:
152+
153+
- [Linux 的命令基本用法 - vim 編輯器](https://kingtam.win/archives/vim.html)
154+
155+
- [Install VIM-PLUG on Synology DSM](https://kingtam.eu.org/posts/dsm-custom/#install-vim-plug-on-synology-dsm)
156+
- [NeoVim and Vim plugins Install in Alpine Linux](https://kingtam.eu.org/posts/alpine-customization/#neovim-and-vim-plugins-install-in-alpine-linux)
24.9 KB
Loading
25.4 KB
Loading
30.7 KB
Loading
31.4 KB
Loading
Loading
32.7 KB
Loading
34.4 KB
Loading
32.4 KB
Loading
33.2 KB
Loading
33.2 KB
Loading
Loading
27.2 KB
Loading
32.9 KB
Loading
Loading

static/img/vim-commentary/Cover.jpeg

297 KB
Loading

0 commit comments

Comments
 (0)