🎓 42 School Extra
The 42 extra provides tools specifically designed for 42 School students, including the standard header, C formatter, and line counter.
Enabling
Add this to your ~/.config/nvim/lua/config/lazy.lua:
{ import = "ftvim.plugins.extras.lang.42" },
Requirements
C Formatter
The C formatter requires the c_formatter_42 Python package:
pip install c-formatter-42
Or with pip3:
pip3 install c-formatter-42
Python Linters (Optional)
For Python linting with flake8 and mypy:
pip install flake8 mypy
Or install them via Mason inside Neovim:
:MasonInstall flake8 mypy
Features
42 Header (Stdheader)
Insert the standard 42 header at the top of your file.
| Keymap | Command | Description |
|---|---|---|
<leader>Fh | :Stdheader | Insert 42 header |
The header uses your username and email. Configure them by setting environment variables:
export USER42="yourlogin"
export MAIL42="yourlogin@student.42.fr"
Or in your ~/.config/nvim/lua/config/options.lua:
vim.g.user42 = "yourlogin"
vim.g.mail42 = "yourlogin@student.42.fr"
C Formatter (42 Norm)
Format C files according to 42's coding norm.
| Keymap | Command | Description |
|---|---|---|
<leader>Ff | :CFormatter42 | Format current C file |
This formatter works on .c files. Make sure you have c_formatter_42 installed via pip.
Line Counter
Count the number of lines in your C functions (useful for the 25-line limit in 42's norm).
| Keymap | Command | Description |
|---|---|---|
<leader>Fc | :FtCountLines | Count lines in functions |
Python Linting
When editing Python files, the 42 extra enables automatic linting with:
- flake8 - Style and syntax checking
- mypy - Type checking (strict mode)
Linting runs automatically on save and when leaving insert mode. Diagnostics appear in the gutter and can be viewed with K or in the diagnostics list (<leader>xl).
Keymaps Summary
All 42 keymaps are under <leader>F:
| Keymap | Description |
|---|---|
<leader>Fh | Insert 42 header |
<leader>Ff | Format C code (42 norm) |
<leader>Fc | Count lines |
<leader>Fk | View keymaps |
Included Plugins
| Plugin | Description |
|---|---|
| 42header | Official 42 header plugin |
| c_formatter_42.vim | C formatter for 42 norm |
| ft_count_lines.nvim | Line counter for C functions |
| nvim-lint | Linting engine for Python |
Troubleshooting
"CFormatter42 not an editor command"
- Make sure the 42 extra is enabled in
lazy.lua - Restart Neovim and run
:Lazyto install plugins - Open a
.cfile (the plugin only loads for C files) - Try
:CFormatter42again
Header shows wrong username
Set your username and email:
-- In lua/config/options.lua
vim.g.user42 = "yourlogin"
vim.g.mail42 = "yourlogin@student.42.fr"
Or use environment variables:
export USER42="yourlogin"
export MAIL42="yourlogin@student.42.fr"
Formatter not working
-
Check if
c_formatter_42is installed:pip show c-formatter-42 -
If not installed:
pip install c-formatter-42 -
Make sure the
c_formatter_42command is in your PATH