feat: add custom commands for commenting and uncommenting lines in C files
This commit is contained in:
parent
10ccea08ec
commit
7214203534
|
@ -2,4 +2,5 @@ local set = vim.opt_local
|
||||||
|
|
||||||
set.shiftwidth = 4
|
set.shiftwidth = 4
|
||||||
set.tabstop = 4
|
set.tabstop = 4
|
||||||
|
vim.g.sleuth_automatic = 0
|
||||||
set.commentstring = '/* %s */'
|
set.commentstring = '/* %s */'
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
-- local set = vim.opt_local
|
-- Import vim module
|
||||||
|
local set = vim.opt_local
|
||||||
|
|
||||||
|
set.shiftwidth = 4
|
||||||
|
set.tabstop = 4
|
||||||
|
set.commentstring = '/* %s */'
|
||||||
|
|
||||||
-- Define a custom command ':IntMain' that inserts int main() {} template
|
-- Define a custom command ':IntMain' that inserts int main() {} template
|
||||||
vim.api.nvim_create_user_command('IntMain', function()
|
vim.api.nvim_create_user_command('IntMain', function()
|
||||||
|
@ -24,3 +29,35 @@ vim.api.nvim_create_user_command('Libft', function()
|
||||||
'#include "libft.h"',
|
'#include "libft.h"',
|
||||||
})
|
})
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command('CommentRestOfFile', function()
|
||||||
|
local current_line = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
|
local last_line = vim.api.nvim_buf_line_count(0)
|
||||||
|
|
||||||
|
-- Get all lines from current to end of file
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(0, current_line - 1, last_line, false)
|
||||||
|
|
||||||
|
-- Prefix each line with //
|
||||||
|
for i = 1, #lines do
|
||||||
|
lines[i] = '//' .. lines[i]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set the modified lines back in the buffer
|
||||||
|
vim.api.nvim_buf_set_lines(0, current_line - 1, last_line, false, lines)
|
||||||
|
end, {})
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command('UncommentRestOfFile', function ()
|
||||||
|
local current_line = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
|
local last_line = vim.api.nvim_buf_line_count(0)
|
||||||
|
|
||||||
|
-- Get all lines from current to end of file
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(0, current_line - 1, last_line, false)
|
||||||
|
|
||||||
|
-- Remove leading // if present
|
||||||
|
for i = 1, #lines do
|
||||||
|
lines[i] = lines[i]:gsub("^%s*//", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set the modified lines back in the buffer
|
||||||
|
vim.api.nvim_buf_set_lines(0, current_line - 1, last_line, false, lines)
|
||||||
|
end, {})
|
||||||
|
|
38
init.lua
38
init.lua
|
@ -1,38 +1,4 @@
|
||||||
--[[
|
|
||||||
|
|
||||||
What is Kickstart?
|
|
||||||
|
|
||||||
Kickstart.nvim is *not* a distribution.
|
|
||||||
|
|
||||||
Kickstart.nvim is a starting point for your own configuration.
|
|
||||||
The goal is that you can read every line of code, top-to-bottom, understand
|
|
||||||
what your configuration is doing, and modify it to suit your needs.
|
|
||||||
|
|
||||||
Once you've done that, you can start exploring, configuring and tinkering to
|
|
||||||
make Neovim your own! That might mean leaving Kickstart just the way it is for a while
|
|
||||||
or immediately breaking it into modular pieces. It's up to you!
|
|
||||||
|
|
||||||
If you don't know anything about Lua, I recommend taking some time to read through
|
|
||||||
a guide. One possible example which will only take 10-15 minutes:
|
|
||||||
- https://learnxinyminutes.com/docs/lua/
|
|
||||||
|
|
||||||
After understanding a bit more about Lua, you can use `:help lua-guide` as a
|
|
||||||
reference for how Neovim integrates Lua.
|
|
||||||
- :help lua-guide
|
|
||||||
- (or HTML version): https://neovim.io/doc/user/lua-guide.html
|
|
||||||
|
|
||||||
Kickstart Guide:
|
|
||||||
|
|
||||||
If you experience any errors while trying to install kickstart, run `:checkhealth` for more info.
|
|
||||||
|
|
||||||
I hope you enjoy your Neovim journey,
|
|
||||||
- TJ
|
|
||||||
|
|
||||||
P.S. You can delete this when you're done too. It's your config now! :)
|
|
||||||
--]]
|
|
||||||
|
|
||||||
-- Set <space> as the leader key
|
-- Set <space> as the leader key
|
||||||
-- See `:help mapleader`
|
|
||||||
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
|
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
|
||||||
vim.g.mapleader = ' '
|
vim.g.mapleader = ' '
|
||||||
vim.g.maplocalleader = ' '
|
vim.g.maplocalleader = ' '
|
||||||
|
@ -793,7 +759,7 @@ require('lazy').setup({
|
||||||
filter = 'pro', -- classic | octagon | pro | machine | ristretto | spectrum
|
filter = 'pro', -- classic | octagon | pro | machine | ristretto | spectrum
|
||||||
-- Enable this will disable filter option
|
-- Enable this will disable filter option
|
||||||
day_night = {
|
day_night = {
|
||||||
enable = false, -- turn off by default
|
enable = true, -- turn off by default
|
||||||
day_filter = 'pro', -- classic | octagon | pro | machine | ristretto | spectrum
|
day_filter = 'pro', -- classic | octagon | pro | machine | ristretto | spectrum
|
||||||
night_filter = 'spectrum', -- classic | octagon | pro | machine | ristretto | spectrum
|
night_filter = 'spectrum', -- classic | octagon | pro | machine | ristretto | spectrum
|
||||||
},
|
},
|
||||||
|
@ -806,7 +772,7 @@ require('lazy').setup({
|
||||||
'renamer',
|
'renamer',
|
||||||
'notify',
|
'notify',
|
||||||
'nvim-tree',
|
'nvim-tree',
|
||||||
'neo-tree',
|
-- 'neo-tree',
|
||||||
'bufferline', -- better used if background of `neo-tree` or `nvim-tree` is cleared
|
'bufferline', -- better used if background of `neo-tree` or `nvim-tree` is cleared
|
||||||
}, -- "float_win", "toggleterm", "telescope", "which-key", "renamer", "neo-tree", "nvim-tree", "bufferline"
|
}, -- "float_win", "toggleterm", "telescope", "which-key", "renamer", "neo-tree", "nvim-tree", "bufferline"
|
||||||
plugins = {
|
plugins = {
|
||||||
|
|
Loading…
Reference in New Issue