1
0
Fork 0
mirror of https://github.com/pnx/dotfiles synced 2026-06-16 19:30:01 +02:00

update nvim config

This commit is contained in:
Henrik Hautakoski 2024-03-06 18:32:18 +01:00
parent e3f9d23175
commit 1e68462bc1
21 changed files with 350 additions and 99 deletions

View file

@ -1,12 +1,8 @@
--
-- Filetype settings
--
local autocmd = vim.api.nvim_create_autocmd
local augroup = vim.api.nvim_create_augroup
local set = vim.opt
-- Default softtab (4)
set.tabstop = 4
set.softtabstop = 4
set.shiftwidth = 4
set.autoindent = true
augroup('indent', { clear = true })
@ -30,3 +26,9 @@ autocmd('Filetype', {
pattern = { 'c', 'cpp' },
command = 'setlocal ts=8 sts=0 sw=8 noexpandtab'
})
-- Fix autocomment plugins to use line comments for php.
autocmd('Filetype', {
pattern = 'php',
command = 'setlocal commentstring=//\\%s'
})

52
nvim/lua/config/icons.lua Normal file
View file

@ -0,0 +1,52 @@
return {
prompt = '',
current = ' ',
selected = '',
close = '',
pinned = '',
diff = {
added = '',
modified = '',
removed = '',
},
filetree = {
basic = {
folder_closed = "",
folder_open = "",
folder_empty = "󰜌",
},
git = {
-- Change type
added = "",
modified = "",
deleted = "",
renamed = "󰁕",
-- Status type
untracked = "",
ignored = "",
unstaged = "",
staged = "",
conflict = "",
},
},
diff_gutter = {
add = '',
change = '',
delete = '',
untracked = '+'
},
diagnostics = {
error = '',
warn = '',
info = '',
hint = ''
},
test = {
ok = '',
failed = '',
running = '',
skipped = '',
watch = '',
unknown = '',
}
}

View file

@ -1,3 +1,3 @@
require("config.settings")
require("config.mappings")
require("config.indent")
require("config.filetype")

View file

@ -1,21 +1,49 @@
--
-- Keymaps! Alot of stuff "borrowed" from thePrimeagen
--
local map = vim.keymap.set
local cmd = vim.cmd
vim.g.mapleader = " "
-- Undo/Redo in insert mode
map("i", "<C-z>", cmd.undo)
map("i", "<C-y>", cmd.redo)
-- Make half page jumps stay in the center of screen
map("n", "<C-u>", "<C-u>zz", { silent = true, desc = "jump half a page up" })
map("n", "<C-d>", "<C-d>zz", { silent = true, desc = "jump half a page down" })
map("n", "<S-PageUp>", "<C-u>zz", { silent = true, desc = "jump half a page up" })
map("n", "<S-PageDown>", "<C-d>zz", { silent = true, desc = "jump half a page down" })
-- Make jump to next search item stay in the center of screen.
map("n", "n", "nzzzv", { silent = true, desc = "jump to next search match" })
map("n", "N", "Nzzzv", { silent = true, desc = "jump to previous search match" })
-- Ctrl+s saves the current buffer in normal/insert mode.
map("n", "<C-s>", cmd.w)
map("i", "<C-s>", cmd.w)
map({"n", "i"}, "<C-s>", cmd.w, { desc = "save current buffer" })
-- Move Text
map("n", "<S-a>", ":m+1<CR>")
map("n", "<S-d>", ":m-2<CR>")
-- Move text
map("n", "<S-a>", ":m -2<CR>v=", { silent = true, desc = "move current line one line up" })
map("n", "<S-d>", ":m +1<CR>v=", { silent = true, desc = "move current line one line down" })
map("v", "<S-a>", ":m '<-2<CR>gv=gv", { silent = true, desc = "move current selection one line up" })
map("v", "<S-d>", ":m '>+1<CR>gv=gv", { silent = true, desc = "move current selection one line down" })
-- copy/paste
map("x", "<leader>p", [["_dP]], { silent = true, desc = "Paste over selected text without losing content in \"-register" })
map({"n", "v"}, "<leader>y", [["+y]], { desc = "Yank to system clipboard register" })
-- File operations
map("n", "<leader>fx", "<cmd>!chmod +x %<CR>", { silent = true, desc = "Set execute flag on current file" })
-- buffers
map("n", "<leader>bn", cmd.bn, { silent = true, desc = "Move to next buffer"})
map("n", "<leader>bb", cmd.bp, { silent = true, desc = "Move to previous buffer"})
map("n", "<leader>bd", cmd.bd, { silent = true, desc = "Close current buffer"})
-- Indent
map('n', "<Tab>", "v=")
map('x', "<Tab>", "=", { desc = "auto indent selection" })
map("i", "<S-Tab>", "<C-d>", { desc = "delete indent" })
-- Make Shift-Tab undo indent.
map("i", "<S-Tab>", "<C-d>")
-- Crazy search+replace
map("n", "<leader>rw", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]], {
desc = "search+replace word under cursor"
})
map("n", "Q", "<nop>")

View file

@ -1,25 +1,35 @@
--
local set = vim.opt
-- General Settings
--
vim.opt.showmode = false -- disable mode in the command line, because i use lualine
set.termguicolors = true
set.updatetime = 50
set.showmode = false -- disable mode in the command line, because i use lualine
--
-- Editor settings
--
vim.opt.scrolloff=20
set.hlsearch = false
set.incsearch = true
set.laststatus = 3
set.scrolloff=20
--vim.opt.sidescrolloff = 8
vim.opt.cursorline = true
set.cursorline = true
-- line numbers
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.numberwidth = 5
vim.opt.statuscolumn = '%=%{v:relnum?v:relnum:v:lnum} %s '
set.number = true
set.relativenumber = true
set.numberwidth = 5
set.statuscolumn = '%=%{v:relnum?v:relnum:v:lnum} %s '
-- indent
vim.opt.smartindent = true
set.tabstop = 4
set.softtabstop = 4
set.shiftwidth = 4
set.autoindent = true
set.smartindent = true
-- Filetypes
vim.filetype.add({

View file

@ -1,8 +1,13 @@
return {
{ '<leader>sf', '<cmd>Telescope find_files<cr>', desc = 'Search files' },
{ '<leader>sa', '<cmd>Telescope live_grep<cr>', desc = 'Search in files' },
{ '<leader>sg', '<cmd>Telescope git_files<cr>', desc = 'Search Git files' },
{ '<leader>sw', '<cmd>Telescope grep_string<cr>', desc = 'Search Word' },
{ '<leader>sw', '<cmd>Telescope grep_string<cr>', desc = 'Search for word under cursor' },
-- LSP
--{ 'gd', '<cmd>Telescope lsp_definitions<cr>', desc = 'Goto definition' },
{ '<leader>sr', '<cmd>Telescope lsp_references<cr>', desc = 'Search Reference' },
{ '<leader>ss', '<cmd>Telescope lsp_document_symbols<cr>', desc = 'Search document symbols' },
{ '<leader>sr', '<cmd>Telescope lsp_references<cr>', desc = 'Search Reference' },
{ '<leader>sr', '<cmd>Telescope lsp_references<cr>', desc = 'Search Reference' },
{ 'gd', '<cmd>Telescope lsp_definitions<cr>', desc = 'Goto definition' },
}

View file

@ -0,0 +1,29 @@
local icons = require('config.icons')
return {
'romgrk/barbar.nvim',
dependencies = {
'lewis6991/gitsigns.nvim',
'nvim-tree/nvim-web-devicons',
},
init = function() vim.g.barbar_auto_setup = false end,
opts = {
animation = false,
auto_hide = 0,
focus_on_close = 'previous',
button = icons.close,
highlight_inactive_file_icons = true,
icons = {
separator = {left = '', right = ''},
separator_at_end = false,
inactive = { button = '' },
modified = {button = icons.filetree.git.modified },
pinned = {button = '', filename = true},
},
maximum_padding = 2,
minimum_padding = 1,
sidebar_filetypes = {
['neo-tree'] = {event = 'BufWipeout'},
}
},
}

View file

@ -52,5 +52,10 @@ return {
local c = require('onedark')
c.setup(opts)
c.load()
vim.cmd(string.format("highlight GitSignsAdd guifg='%s'", opts.colors.green))
vim.cmd(string.format("highlight GitSignsChange guifg='%s'", opts.colors.yellow))
vim.cmd(string.format("highlight GitSignsDelete guifg='%s'", opts.colors.red))
-- vim.api.nvim_command("highlight GitSign"
end
}

View file

@ -1,3 +1,5 @@
local icons = require('config.icons').diff_gutter
return {
'lewis6991/gitsigns.nvim',
lazy = false,
@ -7,10 +9,12 @@ return {
},
opts = {
signs = {
add = { text = '' },
delete = { text = '' },
change = { text = '' },
untracked = { text = '+'}
add = { text = icons.add },
delete = { text = icons.delete },
change = { text = icons.change },
untracked = { text = icons.untracked },
topdelete = { text = icons.delete },
changedelete = { text = icons.change },
},
},
}

View file

@ -1,12 +1,13 @@
return {
"ray-x/go.nvim",
main = "go",
dependencies = {
"ray-x/guihua.lua",
"neovim/nvim-lspconfig",
"nvim-treesitter/nvim-treesitter",
},
config = function()
require("go").setup()
config = function(opts)
require('go').setup(opts)
end,
event = {"CmdlineEnter"},
ft = {"go", 'gomod'},

View file

@ -1,4 +1,4 @@
return {
return{
"lukas-reineke/indent-blankline.nvim",
main = "ibl",
opts = {

View file

@ -21,6 +21,7 @@ require("lazy").setup({
{ import = "plugins.indent" },
{ import = "plugins.nvim-autopairs" },
{ import = "plugins.mini-comment" },
{ import = "plugins.barbar" },
-- Filetree
{ import = "plugins.neo-tree" },
@ -37,6 +38,8 @@ require("lazy").setup({
-- Treesitter
{ import = "plugins.treesitter" },
{ import = "plugins.neotest" },
-- LSP
{ import = "plugins.lsp" },
{ import = "plugins.nvim-cmp" },

View file

@ -3,16 +3,25 @@ return {
dependencies = {
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
'hrsh7th/cmp-nvim-lsp',
},
config = function()
-- Setup Mason to automatically install LSP servers
require('mason').setup()
require('mason-lspconfig').setup({ automatic_installation = true })
local lspconfig = require('lspconfig')
-- local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
local capabilities = require('cmp_nvim_lsp').default_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = false
local on_attach = function(ev)
vim.keymap.set('n', '<leader>rs', vim.lsp.buf.rename, { buffer = ev.buf, desc = "Rename symbol" })
end
-- php - phpactor
lspconfig.phpactor.setup({
on_attach = on_attach,
capabilities = capabilities,
init_options = {
["language_server_phpstan.enabled"] = true,
["language_server_psalm.enabled"] = false,
@ -20,7 +29,10 @@ return {
})
-- GO
lspconfig.gopls.setup({})
lspconfig.gopls.setup({
on_attach = on_attach,
capabilities = capabilities
})
-- Tailwind CSS
--require('lspconfig').tailwindcss.setup({ capabilities = capabilities })
@ -33,7 +45,9 @@ return {
})
-- Typescript
lspconfig.tsserver.setup({})
lspconfig.tsserver.setup({
capabilities = capabilities
})
-- lua
lspconfig.lua_ls.setup({
@ -55,14 +69,16 @@ return {
})
end
return true
end
end,
capabilities = capabilities
})
-- Config
-- Sign configuration
vim.fn.sign_define('DiagnosticSignError', { text = '', texthl = 'DiagnosticSignError' })
vim.fn.sign_define('DiagnosticSignWarn', { text = '', texthl = 'DiagnosticSignWarn' })
vim.fn.sign_define('DiagnosticSignInfo', { text = '', texthl = 'DiagnosticSignInfo' })
vim.fn.sign_define('DiagnosticSignHint', { text = '', texthl = 'DiagnosticSignHint' })
local icons = require('config.icons').diagnostics
vim.fn.sign_define('DiagnosticSignError', { text = icons.error, texthl = 'DiagnosticSignError' })
vim.fn.sign_define('DiagnosticSignWarn', { text = icons.warn, texthl = 'DiagnosticSignWarn' })
vim.fn.sign_define('DiagnosticSignInfo', { text = icons.info, texthl = 'DiagnosticSignInfo' })
vim.fn.sign_define('DiagnosticSignHint', { text = icons.hint, texthl = 'DiagnosticSignHint' })
end
}

View file

@ -1,26 +1,61 @@
local icons = require('config.icons')
return {
'nvim-lualine/lualine.nvim',
event = "VeryLazy",
dependencies = {
'arkav/lualine-lsp-progress',
'kyazdani42/nvim-web-devicons',
'nvim-tree/nvim-web-devicons',
},
opts = {
options = {
component_separators = '',
globalstatus = true,
disabled_filetypes = {
statusline = {
'dashboard',
'TelescopePrompt'
}
}
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch" },
lualine_x = {
{
require("lazy.status").updates,
cond = require("lazy.status").has_updates,
color = { fg = "#ff9e64" },
}
},
-- {
-- "diff",
-- symbols = {
-- added = icons.diff.added .. ' ',
-- modified = icons.diff.modified .. ' ',
-- removed = icons.diff.removed .. ' '
-- }
-- },
{
"diagnostics",
symbols = {
error = icons.diagnostics.error .. ' ',
warn = icons.diagnostics.warn .. ' ',
info = icons.diagnostics.info .. ' ',
hint = icons.diagnostics.hint .. ' ',
},
},
},
lualine_y = {
'encoding', 'fileformat', 'filetype'
}
'encoding',
'fileformat',
'filetype',
'location'
},
lualine_z = {}
},
extensions = {
'lazy',
'neo-tree'
}
}
}

View file

@ -1,7 +1,9 @@
return {
'echasnovski/mini.comment',
version = '*',
config = function()
require('mini.comment').setup({})
end
opts = {
options = {
custom_commentstring = function() return vim.bo.commentstring end
}
}
}

View file

@ -1,8 +1,10 @@
local icons = require('config.icons')
return {
'nvim-neo-tree/neo-tree.nvim',
cmd = 'Neotree',
keys = {
{ '<leader>n', ':Neotree reveal toggle<CR>' },
{ '<leader>fe', ':Neotree reveal toggle<CR>', desc = 'Toggle File Explorer'},
},
dependencies = {
"MunifTanjim/nui.nvim",
@ -21,30 +23,24 @@ return {
indent_marker = "",
last_indent_marker = "",
},
icon = {
folder_closed = "",
folder_open = "",
folder_empty = "󰜌",
},
icon = icons.filetree.basic,
name = {
use_git_status_colors = true,
use_git_status_colors = false,
},
git_status = {
symbols = {
-- Change type
added = "",
modified = "",
deleted = "",
renamed = "󰁕",
-- Status type
untracked = "",
ignored = "",
unstaged = "",
staged = "",
conflict = "",
}
symbols = icons.filetree.git
},
},
event_handlers = {
{
event = "neo_tree_buffer_enter",
handler = function()
if vim.bo.filetype == "neo-tree" then
vim.cmd("setlocal statuscolumn=")
end
end,
}
},
filesystem = {
filtered_items = {
visible = true, -- when true, they will just be displayed differently than normal items
@ -56,6 +52,9 @@ return {
"vendor",
},
},
follow_current_file = {
enable = true
},
},
}
}

View file

@ -0,0 +1,44 @@
return {
"nvim-neotest/neotest",
dependencies = {
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter",
"nvim-neotest/neotest-go",
"olimorris/neotest-phpunit"
},
keys = {
{"<leader>tn", ":lua require('neotest').run.run()<cr>", desc = "test nearest"},
{"<leader>tf", ":lua require('neotest').run.run(vim.fn.expand('%'))<cr>", desc = "test file"},
{"<leader>ta", ":lua require('neotest').output_panel.open()<cr>:lua require('neotest').run.run({suite = true})<cr>", desc = "test all"},
{"<leader>ts", ":lua require('neotest').run.stop()<cr>", desc = "stop test"},
{"<leader>tq", ":lua require('neotest').output_panel.close()<cr>", desc = "close output window"},
},
opts = function()
local icons = require('config.icons').test
return {
adapters = {
require("neotest-go")({
recursive_run = true
}),
require("neotest-phpunit")
},
icons = {
child_indent = "",
child_prefix = "",
collapsed = "",
expanded = "",
failed = icons.failed,
final_child_indent = " ",
final_child_prefix = "",
non_collapsible = "",
passed = icons.ok,
running = icons.running,
skipped = icons.skipped,
unknown = icons.unknown,
watching = icons.watch
}
}
end
}

View file

@ -1,27 +1,37 @@
local icons = require('config.icons')
return {
'nvim-telescope/telescope.nvim',
'nvim-telescope/telescope.nvim',
tag = '0.1.4',
dependencies = {
main = 'telescope',
dependencies = {
'nvim-lua/plenary.nvim',
'kyazdani42/nvim-web-devicons'
'nvim-tree/nvim-web-devicons'
},
keys = require('config.telescope'),
config = function()
require('telescope').setup({
opts = function()
local actions = require("telescope.actions")
return {
defaults = {
path_display = { truncate = 1 },
prompt_prefix = ' ',
selection_caret = ' ',
file_ignore_patterns = {
prompt_prefix = ' ' .. icons.prompt .. ' ',
selection_caret = icons.current .. ' ',
multi_icon = icons.selected .. ' ',
file_ignore_patterns = {
".git/",
"node_modules/"
"node_modules/"
},
mappings = {
i = {
["<esc>"] = actions.close
}
}
},
pickers = {
find_files = {
hidden = true
},
},
})
end
}
}
}
end,
}

View file

@ -4,6 +4,7 @@ return {
require('nvim-treesitter.install').update({ with_sync = true })
end,
dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects',
'nvim-treesitter/playground'
},
opts = {
@ -55,9 +56,9 @@ return {
additional_vim_regex_highlighting = false,
},
-- indent = {
-- enable = true
--}
indent = {
enable = true
}
},
config = function(_, opts)
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()

View file

@ -10,12 +10,11 @@ return {
local wk = require("which-key")
wk.register({
f = {
name = "file", -- optional group name
f = { "<cmd>Telescope find_files<cr>", "Find File" }, -- create a binding with label
n = { "New File" }, -- just a label. don't create any mapping
e = "Edit File" -- same as above
},
f = 'file',
b = 'buffers',
t = 'test',
g = 'git',
s = 'search'
}, { prefix = "<leader>" })
end
}