added basic nvim config - still some keybinding missing

This commit is contained in:
Christopher Beckmann
2023-10-14 02:11:20 +02:00
parent 3f1aae39f3
commit 22e741c30c
14 changed files with 639 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
vim.g.mapleader = ' '
require("kamu.options")
--require("kamu.commands")
require("kamu.lazy")
require("kamu.keymaps")

View File

@@ -0,0 +1,99 @@
-- n, v, i, t = mode names
local M = {}
M.general = {
i = {
-- go to beginning and end
["<C-b>"] = { "<ESC>^i", "Beginning of line" },
["<C-e>"] = { "<End>", "End of line" },
-- navigate within insert mode
["<C-h>"] = { "<Left>", "Move left" },
["<C-l>"] = { "<Right>", "Move right" },
["<C-j>"] = { "<Down>", "Move down" },
["<C-k>"] = { "<Up>", "Move up" },
},
n = {
["<Esc>"] = { ":noh <CR>", "Clear highlights" },
-- switch between windows
["<C-h>"] = { "<C-w>h", "Window left" },
["<C-l>"] = { "<C-w>l", "Window right" },
["<C-j>"] = { "<C-w>j", "Window down" },
["<C-k>"] = { "<C-w>k", "Window up" },
-- save
["<C-s>"] = { "<cmd> w <CR>", "Save file" },
-- Copy all
["<C-c>"] = { "<cmd> %y+ <CR>", "Copy whole file" },
-- line numbers
["<leader>n"] = { "<cmd> set nu! <CR>", "Toggle line number" },
["<leader>rn"] = { "<cmd> set rnu! <CR>", "Toggle relative number" },
-- Allow moving the cursor through wrapped lines with j, k, <Up> and <Down>
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- empty mode is same as using <cmd> :map
-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour
["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', "Move down", opts = { expr = true } },
["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', "Move up", opts = { expr = true } },
["<Up>"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', "Move up", opts = { expr = true } },
["<Down>"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', "Move down", opts = { expr = true } },
-- new buffer
["<leader>b"] = { "<cmd> enew <CR>", "New buffer" },
["<leader>ch"] = { "<cmd> NvCheatsheet <CR>", "Mapping cheatsheet" },
["<leader>fm"] = {
function()
vim.lsp.buf.format { async = true }
end,
"LSP formatting",
},
},
t = {
["<C-x>"] = { vim.api.nvim_replace_termcodes("<C-\\><C-N>", true, true, true), "Escape terminal mode" },
},
v = {
["<Up>"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', "Move up", opts = { expr = true } },
["<Down>"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', "Move down", opts = { expr = true } },
["<"] = { "<gv", "Indent line" },
[">"] = { ">gv", "Indent line" },
},
x = {
["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', "Move down", opts = { expr = true } },
["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', "Move up", opts = { expr = true } },
-- Don't copy the replaced text after pasting in visual mode
-- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste
["p"] = { 'p:let @+=@0<CR>:let @"=@0<CR>', "Dont copy replaced text", opts = { silent = true } },
},
}
M.comment = {
plugin = true,
-- toggle comment in both modes
n = {
["<leader>/"] = {
function()
require("Comment.api").toggle.linewise.current()
end,
"Toggle comment",
},
},
v = {
["<leader>/"] = {
"<ESC><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<CR>",
"Toggle comment",
},
},
}

View File

@@ -0,0 +1,16 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local opts = {}
require("lazy").setup("kamu.plugins", opts)

View File

@@ -0,0 +1,39 @@
local options = {
autoindent = true,
smartindent = true,
tabstop = 2,
shiftwidth = 2,
expandtab = true,
number = true,
relativenumber = true,
numberwidth = 4,
swapfile = false,
backup = false,
undodir = os.getenv("HOME") .. "/.vim/undodir",
undofile = true,
hlsearch = false,
incsearch = true,
showtabline = 0,
termguicolors = true,
signcolumn = "yes",
wrap = false,
fileencoding = "utf-8",
scrolloff = 8,
mouse = "a",
updatetime = 50,
-- guicursor = "a:block"
}
for option, value in pairs(options) do
vim.opt[option] = value
end

View File

@@ -0,0 +1,100 @@
return {
"catppuccin/nvim",
name = "catppuccin",
priority = 1000,
config = function()
require("catppuccin").setup({
flavour = "mocha", -- latte, frappe, macchiato, mocha
background = { -- :h background
light = "latte",
dark = "mocha",
},
transparent_background = true, -- disables setting the background color.
show_end_of_buffer = false, -- shows the '~' characters after the end of buffers
term_colors = false, -- sets terminal colors (e.g. `g:terminal_color_0`)
dim_inactive = {
enabled = false, -- dims the background color of inactive window
shade = "dark",
percentage = 0.15, -- percentage of the shade to apply to the inactive window
},
no_italic = false, -- Force no italic
no_bold = false, -- Force no bold
no_underline = false, -- Force no underline
styles = { -- Handles the styles of general hi groups (see `:h highlight-args`):
comments = { "italic" }, -- Change the style of comments
conditionals = { "italic" },
loops = {"italic"},
functions = {"italic"},
keywords = {"bold"},
strings = {},
variables = {},
numbers = {"italic"},
booleans = {"italic"},
properties = {},
types = {},
operators = {},
},
color_overrides = {
all = {
text = "#ffffff",
},
mocha = {
base = "#000000",
mantle = "#242424",
crust = "#474747",
blue = "#0f63bd",
surface1 = "#011f2a",
--blue = "#0ca8fb", --accent color
-- rosewater = "#f5e0dc",
-- flamingo = "#f2cdcd",
-- pink = "#f5c2e7",
-- mauve = "#cba6f7",
-- red = "#f38ba8",
-- maroon = "#eba0ac",
-- peach = "#fab387",
-- yellow = "#f9e2af",
-- green = "#a6e3a1",
-- teal = "#94e2d5",
-- sky = "#89dceb",
-- sapphire = "#74c7ec",
-- blue = "#89b4fa",
-- lavender = "#b4befe",
-- text = "#cdd6f4",
-- subtext1 = "#bac2de",
-- subtext0 = "#a6adc8",
-- overlay2 = "#9399b2",
-- overlay1 = "#7f849c",
-- overlay0 = "#6c7086",
-- surface2 = "#585b70",
-- surface1 = "#45475a",
-- surface0 = "#313244",
-- base = "#1e1e2e",
-- mantle = "#181825",
-- crust = "#11111b",
}
},
custom_highlights = function(colors)
return {
Comment = { fg = "#89AEB1" }
}
end,
integrations = {
cmp = false,
gitsigns = false,
nvimtree = false,
telescope = {
enabled = true,
},
treesitter = true,
notify = false,
mini = false,
-- For more plugins integrations please scroll down (https://github.com/catppuccin/nvim#integrations)
},
})
vim.cmd.colorscheme "catppuccin"
vim.api.nvim_set_hl(0, 'LineNrAbove', { fg='#CACACA', })
vim.api.nvim_set_hl(0, 'LineNrBelow', { fg='#CACACA', })
vim.api.nvim_set_hl(0, 'LineNr', { fg = "#0ca8fb", bold=true } )
end,
}

View File

@@ -0,0 +1,8 @@
return {
'brenoprata10/nvim-highlight-colors',
config = function()
require('nvim-highlight-colors').setup {
render = 'background'
}
end,
}

View File

@@ -0,0 +1,61 @@
return {
'VonHeikemen/lsp-zero.nvim',
branch = 'v3.x',
dependencies = {
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
'neovim/nvim-lspconfig',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/nvim-cmp',
'L3MON4D3/LuaSnip'
},
config = function()
local lsp_zero = require('lsp-zero')
lsp_zero.on_attach(function(client, bufnr)
local opts = {buffer = bufnr, remap = false}
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
end)
require('mason').setup({})
require('mason-lspconfig').setup({
ensure_installed = {'rust_analyzer'},
handlers = {
lsp_zero.default_setup,
lua_ls = function()
local lua_opts = lsp_zero.nvim_lua_ls()
require('lspconfig').lua_ls.setup(lua_opts)
end,
}
})
local cmp = require('cmp')
local cmp_select = {behavior = cmp.SelectBehavior.Select}
cmp.setup({
sources = {
{name = 'path'},
{name = 'nvim_lsp'},
{name = 'nvim_lua'},
},
formatting = lsp_zero.cmp_format(),
mapping = cmp.mapping.preset.insert({
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
['<C-Space>'] = cmp.mapping.complete(),
}),
})
end,
}

View File

@@ -0,0 +1,167 @@
local palette = require("catppuccin.palettes.init").get_palette()
local mode_map = {
['n'] = 'NORMAL',
['no'] = 'O-PENDING',
['nov'] = 'O-PENDING',
['noV'] = 'O-PENDING',
['no\22'] = 'O-PENDING',
['niI'] = 'NORMAL',
['niR'] = 'NORMAL',
['niV'] = 'NORMAL',
['nt'] = 'NORMAL',
['ntT'] = 'NORMAL',
['v'] = 'VISUAL',
['vs'] = 'VISUAL',
['V'] = 'V-LINE',
['Vs'] = 'V-LINE',
['\22'] = 'V-BLOCK',
['\22s'] = 'V-BLOCK',
['s'] = 'SELECT',
['S'] = 'S-LINE',
['\19'] = 'S-BLOCK',
['i'] = 'INSERT',
['ic'] = 'INSERT',
['ix'] = 'INSERT',
['R'] = 'REPLACE',
['Rc'] = 'REPLACE',
['Rx'] = 'REPLACE',
['Rv'] = 'V-REPLACE',
['Rvc'] = 'V-REPLACE',
['Rvx'] = 'V-REPLACE',
['c'] = 'COMMAND',
['cv'] = 'EX',
['ce'] = 'EX',
['r'] = 'REPLACE',
['rm'] = 'MORE',
['r?'] = 'CONFIRM',
['!'] = 'SHELL',
['t'] = 'TERMINAL',
}
local mode2themeMap = {
['NORMAL'] = 'normal',
['VISUAL'] = 'visual',
['V-LINE'] = 'visual',
['V-BLOCK'] = 'visual',
['INSERT'] = 'insert',
['REPLACE'] = 'replace',
['COMMAND'] = 'command',
['TERMINAL'] = 'terminal',
}
function getModeColor(section, type)
local theme = require("catppuccin.utils.lualine")("mocha")
local mode = vim.api.nvim_get_mode().mode
if mode == nil then
return theme['normal'][section][type]
end
local modeColors = theme[mode2themeMap[mode_map[mode]]]
if modeColors == nil then modeColors = theme['inactive'] end
return modeColors[section][type]
end
return {
'nvim-lualine/lualine.nvim',
dependencies = {'kyazdani42/nvim-web-devicons', opt = true },
config = function()
require('lualine').setup {
options = {
theme = 'catppuccin',
--fmt = string.lower,
icons_enabled = true,
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = false,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {
{
'mode',
color = function()
if vim.fn.mode() == "n" then return { fg = palette.text, gui = "bold" } end
return { fg = "#000000", gui = "bold" }
end,
-- fmt = function(str) return str:sub(1,1) end,
}},
lualine_b = {
{
'branch',
color = { fg = "#FFF"},
icon = {'', color = function() return { fg = getModeColor('a','bg') } end },
},
{
'diff',
diff_color = {
-- custom color for each section of the component in format
-- {fg = '#rrggbb', bg= '#rrggbb', gui='style'}
-- or highlight group
added = nil, -- {fg = '#rrggbb', bg= '#rrggbb', gui='style'}, -- changes diff's added color
modified = { fg = "#FFFFFF" }, -- changes diff's modified color
removed = nil, -- changes diff's removed color
},
},
-- 'diagnostics'
},
lualine_c = {{
'filename',
on_click = function(nc, mb, mods)
local tb = require("telescope.builtin")
if mb == "l" then
--vim.print(mods)
local mod = mods:gsub("%s+", "")
if mod == "c" then tb.find_files(); return end
if mod == "a" then tb.buffers(); return end
end
--require("telescope.builtin").find_files()
end,
}},
lualine_x = {
-- {
-- function()
-- return getModeColor('a','bg')
-- end
-- },
'encoding', 'fileformat', 'filetype'},
lualine_y = {
{
'progress',
color = { fg = "#FFFFFF"},
}
},
lualine_z = {{
'location',
color = function(section)
if vim.fn.mode() == "n" then return { fg = palette.text } end
return { fg = "#000000", }
end,
}}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
}
end,
}

View File

@@ -0,0 +1,13 @@
return {
"nvim-telescope/telescope.nvim",
tag = '0.1.3',
dependencies = {'nvim-lua/plenary.nvim'},
config = function()
require("telescope").setup()
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
end,
}

View File

@@ -0,0 +1,51 @@
return {}
--return {
-- "aserowy/tmux.nvim",
-- config = function()
-- return require("tmux").setup({
-- copy_sync = {
-- -- enables copy sync. by default, all registers are synchronized.
-- -- to control which registers are synced, see the `sync_*` options.
-- enable = true,
-- -- ignore specific tmux buffers e.g. buffer0 = true to ignore the
-- -- first buffer or named_buffer_name = true to ignore a named tmux
-- -- buffer with name named_buffer_name :)
-- ignore_buffers = { empty = false },
-- -- TMUX >= 3.2: all yanks (and deletes) will get redirected to system
-- -- clipboard by tmux
-- redirect_to_clipboard = false,
-- -- offset controls where register sync starts
-- -- e.g. offset 2 lets registers 0 and 1 untouched
-- register_offset = 0,
-- -- overwrites vim.g.clipboard to redirect * and + to the system
-- -- clipboard using tmux. If you sync your system clipboard without tmux,
-- -- disable this option!
-- sync_clipboard = true,
-- -- synchronizes registers *, +, unnamed, and 0 till 9 with tmux buffers.
-- sync_registers = true,
-- -- syncs deletes with tmux clipboard as well, it is adviced to
-- -- do so. Nvim does not allow syncing registers 0 and 1 without
-- -- overwriting the unnamed register. Thus, ddp would not be possible.
-- sync_deletes = true,
-- -- syncs the unnamed register with the first buffer entry from tmux.
-- sync_unnamed = true,
-- },
-- navigation = {
-- -- cycles to opposite pane while navigating into the border
-- cycle_navigation = true,
-- -- enables default keybindings (C-hjkl) for normal mode
-- enable_default_keybindings = true,
-- -- prevents unzoom tmux when navigating beyond vim border
-- persist_zoom = false,
-- },
-- resize = {
-- -- enables default keybindings (A-hjkl) for normal mode
-- enable_default_keybindings = true,
-- -- sets resize steps for x axis
-- resize_step_x = 1,
-- -- sets resize steps for y axis
-- resize_step_y = 1,
-- }
-- })
-- end
--}

View File

@@ -0,0 +1,26 @@
return {
'nvim-tree/nvim-tree.lua',
config = function()
local function my_on_attach(bufnr)
local api = require "nvim-tree.api"
local function opts(desc)
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- default mappings
api.config.mappings.default_on_attach(bufnr)
-- custom mappings
vim.keymap.set('n', '<C-t>', api.tree.change_root_to_parent, opts('Up'))
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
end
-- pass to setup along with your other options
require("nvim-tree").setup {
---
on_attach = my_on_attach,
---
}
end
}

View File

@@ -0,0 +1,33 @@
return {
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = {
"c",
"cpp",
"bash",
"lua",
"vim",
"vimdoc",
"json",
"python",
"yaml",
"markdown",
"make",
"query",
"javascript",
"dockerfile",
"html",
"latex",
"css",
"scss",
},
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end,
}