mirror of
https://github.com/nvim-lua/kickstart.nvim.git
synced 2025-08-08 03:55:04 +02:00
fix: adjust indentation settings and clean up comment handling in C commands
This commit is contained in:
parent
3b2e059139
commit
deb4ac9890
1 changed files with 8 additions and 27 deletions
|
@ -2,10 +2,10 @@
|
||||||
local set = vim.opt_local
|
local set = vim.opt_local
|
||||||
|
|
||||||
-- Indentation settings
|
-- Indentation settings
|
||||||
set.expandtab = true -- Convert tabs to spaces
|
set.expandtab = false -- Convert tabs to spaces
|
||||||
set.shiftwidth = 4 -- Indent size for autoindent
|
set.shiftwidth = 4 -- Indent size for autoindent
|
||||||
set.tabstop = 4 -- How wide tabs appear
|
set.tabstop = 4 -- How wide tabs appear
|
||||||
set.softtabstop = 4 -- How many spaces Tab key inserts/removes
|
-- set.softtabstop = 4 -- How many spaces Tab key inserts/removes
|
||||||
|
|
||||||
-- Comment string for commentary plugins
|
-- Comment string for commentary plugins
|
||||||
set.commentstring = '/* %s */'
|
set.commentstring = '/* %s */'
|
||||||
|
@ -57,7 +57,7 @@ vim.api.nvim_create_user_command('CommentRestOfFile', function()
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
-- Define a custom command ':UncommentRestOfFile' that removes comments from rest of file
|
-- Define a custom command ':UncommentRestOfFile' that removes comments from rest of file
|
||||||
vim.api.nvim_create_user_command('UncommentRestOfFile', function ()
|
vim.api.nvim_create_user_command('UncommentRestOfFile', function()
|
||||||
local current_line = vim.api.nvim_win_get_cursor(0)[1]
|
local current_line = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
local last_line = vim.api.nvim_buf_line_count(0)
|
local last_line = vim.api.nvim_buf_line_count(0)
|
||||||
|
|
||||||
|
@ -66,36 +66,17 @@ vim.api.nvim_create_user_command('UncommentRestOfFile', function ()
|
||||||
|
|
||||||
-- Remove leading // if present
|
-- Remove leading // if present
|
||||||
for i = 1, #lines do
|
for i = 1, #lines do
|
||||||
lines[i] = lines[i]:gsub("^%s*//", "")
|
lines[i] = lines[i]:gsub('^%s*//', '')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set the modified lines back in the buffer
|
-- Set the modified lines back in the buffer
|
||||||
vim.api.nvim_buf_set_lines(0, current_line - 1, last_line, false, lines)
|
vim.api.nvim_buf_set_lines(0, current_line - 1, last_line, false, lines)
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
-- -- Debugging command to check indentation settings
|
|
||||||
-- vim.api.nvim_create_user_command('CheckIndent', function()
|
|
||||||
-- print("expandtab: " .. tostring(vim.bo.expandtab))
|
|
||||||
-- print("tabstop: " .. vim.bo.tabstop)
|
|
||||||
-- print("shiftwidth: " .. vim.bo.shiftwidth)
|
|
||||||
-- print("softtabstop: " .. vim.bo.softtabstop)
|
|
||||||
-- end, {})
|
|
||||||
|
|
||||||
-- Force settings to apply after all other scripts have loaded
|
|
||||||
vim.api.nvim_create_autocmd("BufEnter", {
|
|
||||||
pattern = "*.c,*.h",
|
|
||||||
callback = function()
|
|
||||||
vim.opt_local.expandtab = true
|
|
||||||
vim.opt_local.tabstop = 4
|
|
||||||
vim.opt_local.shiftwidth = 4
|
|
||||||
vim.opt_local.softtabstop = 4
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Add any C-specific key mappings you want here
|
-- Add any C-specific key mappings you want here
|
||||||
-- Example: Map F5 to compile and run the current file
|
-- Example: Map F5 to compile and run the current file
|
||||||
vim.keymap.set('n', '<F5>', function()
|
vim.keymap.set('n', '<F5>', function()
|
||||||
local filename = vim.fn.expand('%:r')
|
local filename = vim.fn.expand '%:r'
|
||||||
vim.cmd('write')
|
vim.cmd 'write'
|
||||||
vim.cmd('belowright split | terminal gcc -Wall -Wextra -Werror % -o ' .. filename .. ' && ./' .. filename)
|
vim.cmd('belowright split | terminal gcc -Wall -Wextra -Werror % -o ' .. filename .. ' && ./' .. filename)
|
||||||
end, { buffer = true, desc = 'Compile and run C file' })
|
end, { buffer = true, desc = 'Compile and run C file' })
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue