42LineCounter
A simple Visual Studio Code extension that automatically counts the number of lines in C functions and inserts a comment above each function with the line count. 😸
👀 Like this:
// »»-----► Number of lines: 1
void square(int *x) {
*x = (*x) * (*x);
}
Usage 🛸
The extension provides two commands:
✅ Adding line counters:
- 42 Line Counter: Adds line count comments above each function
- Press
Ctrl + Alt + C
(Windows/Linux)
- Press
Ctrl+ Cmd + C
(Mac)
❌ Removing line counters:
- 42 Line Remove: Removes all previously added line count comments
- Press
Ctrl + Alt + F
(Windows/Linux)
- Press
Ctrl + Cmd + F
(Mac)
Demo 🎥

Supported Languages 🌐
C files (.c
)
Features 🛰️
- 📏 Counts lines inside C functions
- 💬 Writes a comment containing the number of lines
- ❌ Excludes the opening
{
and closing }
braces from the count
- 🧹 Remove feature: Clean up all line count comments
⚠️
Note:
- Counts empty lines within functions
- Does not count comment lines
⚠️
☄️ Installation
📕From the VS Code Marketplace
- Open Extensions in VS Code
- Search for 42LineCounter
- Click Install
📘 Using a .vsix
file
- Download the
.vsix
file from Github
- In VS Code, press
Ctrl + Shift + P
(Windows/Linux) or Cmd + Shift + P
(Mac)
- Type "Extensions: Install from VSIX..."
- Choose the downloaded
.vsix
file
Project Structure
.
├── 42-line-counter-0.0.2.vsix # Packaged VS Code extension file (installable)
├── CHANGELOG.md # Log of changes and version history
├── eslint.config.mjs # ESLint configuration for linting code
├── img # Images used in README, marketplace, or UI
│ ├── demo.gif # Demo animation/GIF showing extension usage
│ ├── logo.png # Main logo for the extension
│ └── logo_.png # Alternative/variant of the logo
├── out # Compiled JavaScript output (from TypeScript)
│ ├── extension.js # Compiled main extension entry file
│ ├── extension.js.map # Source map for debugging extension.js
│ ├── formatters # Compiled formatter utilities
│ │ ├── functionFormatter.js # Compiled function formatter logic
│ │ └── functionFormatter.js.map # Source map for functionFormatter.js
│ └── test # Compiled test files
│ ├── extension.test.js # Compiled extension tests
│ └── extension.test.js.map # Source map for extension.test.js
├── package.json # Project metadata & dependencies for VS Code extension
├── package-lock.json # Exact dependency tree (auto-generated by npm)
├── README.md # Documentation and usage instructions
├── src # Source TypeScript code (before compilation)
│ ├── extension.ts # Main entry point for the extension
│ ├── formatters # Formatter-related logic (TypeScript source)
│ │ └── functionFormatter.ts # Function formatting logic in TS
│ └── test # Test files (TypeScript source)
│ └── extension.test.ts # Tests for the extension
├── tsconfig.json # TypeScript compiler configuration
└── vsc-extension-quickstart.md # Auto-generated guide for creating extensions
⭐ Configuration and Customization
🚨 After Making Changes
- Install dependencies:
npm install
- Recompile:
npm run compile
- Package extension:
vsce package
- Install the generated:
.vsix
file
Renaming Commands
If you want to modify the command names that appear in the VSCode command palette, you need to edit the package.json
file.
⚙️ File to modify: package.json
Find the contributes.commands
section:
{
"contributes": {
"commands": [
{
"command": "42-line-counter.countLines",
"title": "42 Line Counter" ← Modify this title
},
{
"command": "42-line-counter.removeComments",
"title": "42 Line Remove" ← Modify this title
}
]
}
}
Examples : For shorter names
{
"commands": [
{
"command": "42-line-counter.countLines",
"title": "Line Count"
},
{
"command": "42-line-counter.removeComments",
"title": "Remove Count"
}
]
}
🚨 Important note: Only the package.json
file should be modified to rename commands.
The TypeScript code in extension.ts
uses command identifiers (42-line-counter.countLines
and 42-line-counter.removeComments
) which should NOT be changed.
If you want to change the appearance of the comment prefix '// »»-----►'
, you need to modify the extension.ts
file.
File to modify: src/extension.ts
.
├── src
└── extension.ts <--- HERE
Find and modify :
const commentPrefix = '// »»-----►'; ← Change this line
And also update :
return trimmed.startsWith('// »»-----►'); ← Change this line too
Examples
const commentPrefix = '// [LINE COUNT]';
return trimmed.startsWith('// [LINE COUNT]');
🚨 Important: Both lines must use the exact same prefix for the remove function to work properly! 🚨
📜 License
- This project is licensed under the MIT License.
- See MIT License for details.
Changelog 📝
v0.0.1 - Initial release : August 20, 2025
v0.0.2 - Initial release : August 21, 2025