summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2025-06-19 01:07:18 +0400
committerSuleyman Farajli <suleyman@farajli.net>2025-06-19 01:07:18 +0400
commit09d70e1bc0bf1e5c54b3faf2918a3e14c4fc4cfc (patch)
tree2d8990fde64d5a81e65605447657c427ac4f19d4
parent226b3c808393b5e91e3eb6c6c591f5bc5e5d9775 (diff)
refactor: improve Neovim config for better readability and functionality
- Switch to Lua API options for setting vim options instead of vim.cmd - Add autocmd to trim trailing whitespace on save (except markdown) - Disable auto-comments via autocmd for all filetypes - Enhance and standardize key mappings with noremap and silent flags - Clean up plugin config indentation and comments
-rw-r--r--config/nvim/init.lua83
-rw-r--r--config/nvim/lua/plugins.lua24
2 files changed, 70 insertions, 37 deletions
diff --git a/config/nvim/init.lua b/config/nvim/init.lua
index df90607..ea8a3d2 100644
--- a/config/nvim/init.lua
+++ b/config/nvim/init.lua
@@ -1,15 +1,14 @@
require("plugins")
-vim.cmd("let mapleader = ' '")
-vim.cmd("set relativenumber")
-vim.cmd("set number")
-vim.cmd("colorscheme duskfox")
-vim.cmd("set nowrap")
-vim.cmd("set clipboard=unnamedplus") -- Use system clipboard
-vim.cmd("set background=dark")
-vim.cmd("set shm+=I") -- Disable intro message
-vim.cmd("autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o") -- Disable auto-comment
--- vim.cmd("set list") -- Show spaces tabs etc.
+vim.g.mapleader = ' '
+vim.opt.background = "dark"
+vim.opt.clipboard = "unnamedplus" -- Use system clipboard
+vim.opt.list = true -- Show spaces, tabs, etc.
+vim.opt.number = true
+vim.opt.relativenumber = true
+vim.opt.shortmess:append("I") -- Disable intro message
+vim.opt.wrap = false
+vim.cmd.colorscheme("duskfox")
vim.opt.fillchars = {
vert = "|",
@@ -22,16 +21,54 @@ vim.opt.fillchars = {
foldclose = ">",
}
-vim.keymap.set('n', '<leader><leader>', ':w!<CR>')
-vim.keymap.set('n', '<leader>q', ':wq!<CR>')
-vim.keymap.set('n', '<C-t>', ':tabnew<CR>')
-vim.keymap.set('n', 'J', ':tabn<CR>')
-vim.keymap.set('n', 'K', ':tabp<CR>')
-vim.keymap.set('n', '<C-n>', ':vsplit<CR>')
-vim.keymap.set('n', 'H', ':wincmd h<CR>')
-vim.keymap.set('n', 'L', ':wincmd l<CR>')
-vim.keymap.set('n', '<leader>e', ':Neotree toggle right<CR>')
-vim.keymap.set('n', '<leader>o', '<C-W>w')
-vim.keymap.set('i', '<C-h>', '<Left>')
-vim.keymap.set('i', '<C-l>', '<Right>')
-vim.keymap.set('i', '<C-space>', '<ESC>')
+-- Remove trailing whitespace on all lines before saving, excluding markdown files
+vim.api.nvim_create_autocmd("BufWritePre", {
+ pattern = "*",
+ callback = function()
+ if vim.bo.filetype == "markdown" then
+ return
+ end
+ vim.cmd([[%s/\s\+$//e]])
+ end,
+})
+
+-- Disable auto-comment
+vim.api.nvim_create_autocmd("FileType", {
+ pattern = "*",
+ callback = function()
+ vim.opt_local.formatoptions:remove({ "c", "r", "o" })
+ end,
+})
+
+
+-- NOTE: On some terminal emulators, the keybinds
+-- <C-j> and <C-k> don't work either in normal or insert mode.
+
+-- Tabs
+vim.keymap.set('n', '<C-t>', '<cmd>tabnew<CR>' , { noremap = true, silent = true })
+vim.keymap.set('n', 'H' , '<cmd>wincmd h<CR>', { noremap = true, silent = true })
+vim.keymap.set('n', 'J' , '<cmd>tabn<CR>' , { noremap = true, silent = true })
+vim.keymap.set('n', 'K' , '<cmd>tabp<CR>' , { noremap = true, silent = true })
+vim.keymap.set('n', 'L' , '<cmd>wincmd l<CR>', { noremap = true, silent = true })
+
+-- Windows
+vim.keymap.set('n', '<C-Down>' , '<cmd>split<CR>' , { noremap = true, silent = true })
+vim.keymap.set('n', '<C-Right>', '<cmd>vsplit<CR>', { noremap = true, silent = true })
+vim.keymap.set('n', '<C-h>' , '<C-w>h' , { noremap = true })
+vim.keymap.set('n', '<C-j>' , '<C-w>j' , { noremap = true })
+vim.keymap.set('n', '<C-k>' , '<C-w>k' , { noremap = true })
+vim.keymap.set('n', '<C-l>' , '<C-w>l' , { noremap = true })
+
+-- Imitate normal mode in insert mode
+vim.keymap.set('i', '<C-h>' , '<Left>' , { noremap = true })
+vim.keymap.set('i', '<C-l>' , '<Right>', { noremap = true })
+vim.keymap.set('i', '<C-j>' , '<Down>' , { noremap = true })
+vim.keymap.set('i', '<C-k>' , '<Up>' , { noremap = true })
+vim.keymap.set('i', '<C-space>', '<ESC>' , { noremap = true })
+
+-- Plugins
+vim.keymap.set('n', '<leader>e', '<cmd>Neotree toggle right<CR>', { noremap = true, silent = true })
+
+-- Other
+vim.keymap.set('n', '<leader><leader>', '<cmd>w!<CR>' , { noremap = true, silent = true })
+vim.keymap.set('n', '<leader>q' , '<cmd>wq!<CR>', { noremap = true, silent = true })
diff --git a/config/nvim/lua/plugins.lua b/config/nvim/lua/plugins.lua
index 911a4d7..7b00b1c 100644
--- a/config/nvim/lua/plugins.lua
+++ b/config/nvim/lua/plugins.lua
@@ -33,18 +33,18 @@ require("lazy").setup({
})
require("Comment").setup{
- padding = true, -- Add a space b/w comment and the line
- sticky = true, -- Whether the cursor should stay at its position
- ignore = nil, -- Lines to be ignored while (un)comment
+ padding = true, -- Add a space b/w comment and the line
+ sticky = true, -- Whether the cursor should stay at its position
+ ignore = nil, -- Lines to be ignored while (un)comment
-- LHS of toggle mappings in NORMAL mode
toggler = {
- line = 'cc', --Line-comment toggle keymap
- block = 'cb', -- Block-comment toggle keymap
+ line = 'cc', --Line-comment toggle keymap
+ block = 'cb', -- Block-comment toggle keymap
},
-- LHS of operator-pending mappings in NORMAL and VISUAL mode
opleader = {
- line = 'cc', --Line-comment keymap
- block = 'cb', --Block-comment keymap
+ line = 'cc', --Line-comment keymap
+ block = 'cb', --Block-comment keymap
},
}
@@ -72,25 +72,21 @@ require("neo-tree").setup({
}
}
},
- --Indent Markers
default_component_configs = {
indent = {
+ --Indent Markers
with_markers = true,
indent_marker = "│",
last_indent_marker = "└",
indent_size = 2,
- },
- },
- --Expanders
- default_component_configs = {
- indent = {
+ -- Expanders
with_expanders = false, --Not active
expander_collapsed = ">",
expander_expanded = "",
expander_highlight = "NeoTreeExpander",
+
},
},
-
})
require("nvim-autopairs").setup({