Skip to content

Commit deb4ac9

Browse files
committed
fix: adjust indentation settings and clean up comment handling in C commands
1 parent 3b2e059 commit deb4ac9

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

after/ftplugin/c.lua

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
local set = vim.opt_local
33

44
-- Indentation settings
5-
set.expandtab = true -- Convert tabs to spaces
6-
set.shiftwidth = 4 -- Indent size for autoindent
7-
set.tabstop = 4 -- How wide tabs appear
8-
set.softtabstop = 4 -- How many spaces Tab key inserts/removes
5+
set.expandtab = false -- Convert tabs to spaces
6+
set.shiftwidth = 4 -- Indent size for autoindent
7+
set.tabstop = 4 -- How wide tabs appear
8+
-- set.softtabstop = 4 -- How many spaces Tab key inserts/removes
99

1010
-- Comment string for commentary plugins
1111
set.commentstring = '/* %s */'
@@ -57,7 +57,7 @@ vim.api.nvim_create_user_command('CommentRestOfFile', function()
5757
end, {})
5858

5959
-- Define a custom command ':UncommentRestOfFile' that removes comments from rest of file
60-
vim.api.nvim_create_user_command('UncommentRestOfFile', function ()
60+
vim.api.nvim_create_user_command('UncommentRestOfFile', function()
6161
local current_line = vim.api.nvim_win_get_cursor(0)[1]
6262
local last_line = vim.api.nvim_buf_line_count(0)
6363

@@ -66,36 +66,17 @@ vim.api.nvim_create_user_command('UncommentRestOfFile', function ()
6666

6767
-- Remove leading // if present
6868
for i = 1, #lines do
69-
lines[i] = lines[i]:gsub("^%s*//", "")
69+
lines[i] = lines[i]:gsub('^%s*//', '')
7070
end
7171

7272
-- Set the modified lines back in the buffer
7373
vim.api.nvim_buf_set_lines(0, current_line - 1, last_line, false, lines)
7474
end, {})
7575

76-
-- -- Debugging command to check indentation settings
77-
-- vim.api.nvim_create_user_command('CheckIndent', function()
78-
-- print("expandtab: " .. tostring(vim.bo.expandtab))
79-
-- print("tabstop: " .. vim.bo.tabstop)
80-
-- print("shiftwidth: " .. vim.bo.shiftwidth)
81-
-- print("softtabstop: " .. vim.bo.softtabstop)
82-
-- end, {})
83-
84-
-- Force settings to apply after all other scripts have loaded
85-
vim.api.nvim_create_autocmd("BufEnter", {
86-
pattern = "*.c,*.h",
87-
callback = function()
88-
vim.opt_local.expandtab = true
89-
vim.opt_local.tabstop = 4
90-
vim.opt_local.shiftwidth = 4
91-
vim.opt_local.softtabstop = 4
92-
end
93-
})
94-
9576
-- Add any C-specific key mappings you want here
9677
-- Example: Map F5 to compile and run the current file
9778
vim.keymap.set('n', '<F5>', function()
98-
local filename = vim.fn.expand('%:r')
99-
vim.cmd('write')
79+
local filename = vim.fn.expand '%:r'
80+
vim.cmd 'write'
10081
vim.cmd('belowright split | terminal gcc -Wall -Wextra -Werror % -o ' .. filename .. ' && ./' .. filename)
10182
end, { buffer = true, desc = 'Compile and run C file' })

0 commit comments

Comments
 (0)