summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-09-14 19:48:38 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-09-14 20:05:12 +0200
commit7dcd592eae886dc8edde2dc65d6e6323201a2aaf (patch)
tree8c792984bd55d710dd409bcc90d450e2e90a58ce
parent6081f67ec9f5032fcd9d4453a2646ca033364615 (diff)
checkpoint
- changed installation of tmux-navigator - removed init.lua file in user/ directory - added autocmd for terminal in insert mode - added keybind for opening terminal - added keybinds for lsp commands - added lua lsp setup - added nvim-cmp - added keybind for editing config - added keybinds for opening splits - added conceallevel = 2 - commented encoding options - plugins: - added go.nvim - added cmp-calc - markdown: - disable pairs for quotes - added pairs in markdown - go: - added go lsp - added autoformat of go files on save
-rw-r--r--after/plugin/autoclose.lua34
-rw-r--r--after/plugin/conform.lua10
-rw-r--r--after/plugin/vim-tmux-navigator.lua6
-rw-r--r--init.lua66
-rw-r--r--lua/user/init.lua37
-rw-r--r--lua/user/lazy.lua37
-rw-r--r--lua/user/lsp.lua103
-rw-r--r--lua/user/main.go7
-rw-r--r--lua/user/map.lua7
-rw-r--r--lua/user/set.lua5
10 files changed, 247 insertions, 65 deletions
diff --git a/after/plugin/autoclose.lua b/after/plugin/autoclose.lua
index 543d7d9..b742fc6 100644
--- a/after/plugin/autoclose.lua
+++ b/after/plugin/autoclose.lua
@@ -1,20 +1,34 @@
-require("autoclose").setup({
+local filetypes = require("autoclose").setup({
keys = {
["("] = { escape = false, close = true, pair = "()" },
- ["["] = { escape = false, close = true, pair = "[]" },
- ["{"] = { escape = false, close = true, pair = "{}" },
-
- [">"] = { escape = true, close = false, pair = "<>" },
[")"] = { escape = true, close = false, pair = "()" },
+ ["["] = { escape = false, close = true, pair = "[]" },
["]"] = { escape = true, close = false, pair = "[]" },
+ ["{"] = { escape = false, close = true, pair = "{}" },
["}"] = { escape = true, close = false, pair = "{}" },
-
- ['"'] = { escape = true, close = true, pair = '""' },
- ["'"] = { escape = true, close = true, pair = "''" },
- ["`"] = { escape = true, close = true, pair = "``" },
+ [">"] = { escape = true, close = false, pair = "<>" },
+ ['"'] = {
+ escape = true,
+ close = true,
+ pair = '""',
+ disabled_filetypes = { "text", "telekasten", "groff", "diff", "gitcommit", "fugitive", "markdown" },
+ },
+ ["'"] = {
+ escape = true,
+ close = true,
+ pair = "''",
+ disabled_filetypes = { "text", "telekasten", "groff", "diff", "gitcommit", "fugitive", "markdown" },
+ },
+ ["`"] = {
+ escape = true,
+ close = true,
+ pair = "``",
+ disabled_filetypes = { "text", "telekasten", "groff", "diff", "gitcommit", "fugitive" },
+ },
+ ["*"] = { escape = true, close = true, pair = "**", enabled_filetypes = { "markdown" } },
+ ["_"] = { escape = true, close = true, pair = "__", enabled_filetypes = { "markdown" } },
},
options = {
- disabled_filetypes = { "text", "telekasten", "groff", "diff", "gitcommit", "fugitive" },
disable_when_touch = true,
},
})
diff --git a/after/plugin/conform.lua b/after/plugin/conform.lua
new file mode 100644
index 0000000..13961b6
--- /dev/null
+++ b/after/plugin/conform.lua
@@ -0,0 +1,10 @@
+require("conform").setup({
+ formatters_by_ft = {
+ lua = { "stylua" },
+ },
+ format_on_save = {
+ -- These options will be passed to conform.format()
+ timeout_ms = 500,
+ lsp_format = "fallback",
+ },
+})
diff --git a/after/plugin/vim-tmux-navigator.lua b/after/plugin/vim-tmux-navigator.lua
deleted file mode 100644
index 1574080..0000000
--- a/after/plugin/vim-tmux-navigator.lua
+++ /dev/null
@@ -1,6 +0,0 @@
-vim.g.tmux_navigator_no_mappings = true
-vim.keymap.set("n", "<M-h>", ":<C-U>TmuxNavigateLeft<cr>", { silent = true })
-vim.keymap.set("n", "<M-j>", ":<C-U>TmuxNavigateDown<cr>", { silent = true })
-vim.keymap.set("n", "<M-k>", ":<C-U>TmuxNavigateUp<cr>", { silent = true })
-vim.keymap.set("n", "<M-l>", ":<C-U>TmuxNavigateRight<cr>", { silent = true })
-vim.keymap.set("n", "<M-/>", ":<C-U>TmuxNavigatePrevious<cr>", { silent = true })
diff --git a/init.lua b/init.lua
index ea49ffa..6f73586 100644
--- a/init.lua
+++ b/init.lua
@@ -1 +1,65 @@
-require("user")
+require("user.lazy")
+require("user.set")
+require("user.map")
+require("user.lsp")
+
+local autocmd = vim.api.nvim_create_autocmd
+
+local function augroup(name)
+ return vim.api.nvim_create_augroup("user_" .. name, { clear = true })
+end
+
+-- [[ Highlight on yank ]]
+autocmd("TextYankPost", {
+ group = augroup("highlight_yank"),
+ callback = function()
+ vim.highlight.on_yank()
+ end,
+})
+
+-- [[ Auto create parent directory if it doesn't exist ]]
+autocmd("BufWritePre", {
+ group = augroup("auto_create_dir"),
+ callback = function(event)
+ if event.match:match("^%w%w+://") then
+ return
+ end
+ local file = vim.loop.fs_realpath(event.match) or event.match
+ vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
+ end,
+})
+
+-- Run gofmt + goimports on save
+local format_sync_grp = vim.api.nvim_create_augroup("goimports", {})
+autocmd("BufWritePre", {
+ pattern = "*.go",
+ callback = function()
+ require("go.format").goimports()
+ end,
+ group = format_sync_grp,
+})
+
+autocmd("TermOpen", {
+ callback = function()
+ local o = vim.opt_local
+ o.signcolumn = "no"
+ o.number = false
+ o.relativenumber = false
+ vim.cmd("startinsert")
+ vim.keymap.set("t", "<Esc>", "<C-\\><C-n>", { noremap = true })
+ end,
+})
+-- -- close automatically when shell process exits
+-- -- TODO: does not work
+-- autocmd("TermClose", {
+-- callback = function()
+-- vim.cmd("bdelete")
+-- end,
+-- })
+vim.keymap.set("n", "!", "<cmd>sp<CR><cmd>term<CR>", { desc = "Open terminal" })
+
+-- [[ preserve last position ]]
+autocmd("BufReadPost", {
+ pattern = "*",
+ command = 'silent! normal! g`"zv',
+})
diff --git a/lua/user/init.lua b/lua/user/init.lua
deleted file mode 100644
index b467dc3..0000000
--- a/lua/user/init.lua
+++ /dev/null
@@ -1,37 +0,0 @@
-require("user.set")
-require("user.map")
-require("user.lazy")
-require("user.lsp")
-
-local autocmd = vim.api.nvim_create_autocmd
-
-local function augroup(name)
- return vim.api.nvim_create_augroup("user_" .. name, { clear = true })
-end
-
--- [[ Highlight on yank ]]
-autocmd("TextYankPost", {
- group = augroup("highlight_yank"),
- callback = function()
- vim.highlight.on_yank()
- end,
-})
-
--- [[ Auto create parent directory if it doesn't exist ]]
-autocmd("BufWritePre", {
- group = augroup("auto_create_dir"),
- callback = function(event)
- if event.match:match("^%w%w+://") then
- return
- end
- local file = vim.loop.fs_realpath(event.match) or event.match
- vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
- end,
-})
-
-autocmd("BufWritePre", {
- pattern = "*",
- callback = function(args)
- require("conform").format({ bufnr = args.buf })
- end,
-})
diff --git a/lua/user/lazy.lua b/lua/user/lazy.lua
index 640e10f..31780ec 100644
--- a/lua/user/lazy.lua
+++ b/lua/user/lazy.lua
@@ -42,7 +42,9 @@ require("lazy").setup({
"hrsh7th/cmp-path",
-- cmp snippy support
"dcampos/cmp-snippy",
+ "hrsh7th/cmp-calc",
},
+ event = { "InsertEnter", "CmdlineEnter" },
},
-- kind icons
"onsails/lspkind.nvim",
@@ -53,12 +55,43 @@ require("lazy").setup({
-- better ntrw
"tpope/vim-vinegar",
-- integration with tmux keybinds
- "christoomey/vim-tmux-navigator",
+ {
+ "christoomey/vim-tmux-navigator",
+ cmd = {
+ "TmuxNavigateLeft",
+ "TmuxNavigateDown",
+ "TmuxNavigateUp",
+ "TmuxNavigateRight",
+ "TmuxNavigatePrevious",
+ },
+ keys = {
+ { "<M-h>", "<cmd>TmuxNavigateLeft<cr>" },
+ { "<M-j>", "<cmd>TmuxNavigateDown<cr>" },
+ { "<M-k>", "<cmd>TmuxNavigateUp<cr>" },
+ { "<M-l>", "<cmd>TmuxNavigateRight<cr>" },
+ { "<M-\\>", "<cmd>TmuxNavigatePrevious<cr>" },
+ },
+ },
-- auto close brackets
"m4xshen/autoclose.nvim",
},
+ {
+ "ray-x/go.nvim",
+ dependencies = { -- optional packages
+ "ray-x/guihua.lua",
+ "neovim/nvim-lspconfig",
+ "nvim-treesitter/nvim-treesitter",
+ },
+ config = function()
+ require("go").setup()
+ end,
+ event = { "CmdlineEnter" },
+ ft = { "go", "gomod" },
+ build = ':lua require("go.install").update_all_sync()', -- if you need to install/update all binaries
+ },
- "mg979/vim-visual-multi",
+ "mg979/vim-visual-multi",
+ "jghauser/follow-md-links.nvim",
{
"dstein64/vim-startuptime",
diff --git a/lua/user/lsp.lua b/lua/user/lsp.lua
index 2de41ba..1443887 100644
--- a/lua/user/lsp.lua
+++ b/lua/user/lsp.lua
@@ -1,2 +1,105 @@
+-- [[ Keybinds ]]
+local map = vim.keymap.set
+map("n", " a", vim.lsp.buf.code_action)
+map("n", "gd", vim.lsp.buf.definition)
+map("n", " r", vim.lsp.buf.rename)
+map("n", " i", vim.lsp.buf.implementation)
+map("n", " sh", vim.lsp.buf.signature_help)
+map("n", " t", vim.lsp.buf.typehierarchy)
+map("n", " r", vim.lsp.buf.references)
+map("n", " sl", vim.lsp.buf.document_symbol)
+map("n", " td", vim.lsp.buf.type_definition)
+
+-- [[ LSP Setups ]]
local lspconfig = require("lspconfig")
+
+-- go
lspconfig.gopls.setup({})
+
+-- lua
+-- with neovim support
+require("lspconfig").lua_ls.setup({
+ on_init = function(client)
+ local path = client.workspace_folders[1].name
+ if vim.loop.fs_stat(path .. "/.luarc.json") or vim.loop.fs_stat(path .. "/.luarc.jsonc") then
+ return
+ end
+
+ client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, {
+ runtime = {
+ -- Tell the language server which version of Lua you're using
+ -- (most likely LuaJIT in the case of Neovim)
+ version = "LuaJIT",
+ },
+ -- Make the server aware of Neovim runtime files
+ workspace = {
+ checkThirdParty = false,
+ library = {
+ vim.env.VIMRUNTIME,
+ -- Depending on the usage, you might want to add additional paths here.
+ -- "${3rd}/luv/library"
+ -- "${3rd}/busted/library",
+ },
+ -- or pull in all of 'runtimepath'. NOTE: this is a lot slower
+ -- library = vim.api.nvim_get_runtime_file("", true)
+ },
+ })
+ end,
+ settings = {
+ Lua = {},
+ },
+})
+
+-- [[ nvim cmp ]]
+local capabilities = require("cmp_nvim_lsp").default_capabilities()
+local cmp = require("cmp")
+local lspkind = require("lspkind")
+cmp.setup({
+ snippet = {
+ expand = function(args)
+ require("snippy").expand_snippet(args.body)
+ end,
+ },
+ window = {
+ completion = cmp.config.window.bordered(),
+ documentation = cmp.config.window.bordered(),
+ },
+ mapping = cmp.mapping.preset.insert({
+ ["<C-b>"] = cmp.mapping.scroll_docs(-4),
+ ["<C-f>"] = cmp.mapping.scroll_docs(4),
+ ["<C-Space>"] = cmp.mapping.complete(),
+ ["<C-c>"] = cmp.mapping.abort(),
+ ["<CR>"] = cmp.mapping({
+ i = function(fallback)
+ if cmp.visible() and cmp.get_active_entry() then
+ cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
+ else
+ fallback()
+ end
+ end,
+ s = cmp.mapping.confirm({ select = true }),
+ c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
+ }),
+ }),
+ sources = cmp.config.sources({
+ { name = "nvim_lsp" },
+ -- { name = "snippy" },
+ }, {
+ { name = "buffer" },
+ { name = "calc" },
+ }),
+ formatting = {
+ format = lspkind.cmp_format({
+ mode = "symbol_text",
+ menu = {
+ buffer = "(Buffer)",
+ nvim_lsp = "(LSP)",
+ luasnip = "(LuaSnip)",
+ nvim_lua = "(Lua)",
+ latex_symbols = "(Latex)",
+ },
+ }),
+ },
+})
+
+vim.api.nvim_set_hl(0, "CmpItemMenu", { italic = true })
diff --git a/lua/user/main.go b/lua/user/main.go
deleted file mode 100644
index ef25884..0000000
--- a/lua/user/main.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package main
-
-import "fmt"
-
-func main() {
- fmt.Println("Hello, world!")
-}
diff --git a/lua/user/map.lua b/lua/user/map.lua
index ca4142b..230588f 100644
--- a/lua/user/map.lua
+++ b/lua/user/map.lua
@@ -4,6 +4,11 @@ local map = vim.keymap.set
vim.g.mapleader = " "
vim.g.maplocalleader = ","
+-- open config
+map("n", " c", function()
+ vim.cmd("cd ~/.config/nvim")
+ vim.cmd("e " .. "init.lua")
+end, { desc = "Open neovim config file" })
-- Move text easilly
map("v", "J", ":m '>+1<CR>gv=gv", { desc = "Move selected text up" })
map("v", "K", ":m '<-2<CR>gv=gv", { desc = "Move selected text down" })
@@ -23,6 +28,8 @@ map("i", "<C-e>", "<C-o>A", { noremap = true })
map("i", "<C-k>", "<C-o>D", { noremap = true })
-- buffers
+map("n", "<leader>sp", "<cmd>sp<cr>", { desc = "Open horizontal split" })
+map("n", "<leader>vs", "<cmd>vs<cr>", { desc = "Open vertical split" })
map("n", "gb", "<cmd>buffers<cr>:buffer<Space>", { noremap = true })
map("n", "<Leader>q", "<cmd>q!<cr>", { noremap = true })
map("n", "<Leader>Q", "<cmd>qa!<cr>", { noremap = true })
diff --git a/lua/user/set.lua b/lua/user/set.lua
index cb8dba4..6040c72 100644
--- a/lua/user/set.lua
+++ b/lua/user/set.lua
@@ -3,6 +3,7 @@ local opt = vim.opt
-- Don't highlight on search
opt.hlsearch = false
opt.incsearch = true
+opt.conceallevel = 2
-- Enable line numbers by default
opt.number = true
@@ -79,8 +80,8 @@ opt.backspace = "indent,eol,start"
opt.laststatus = 2
opt.history = 200
-opt.encoding = "utf-8"
-opt.fileencoding = "utf-8"
+-- opt.encoding = "utf-8"
+-- opt.fileencoding = "utf-8"
opt.smartindent = true
opt.scrolloff = 8