Skip to content

Format code C/C++ according to the 42 norm V3 directly in Nvim. Written in Lua.

License

Notifications You must be signed in to change notification settings

Diogo-ss/42-C-Formatter.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🛸 42 C Formatter

✨ Features

  • use CFormat42 to format current buffer

⚡ Requirements

🎈 Setup

📦 Packer.nvim

use { "Diogo-ss/42-C-Formatter.nvim" }

💤 Lazy.nvim

{ "Diogo-ss/42-C-Formatter.nvim" }
{
  "Diogo-ss/42-C-Formatter.nvim",
  cmd = "CFormat42",
  config = function()
    local formatter = require "42-formatter"
    formatter.setup({
      formatter = 'c_formatter_42',
      filetypes = { c = true, h = true, cpp = true, hpp = true },
    })
  end
}

🔌 Vim-plug

call plug#begin()
  Plug 'Diogo-ss/42-C-Formatter.nvim'
call plug#end()

⚙ Options

{
  formatter = 'c_formatter_42',  -- The formatter to be used (e.g., 'c_formatter_42')
  filetypes = {
    c = true,     -- C files
    h = true,     -- C header files
    cpp = true,   -- C++ files
    hpp = true    -- C++ header files
    -- Add more file extensions here and set them to true as needed.
  }
}

🎨 Quick format

  • Format on save:
local formatgrp = vim.api.nvim_create_augroup("C_format_42", {})

vim.api.nvim_create_autocmd("BufWritePre", {
  command = "CFormat42",
  group = formatgrp,
})
  • Format using keybindings:
vim.api.nvim_set_keymap('n', '<F2>', ':CFormat42<CR>', { noremap = true, silent = true })

About

Format code C/C++ according to the 42 norm V3 directly in Nvim. Written in Lua.

Resources

License

Stars

Watchers

Forks

Languages