Initial Configurations

This commit is contained in:
dubnde 2023-08-20 11:00:16 +01:00
parent 01a1ebed38
commit 5c216504bb
15 changed files with 478 additions and 687 deletions

View file

@ -1,5 +0,0 @@
-- You can add your own plugins here or in other files in this directory!
-- I promise not to create any merge conflicts in this directory :)
--
-- See the kickstart.nvim README for more information
return {}

43
lua/defaults/autocmds.lua Normal file
View file

@ -0,0 +1,43 @@
local group = vim.api.nvim_create_augroup('user_cmds', { clear = true })
vim.api.nvim_create_user_command('ReloadConfig', 'source $MYVIMRC | PackerCompile', {})
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'qf', 'help', 'man', 'lspinfo', 'spectre_panel' },
group = group,
command = 'nnoremap <buffer> q <cmd>quit<cr>',
})
vim.api.nvim_create_autocmd({ 'FileType' }, {
pattern = { 'gitcommit' },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
})
vim.cmd "autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif"
vim.api.nvim_create_autocmd({ 'VimResized' }, {
callback = function()
vim.cmd 'tabdo wincmd ='
end,
})
vim.api.nvim_create_autocmd({ 'CmdWinEnter' }, {
callback = function()
vim.cmd 'quit'
end,
})
vim.api.nvim_create_autocmd({ 'TextYankPost' }, {
callback = function()
vim.highlight.on_yank { higroup = 'Visual', timeout = 200 }
end,
})
vim.api.nvim_create_autocmd({ 'VimEnter' }, {
callback = function()
vim.cmd 'hi link illuminatedWord LspReferenceText'
end,
})

92
lua/defaults/keymaps.lua Normal file
View file

@ -0,0 +1,92 @@
-- Shorten function name
local keymap = vim.keymap.set
-- Silent keymap option
local opts = { noremap = true, silent = true }
--Remap space as leader key
keymap('', '<Space>', '<Nop>', opts)
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Modes
-- normal_mode = "n",
-- insert_mode = "i",
-- visual_mode = "v",
-- visual_block_mode = "x",
-- term_mode = "t",
-- command_mode = "c",
-- Normal --
-- Better window navigation
keymap('n', '<C-h>', '<C-w>h', opts)
keymap('n', '<C-j>', '<C-w>j', opts)
keymap('n', '<C-k>', '<C-w>k', opts)
keymap('n', '<C-l>', '<C-w>l', opts)
-- Resize with arrows
keymap('n', '<C-Up>', ':resize -2<CR>', opts)
keymap('n', '<C-Down>', ':resize +2<CR>', opts)
keymap('n', '<C-Left>', ':vertical resize -2<CR>', opts)
keymap('n', '<C-Right>', ':vertical resize +2<CR>', opts)
-- Navigate buffers
keymap('n', '<S-l>', ':bnext<CR>', opts)
keymap('n', '<S-h>', ':bprevious<CR>', opts)
-- Clear highlights
keymap('n', '<leader>nh', '<cmd>nohlsearch<CR>', opts)
-- delete single character without copying into register
keymap('n', 'x', '"_x', opts)
-- Close buffers
keymap('n', '<leader>bd', '<cmd>:bd<CR>', opts)
keymap('n', '<leader>bD', '<cmd>Bdelete!<CR>', opts)
-- Write file
keymap('n', '<leader>fs', '<cmd>:write<CR>', opts)
keymap('n', '<leader>fw', '<cmd>:write<CR>', opts)
keymap('n', '<leader>fS', '<cmd>:wa<CR>', opts)
keymap('n', '<leader>fW', '<cmd>:wa<CR>', opts)
-- Safe quit
keymap('n', '<Leader>qq', ':quitall<CR>', opts)
-- Force quit
keymap('n', '<Leader>Q', ':quitall!<CR>', opts)
-- Better paste
keymap('v', 'p', '"_dP', opts)
-- Insert --
-- Press jk fast to enter
keymap('i', 'jk', '<ESC>', opts)
keymap('v', 'jk', '<ESC>', opts)
-- Visual --
-- Stay in indent mode
keymap('v', '<', '<gv', opts)
keymap('v', '>', '>gv', opts)
-- Search will center on the line it's found in
keymap('n', 'n', 'nzzzv', opts)
keymap('n', 'N', 'Nzzzv', opts)
keymap('n', '#', '#zz', opts)
keymap('n', '*', '*zz', opts)
-- increment/decrement numbers
keymap('n', '<leader>+', '<C-a>', opts) -- increment
keymap('n', '<leader>-', '<C-x>', opts) -- decrement
-- window management
keymap('n', '<leader>wv', '<C-w>v', opts) -- split window vertically
keymap('n', '<leader>wh', '<C-w>s', opts) -- split window horizontally
keymap('n', '<leader>w-', '<C-w>s', opts) -- split window horizontally
keymap('n', '<leader>wd', ':close<CR>', opts) -- close current split window
keymap('n', '<leader>to', ':tabnew<CR>', opts) -- open new tab
keymap('n', '<leader>tx', ':tabclose<CR>', opts) -- close current tab
keymap('n', '<leader>tn', ':tabn<CR>', opts) -- go to next tab
keymap('n', '<leader>tp', ':tabp<CR>', opts) -- go to previous tab

87
lua/defaults/settings.lua Normal file
View file

@ -0,0 +1,87 @@
-- vim.opt.clipboard = "unnamedplus" -- allows neovim to access the system clipboard
vim.opt.clipboard:append 'unnamedplus' -- use system clipboard as default register
vim.opt.cmdheight = 1 -- more space in the neovim command line for displaying messages
vim.opt.completeopt = 'menu,menuone,noselect' -- cmp needs this
vim.opt.conceallevel = 0 -- so that `` is visible in markdown files
vim.opt.fileencoding = 'utf-8' -- the encoding written to a file
vim.opt.hlsearch = false -- highlight all matches on previous search pattern
vim.opt.ignorecase = true -- ignore case in search patterns
vim.opt.mouse = 'a' -- allow the mouse to be used in neovim
vim.opt.pumheight = 10 -- pop up menu height
vim.opt.showmode = false -- we don't need to see things like -- INSERT -- anymore
vim.opt.showtabline = 0 -- always show tabs
vim.opt.smartcase = true -- smart case
vim.opt.smartindent = true -- make indenting smarter again
vim.opt.splitbelow = true -- force all horizontal splits to go below current window
vim.opt.splitright = true -- force all vertical splits to go to the right of current window
vim.opt.swapfile = false -- creates a swapfile
vim.opt.termguicolors = true -- set term gui colors (most terminals support this)
vim.opt.background = 'dark' --
vim.opt.timeoutlen = 1000 -- time to wait for a mapped sequence to complete (in milliseconds)
vim.opt.undofile = true -- enable persistent undo
vim.opt.updatetime = 300 -- faster completion (4000ms default)
vim.opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited
vim.opt.expandtab = true -- convert tabs to spaces
vim.opt.shiftwidth = 2 -- the number of spaces inserted for each indentation
vim.opt.shiftround = true --
vim.opt.tabstop = 2 -- insert 2 spaces for a tab
vim.opt.cursorline = true -- highlight the current line
vim.opt.number = true -- set numbered lines
vim.opt.relativenumber = true -- Relative numbers numbers
vim.opt.laststatus = 3 -- only the last window will always have a status line
vim.opt.showcmd = false -- hide (partial) command in the last line of the screen (for performance)
vim.opt.ruler = false -- hide the line and column number of the cursor position
vim.opt.numberwidth = 4 -- minimal number of columns to use for the line number {default 4}
vim.opt.signcolumn = 'yes' -- always show the sign column, otherwise it would shift the text each time
vim.opt.wrap = false -- display lines as one long line
vim.opt.scrolloff = 8 -- minimal number of screen lines to keep above and below the cursor
vim.opt.sidescrolloff = 8 -- minimal number of screen columns to keep to the left and right of the cursor if wrap is `false`
vim.opt.guifont = 'monospace:h17' -- the font used in graphical neovim applications
vim.opt.fillchars.eob = ' ' -- show empty lines at the end of a buffer as ` ` {default `~`}
vim.opt.shortmess:append 'c' -- hide all the completion messages, e.g. "-- XXX completion (YYY)", "match 1 of 2", "The only match", "Pattern not found"
vim.opt.whichwrap:append '<,>,[,],h,l' -- keys allowed to move to the previous/next line when the beginning/end of line is reached
vim.opt.iskeyword:append '-' -- treats words with `-` as single words
vim.opt.formatoptions:remove { 'c', 'r', 'o' } -- This is a sequence of letters which describes how automatic formatting is to be done
vim.opt.linebreak = true
vim.opt.backspace = 'indent,eol,start' -- allow backspace on indent, end of line or insert mode start position
vim.opt.backup = false -- creates a backup file
local disabled_built_ins = {
'2html_plugin',
'getscript',
'getscriptPlugin',
'gzip',
'logipat',
'loaded_netrw',
'loaded_netrwPlugin',
'loaded_remote_plugins',
'loaded_tutor_mode_plugin',
'matchit',
'matchparen',
'netrw',
'netrwFileHandlers',
'netrwPlugin',
'netrwSettings',
'rrhelper',
'spellfile_plugin',
'tar',
'tarPlugin',
'vimball',
'vimballPlugin',
'zip',
'zipPlugin',
}
for _, plugin in pairs(disabled_built_ins) do
vim.g['loaded_' .. plugin] = 1
end
-- disable netrw at the very start of your init.lua (strongly advised)
vim.g.loaded_perl_provider = 0
vim.g.loaded_ruby_provider = 0
if vim.fn.executable 'rg' then
-- if ripgrep installed, use that as a grepper
vim.opt.grepprg = 'rg --vimgrep --no-heading --smart-case'
vim.opt.grepformat = '%f:%l:%c:%m,%f:%l:%m'
end

View file

@ -1,74 +0,0 @@
-- autoformat.lua
--
-- Use your language server to automatically format your code on save.
-- Adds additional commands as well to manage the behavior
return {
'neovim/nvim-lspconfig',
config = function()
-- Switch for controlling whether you want autoformatting.
-- Use :KickstartFormatToggle to toggle autoformatting on or off
local format_is_enabled = true
vim.api.nvim_create_user_command('KickstartFormatToggle', function()
format_is_enabled = not format_is_enabled
print('Setting autoformatting to: ' .. tostring(format_is_enabled))
end, {})
-- Create an augroup that is used for managing our formatting autocmds.
-- We need one augroup per client to make sure that multiple clients
-- can attach to the same buffer without interfering with each other.
local _augroups = {}
local get_augroup = function(client)
if not _augroups[client.id] then
local group_name = 'kickstart-lsp-format-' .. client.name
local id = vim.api.nvim_create_augroup(group_name, { clear = true })
_augroups[client.id] = id
end
return _augroups[client.id]
end
-- Whenever an LSP attaches to a buffer, we will run this function.
--
-- See `:help LspAttach` for more information about this autocmd event.
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }),
-- This is where we attach the autoformatting for reasonable clients
callback = function(args)
local client_id = args.data.client_id
local client = vim.lsp.get_client_by_id(client_id)
local bufnr = args.buf
-- Only attach to clients that support document formatting
if not client.server_capabilities.documentFormattingProvider then
return
end
-- Tsserver usually works poorly. Sorry you work with bad languages
-- You can remove this line if you know what you're doing :)
if client.name == 'tsserver' then
return
end
-- Create an autocmd that will run *before* we save the buffer.
-- Run the formatting command for the LSP that has just attached.
vim.api.nvim_create_autocmd('BufWritePre', {
group = get_augroup(client),
buffer = bufnr,
callback = function()
if not format_is_enabled then
return
end
vim.lsp.buf.format {
async = false,
filter = function(c)
return c.id == client.id
end,
}
end,
})
end,
})
end,
}

View file

@ -1,87 +0,0 @@
-- debug.lua
--
-- Shows how to use the DAP plugin to debug your code.
--
-- Primarily focused on configuring the debugger for Go, but can
-- be extended to other languages as well. That's why it's called
-- kickstart.nvim and not kitchen-sink.nvim ;)
return {
-- NOTE: Yes, you can install new plugins here!
'mfussenegger/nvim-dap',
-- NOTE: And you can specify dependencies as well
dependencies = {
-- Creates a beautiful debugger UI
'rcarriga/nvim-dap-ui',
-- Installs the debug adapters for you
'williamboman/mason.nvim',
'jay-babu/mason-nvim-dap.nvim',
-- Add your own debuggers here
'leoluz/nvim-dap-go',
},
config = function()
local dap = require 'dap'
local dapui = require 'dapui'
require('mason-nvim-dap').setup {
-- Makes a best effort to setup the various debuggers with
-- reasonable debug configurations
automatic_setup = true,
-- You can provide additional configuration to the handlers,
-- see mason-nvim-dap README for more information
handlers = {},
-- You'll need to check that you have the required things installed
-- online, please don't ask me how to install them :)
ensure_installed = {
-- Update this to ensure that you have the debuggers for the langs you want
'delve',
},
}
-- Basic debugging keymaps, feel free to change to your liking!
vim.keymap.set('n', '<F5>', dap.continue, { desc = 'Debug: Start/Continue' })
vim.keymap.set('n', '<F1>', dap.step_into, { desc = 'Debug: Step Into' })
vim.keymap.set('n', '<F2>', dap.step_over, { desc = 'Debug: Step Over' })
vim.keymap.set('n', '<F3>', dap.step_out, { desc = 'Debug: Step Out' })
vim.keymap.set('n', '<leader>b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' })
vim.keymap.set('n', '<leader>B', function()
dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ')
end, { desc = 'Debug: Set Breakpoint' })
-- Dap UI setup
-- For more information, see |:help nvim-dap-ui|
dapui.setup {
-- Set icons to characters that are more likely to work in every terminal.
-- Feel free to remove or use ones that you like more! :)
-- Don't feel like these are good choices.
icons = { expanded = '', collapsed = '', current_frame = '*' },
controls = {
icons = {
pause = '',
play = '',
step_into = '',
step_over = '',
step_out = '',
step_back = 'b',
run_last = '▶▶',
terminate = '',
disconnect = '',
},
},
}
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
vim.keymap.set('n', '<F7>', dapui.toggle, { desc = 'Debug: See last session result.' })
dap.listeners.after.event_initialized['dapui_config'] = dapui.open
dap.listeners.before.event_terminated['dapui_config'] = dapui.close
dap.listeners.before.event_exited['dapui_config'] = dapui.close
-- Install golang specific config
require('dap-go').setup()
end,
}

View file

@ -0,0 +1,37 @@
return {
"catppuccin/nvim",
lazy = true,
name = "catppuccin",
opts = {
integrations = {
alpha = true,
cmp = true,
flash = true,
gitsigns = true,
illuminate = true,
indent_blankline = { enabled = true },
lsp_trouble = true,
mason = true,
mini = true,
native_lsp = {
enabled = true,
underlines = {
errors = { "undercurl" },
hints = { "undercurl" },
warnings = { "undercurl" },
information = { "undercurl" },
},
},
navic = { enabled = true, custom_bg = "lualine" },
neotest = true,
noice = true,
notify = true,
neotree = true,
semantic_tokens = true,
telescope = true,
treesitter = true,
which_key = true,
},
},
}

43
lua/plugins/lualine.lua Normal file
View file

@ -0,0 +1,43 @@
local options = {
icons_enabled = false,
component_separators = '|',
section_separators = '',
disabled_filetypes = {},
always_divide_middle = true,
globalstatus = false,
}
local sections = {
lualine_a = { 'mode' },
lualine_b = { 'branch', 'diff', 'diagnostics' },
lualine_c = { '%f', '[%-m]', 'filesize' },
lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' },
lualine_z = { 'location' },
}
local inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { 'filename' },
lualine_x = { 'location' },
lualine_y = { 'test' },
lualine_z = {},
}
local tabline = {}
local extensions = {}
return {
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = function(_, opts)
table.insert(opts, { ['options'] = options })
table.insert(opts, { ['sections'] = sections })
table.insert(opts, { ['tabline'] = tabline })
table.insert(opts, { ['extensions'] = extensions })
end,
},
}

10
lua/plugins/neogit.lua Normal file
View file

@ -0,0 +1,10 @@
return {
"TimUntersberger/neogit",
dependencies = "nvim-lua/plenary.nvim",
keys = {
{ "<leader>gs", "<cmd>Neogit<CR>", desc = "Open neogit" },
},
opts = {
use_magit_keybindings = true,
},
}

24
lua/plugins/sensible.lua Normal file
View file

@ -0,0 +1,24 @@
return {
-- Easier comments (gc / gcc)
{
"numToStr/Comment.nvim",
event = "VeryLazy",
config = function()
require("Comment").setup()
end,
},
-- Actions that work on surrounding context
{ "tpope/vim-surround", event = "VeryLazy" },
{ "tpope/vim-unimpaired", event = "VeryLazy" },
{
"folke/todo-comments.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
},
event = "VeryLazy",
config = function()
require("todo-comments").setup()
end,
},
}

36
lua/plugins/telescope.lua Normal file
View file

@ -0,0 +1,36 @@
return {
"nvim-telescope/telescope.nvim",
cmd = "Telescope",
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ 'nvim-telescope/telescope-fzf-native.nvim',
build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build',
},
},
keys = {
{ "<leader>ff", "<cmd>Telescope find_files<CR>", desc = "Find Files" },
{ "<leader>ft", "<cmd>Telescope live_grep<CR>", desc = "Find a string" },
{ "<leader>fb", "<cmd>Telescope buffers<CR>", desc = "Find buffers" },
{ "<leader>fh", "<cmd>Telescope help_tags<CR>", desc = "Help" },
{ "<leader>fk", "<cmd>Telescope keymaps<CR>", desc = "Find keymaps" },
},
opts = {
defaults = {
prompt_prefix = "> ",
selection_caret = "> ",
path_display = { "smart" },
file_ignore_patterns = { ".git", "node_modules", ".idea", ".cache", "build_*" },
},
extensions = {
fzf = {
fuzzy = true, -- false will only do exact matching
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
},
},
},
config = function()
require("telescope").load_extension("fzf")
end,
}

View file

@ -0,0 +1,5 @@
return {
"folke/tokyonight.nvim",
lazy = true,
opts = { style = "moon" },
}

View file

@ -0,0 +1,82 @@
local load_textobjects = false
return {
{
"nvim-treesitter/nvim-treesitter",
version = false, -- last release is way too old and doesn't work on Windows
build = ":TSUpdate",
event = { "BufReadPost", "BufNewFile" },
dependencies = {
{
"nvim-treesitter/nvim-treesitter-textobjects",
init = function()
-- disable rtp plugin, as we only need its queries for mini.ai
-- In case other textobject modules are enabled, we will load them
-- once nvim-treesitter is loaded
require("lazy.core.loader").disable_rtp_plugin("nvim-treesitter-textobjects")
load_textobjects = true
end,
},
},
cmd = { "TSUpdateSync" },
keys = {
{ "<c-space>", desc = "Increment selection" },
{ "<bs>", desc = "Decrement selection", mode = "x" },
},
---@type TSConfig
opts = {
highlight = { enable = true },
indent = { enable = true },
ensure_installed = {
"bash",
"c",
"cpp",
"html",
"json",
"lua",
"markdown",
"python",
"rust",
"yaml",
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<C-space>",
node_incremental = "<C-space>",
scope_incremental = false,
node_decremental = "<bs>",
},
},
},
---@param opts TSConfig
config = function(_, opts)
if type(opts.ensure_installed) == "table" then
---@type table<string, boolean>
local added = {}
opts.ensure_installed = vim.tbl_filter(function(lang)
if added[lang] then
return false
end
added[lang] = true
return true
end, opts.ensure_installed)
end
require("nvim-treesitter.configs").setup(opts)
if load_textobjects then
-- PERF: no need to load the plugin, if we only need its queries for mini.ai
if opts.textobjects then
for _, mod in ipairs({ "move", "select", "swap", "lsp_interop" }) do
if opts.textobjects[mod] and opts.textobjects[mod].enable then
local Loader = require("lazy.core.loader")
Loader.disabled_rtp_plugins["nvim-treesitter-textobjects"] = nil
local plugin = require("lazy.core.config").plugins["nvim-treesitter-textobjects"]
require("lazy.core.loader").source_runtime(plugin.dir, "plugin")
break
end
end
end
end
end,
},
}

View file

@ -0,0 +1,5 @@
return {
"folke/neodev.nvim",
"folke/which-key.nvim",
{ "folke/neoconf.nvim", cmd = "Neoconf" },
}