Skip to main content

🎓 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.

KeymapCommandDescription
<leader>Fh:StdheaderInsert 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.

KeymapCommandDescription
<leader>Ff:CFormatter42Format current C file
note

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).

KeymapCommandDescription
<leader>Fc:FtCountLinesCount 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:

KeymapDescription
<leader>FhInsert 42 header
<leader>FfFormat C code (42 norm)
<leader>FcCount lines
<leader>FkView keymaps

Included Plugins

PluginDescription
42headerOfficial 42 header plugin
c_formatter_42.vimC formatter for 42 norm
ft_count_lines.nvimLine counter for C functions
nvim-lintLinting engine for Python

Troubleshooting

"CFormatter42 not an editor command"

  1. Make sure the 42 extra is enabled in lazy.lua
  2. Restart Neovim and run :Lazy to install plugins
  3. Open a .c file (the plugin only loads for C files)
  4. Try :CFormatter42 again

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

  1. Check if c_formatter_42 is installed:

    pip show c-formatter-42
  2. If not installed:

    pip install c-formatter-42
  3. Make sure the c_formatter_42 command is in your PATH