From fa147e9042677936bd01e020e306a8ce0271213a Mon Sep 17 00:00:00 2001 From: FredzyW Date: Mon, 27 May 2024 16:35:03 +0200 Subject: [PATCH] initial commit --- README.md | 5 ++ after/ftplugin/haskell.lua | 18 +++++++ init.lua | 32 ++++++++++++ lazy-lock.json | 33 ++++++++++++ lua/keybindings/keymap.lua | 72 ++++++++++++++++++++++++++ lua/opt/options.lua | 9 ++++ lua/plugin/autoclose.lua | 7 +++ lua/plugin/cmp.lua | 34 +++++++++++++ lua/plugin/dracula.lua | 40 +++++++++++++++ lua/plugin/fzf_lsp.lua | 1 + lua/plugin/lsp_config.lua | 34 +++++++++++++ lua/plugin/telescope.lua | 19 +++++++ lua/plugin/treesitter.lua | 34 +++++++++++++ lua/plugins.lua | 102 +++++++++++++++++++++++++++++++++++++ 14 files changed, 440 insertions(+) create mode 100644 README.md create mode 100644 after/ftplugin/haskell.lua create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/keybindings/keymap.lua create mode 100644 lua/opt/options.lua create mode 100644 lua/plugin/autoclose.lua create mode 100644 lua/plugin/cmp.lua create mode 100644 lua/plugin/dracula.lua create mode 100644 lua/plugin/fzf_lsp.lua create mode 100644 lua/plugin/lsp_config.lua create mode 100644 lua/plugin/telescope.lua create mode 100644 lua/plugin/treesitter.lua create mode 100644 lua/plugins.lua diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a7496f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# nvim + +Detta är ett repo för att hålla filerna till min NeoVim konfiguration. + +Konfigurationen är ganska minimal estetiskt, men har hyfsat mycket funktionalitet. diff --git a/after/ftplugin/haskell.lua b/after/ftplugin/haskell.lua new file mode 100644 index 0000000..9893168 --- /dev/null +++ b/after/ftplugin/haskell.lua @@ -0,0 +1,18 @@ +-- ~/.config/nvim/after/ftplugin/haskell.lua +local ht = require('haskell-tools') +local bufnr = vim.api.nvim_get_current_buf() +local opts = { noremap = true, silent = true, buffer = bufnr, } +-- haskell-language-server relies heavily on codeLenses, +-- so auto-refresh (see advanced configuration) is enabled by default +vim.keymap.set('n', 'cl', vim.lsp.codelens.run, opts) +-- Hoogle search for the type signature of the definition under the cursor +vim.keymap.set('n', 'hs', ht.hoogle.hoogle_signature, opts) +-- Evaluate all code snippets +vim.keymap.set('n', 'ra', ht.lsp.buf_eval_all, opts) +-- Toggle a GHCi repl for the current package +vim.keymap.set('n', 'rr', ht.repl.toggle, opts) +-- Toggle a GHCi repl for the current buffer +vim.keymap.set('n', 'rf', function() + ht.repl.toggle(vim.api.nvim_buf_get_name(0)) +end, opts) +vim.keymap.set('n', 'rq', ht.repl.quit, opts) diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..7f91fa4 --- /dev/null +++ b/init.lua @@ -0,0 +1,32 @@ +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) + + +require("lazy").setup("plugins") + +-- Keybindsings +require 'keybindings.keymap' + +-- Settings +require 'opt.options' + +-- Configuration of plugins +require 'plugin.telescope' +require 'plugin.fzf_lsp' +require 'plugin.autoclose' +require 'plugin.lsp_config' +require 'plugin.treesitter' +require 'plugin.dracula' +require 'plugin.cmp' + +vim.cmd('colorscheme dracula-soft') diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..98ebd0c --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,33 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "a7a4b4682c4b3e2ba82b82a4e6e5f5a0e79dec32" }, + "LuaSnip-snippets.nvim": { "branch": "main", "commit": "d7e40e4cce622eab2316607dbcd8d6039bcb9fe0" }, + "autoclose.nvim": { "branch": "main", "commit": "dc42806540dcf448ecb2bad6b67204410cfbe629" }, + "base16-nvim": { "branch": "master", "commit": "b3e9ec6a82c05b562cd71f40fe8964438a9ba64a" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "dracula.nvim": { "branch": "main", "commit": "8d8bddb8814c3e7e62d80dda65a9876f97eb699c" }, + "friendly-snippets": { "branch": "main", "commit": "ea068f1becd91bcd4591fceb6420d4335e2e14d3" }, + "fzf": { "branch": "master", "commit": "c30e486b648c1540a660802a5015aeca208274fa" }, + "fzf-lsp.nvim": { "branch": "main", "commit": "16905056051759b15a388709a3fa65ff098eb243" }, + "haskell-tools.nvim": { "branch": "master", "commit": "217cb7958ebbebf360f7c43efd5129e66d748042" }, + "indent-blankline.nvim": { "branch": "master", "commit": "3d08501caef2329aba5121b753e903904088f7e6" }, + "lazy.nvim": { "branch": "main", "commit": "af6afefbb46ab29a8a1db69536b04290a9403876" }, + "lazygit.nvim": { "branch": "main", "commit": "0ada6c6e7e138df92f5009b6952f4ac41248305a" }, + "leap.nvim": { "branch": "main", "commit": "25753d8a16b69fbbce5d392702c21dbc79d86bd1" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "2b5e9a39b3bf60bfb0cc7c35d5f2e879d4cd72ea" }, + "neoconf.nvim": { "branch": "main", "commit": "9a419c4fa772c4c61839a8f7fdd8e863679a8c94" }, + "neodev.nvim": { "branch": "main", "commit": "6a533ed9d3435dcaa456380d833ea04da37ea2ed" }, + "nvim-cmp": { "branch": "main", "commit": "97dc716fc914c46577a4f254035ebef1aa72558a" }, + "nvim-dap": { "branch": "master", "commit": "c1695e500c7d552a0a19953a9aefcc89178fb1af" }, + "nvim-lspconfig": { "branch": "master", "commit": "6e5c78ebc9936ca74add66bda22c566f951b6ee5" }, + "nvim-treesitter": { "branch": "master", "commit": "1c3fb9eac2a04230e4af23715fa2c190cbeacd70" }, + "plenary.nvim": { "branch": "master", "commit": "f7adfc4b3f4f91aab6caebf42b3682945fbc35be" }, + "ripgrep": { "branch": "master", "commit": "3ad0e83471588d8802d5747d0cc9accec76f7ccf" }, + "rnvimr": { "branch": "main", "commit": "3c41af742a61caf74a9f83fb82b9ed03ef13b880" }, + "sniprun": { "branch": "master", "commit": "97daa506e2faa3939e0491642103635f9d22cd04" }, + "substitute.nvim": { "branch": "main", "commit": "17ffaeb5a1dc2dbef39cf0865d8a4b6000836714" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" }, + "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, + "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" } +} \ No newline at end of file diff --git a/lua/keybindings/keymap.lua b/lua/keybindings/keymap.lua new file mode 100644 index 0000000..9cb7d6f --- /dev/null +++ b/lua/keybindings/keymap.lua @@ -0,0 +1,72 @@ +vim.keymap.set('n', 'z', '(leap)') +vim.keymap.set('n', 'Z', '(leap-from-window)') +vim.keymap.set({ 'x', 'o' }, 'z', '(leap-forward)') +vim.keymap.set({ 'x', 'o' }, 'Z', '(leap-backward)') + +-- Substitute +vim.keymap.set("n", "s", require('substitute').operator, { noremap = true }) +vim.keymap.set("n", "ss", require('substitute').line, { noremap = true }) +vim.keymap.set("n", "S", require('substitute').eol, { noremap = true }) +vim.keymap.set("x", "s", require('substitute').visual, { noremap = true }) + +-- Move commands +vim.keymap.set('n', '', ':MoveLine(1)', opts) +vim.keymap.set('n', '', ':MoveLine(-1)', opts) +vim.keymap.set('v', '', ':MoveBlock(1)', opts) +vim.keymap.set('v', '', ':MoveBlock(-1)', opts) + +-- Good navigation mappings for wrap +vim.api.nvim_set_keymap('n', 'j', 'gj', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'k', 'gk', { noremap = true, silent = true }) + +-- Buffer navigation +vim.api.nvim_set_keymap('n', '', ':bnext', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', ':bprevious', { noremap = true, silent = true }) + +-- Window navigation +vim.api.nvim_set_keymap('n', '', ':wincmd k', { silent = true }) +vim.api.nvim_set_keymap('n', '', ':wincmd j', { silent = true }) +vim.api.nvim_set_keymap('n', '', ':wincmd h', { silent = true }) +vim.api.nvim_set_keymap('n', '', ':wincmd l', { silent = true }) + +vim.api.nvim_set_keymap('n', 'c', ':bd', { silent = true }) + +-- Sniprun +vim.api.nvim_set_keymap('v', 'f', 'SnipRun', { silent = true }) +vim.api.nvim_set_keymap('n', 'f', 'SnipRunOperator', { silent = true }) +vim.api.nvim_set_keymap('n', 'ff', 'SnipRun', { silent = true }) + +-- Highlight yanked +vim.api.nvim_create_autocmd('TextYankPost', { + group = vim.api.nvim_create_augroup('highlight_yank', {}), + desc = 'Hightlight selection on yank', + pattern = '*', + callback = function() + vim.highlight.on_yank { higroup = 'IncSearch', timeout = 200 } + end, +}) + +-- Telescope bindings +local builtin = require('telescope.builtin') +vim.keymap.set('n', 'f', builtin.find_files, {}) +vim.keymap.set('n', 'o', builtin.live_grep, {}) +vim.keymap.set('n', 'b', builtin.buffers, {}) + + +-- Bindings for save and quit +vim.api.nvim_set_keymap('n', 'w', ':w', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'q', ':q', {}) + +-- Neotree bindings +vim.api.nvim_set_keymap('n', 'e', ':RnvimrToggle', { noremap = true, silent = true }) +vim.api.nvim_set_var('rnvimr_enable_ex', 1) +vim.api.nvim_set_var('rnvimr_hidden_filter', "") +vim.api.nvim_set_var('rnvimr_enable_picker', 1) +vim.api.nvim_set_var('rnvimr_edit_cmd', 'drop') +vim.api.nvim_set_var('rnvimr_draw_border', 0) +vim.api.nvim_set_var('rnvimr_hide_gitignore', 0) +vim.api.nvim_set_var('rnvimr_border_attr', {fg = 14, bg = -1}) +vim.api.nvim_set_var('rnvimr_enable_bw', 1) +vim.api.nvim_set_var('rnvimr_shadow_winblend', 70) +vim.api.nvim_set_var('rnvimr_ranger_cmd', {'ranger', '--cmd=set draw_borders both'}) + diff --git a/lua/opt/options.lua b/lua/opt/options.lua new file mode 100644 index 0000000..bb178dc --- /dev/null +++ b/lua/opt/options.lua @@ -0,0 +1,9 @@ +vim.opt.wrap = true +vim.opt.shiftwidth = 4 +vim.opt.tabstop = 4 +vim.o.termguicolors = true +vim.wo.relativenumber = true +vim.wo.number = true +vim.g.mapleader = ' ' +vim.o.cmdheight = 0 + diff --git a/lua/plugin/autoclose.lua b/lua/plugin/autoclose.lua new file mode 100644 index 0000000..82ca4be --- /dev/null +++ b/lua/plugin/autoclose.lua @@ -0,0 +1,7 @@ +require("autoclose").setup({ + keys = { + ["$"] = { escape = true, close = true, pair = "$$", disabled_filetypes = { "haskell", "bash", "php" } }, + ["'"] = { escape = true, close = true, pair = "''", disabled_filetypes = { "markdown" } }, + ["`"] = { escape = true, close = true, pair = "``", disabled_filetypes = { "markdown" } }, + }, +}) diff --git a/lua/plugin/cmp.lua b/lua/plugin/cmp.lua new file mode 100644 index 0000000..ab84d34 --- /dev/null +++ b/lua/plugin/cmp.lua @@ -0,0 +1,34 @@ +local cmp = require('cmp') + +cmp.setup({ + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, + mapping = { + [''] = cmp.mapping.confirm({ select = false }), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.select_prev_item({ behavior = 'select' }), + [''] = cmp.mapping.select_next_item({ behavior = 'select' }), + [''] = cmp.mapping.select_next_item({ behavior = 'select' }), + [''] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item({ behavior = 'insert' }) + else + cmp.complete() + end + end), + [''] = cmp.mapping(function() + if cmp.visible() then + cmp.select_next_item({ behavior = 'insert' }) + else + cmp.complete() + end + end), + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, +}) diff --git a/lua/plugin/dracula.lua b/lua/plugin/dracula.lua new file mode 100644 index 0000000..edb1d95 --- /dev/null +++ b/lua/plugin/dracula.lua @@ -0,0 +1,40 @@ +local dracula = require("dracula") +dracula.setup({ + -- customize dracula color palette + colors = { + bg = "#282A36", + fg = "#F8F8F2", + selection = "#44475A", + comment = "#6272A4", + red = "#FF5555", + orange = "#FFB86C", + yellow = "#F1FA8C", + green = "#50fa7b", + purple = "#BD93F9", + cyan = "#8BE9FD", + pink = "#FF79C6", + bright_red = "#FF6E6E", + bright_green = "#69FF94", + bright_yellow = "#FFFFA5", + bright_blue = "#D6ACFF", + bright_magenta = "#FF92DF", + bright_cyan = "#A4FFFF", + bright_white = "#FFFFFF", + menu = "#21222C", + visual = "#3E4452", + gutter_fg = "#4B5263", + nontext = "#3B4048", + white = "#ABB2BF", + black = "#191A21", + }, + -- show the '~' characters after the end of buffers + show_end_of_buffer = false, -- default false + -- use transparent background + transparent_bg = false, -- default false + -- set custom lualine background color + lualine_bg_color = "#FFFFFF", -- default nil + -- set italic comment + italic_comment = true, -- default false + -- overrides the default highlights with table see `:h synIDattr` + overrides = {}, +}) diff --git a/lua/plugin/fzf_lsp.lua b/lua/plugin/fzf_lsp.lua new file mode 100644 index 0000000..b14cf4a --- /dev/null +++ b/lua/plugin/fzf_lsp.lua @@ -0,0 +1 @@ +require'fzf_lsp'.setup() diff --git a/lua/plugin/lsp_config.lua b/lua/plugin/lsp_config.lua new file mode 100644 index 0000000..20f6de4 --- /dev/null +++ b/lua/plugin/lsp_config.lua @@ -0,0 +1,34 @@ +-- LSP Setup +local lsp_zero = require('lsp-zero') + +lsp_zero.on_attach(function(client, bufnr) + lsp_zero.default_keymaps({ buffer = bufnr }) +end) +require 'lspconfig'.hls.setup {} +require 'lspconfig'.omnisharp.setup { + cmd = { "/home/fw/.nix-profile/bin/dotnet", "/home/fw/.local/share/lvim/mason/packages/omnisharp/libexec/OmniSharp.dll" }, +} +require 'lspconfig'.clojure_lsp.setup {} +require 'lspconfig'.nil_ls.setup {} +require 'lspconfig'.marksman.setup {} +require 'lspconfig'.pylsp.setup {} +require 'lspconfig'.bashls.setup {} +require 'lspconfig'.dockerls.setup {} +require 'lspconfig'.docker_compose_language_service.setup {} +require 'lspconfig'.ansiblels.setup {} +require 'lspconfig'.yamlls.setup {} +require 'lspconfig'.lua_ls.setup { + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } +} +require'lspconfig'.vls.setup{} +require'lspconfig'.volar.setup{ + filetypes = {'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json'} +} +require'lspconfig'.vuels.setup{} +require'lspconfig'.jsonls.setup{} diff --git a/lua/plugin/telescope.lua b/lua/plugin/telescope.lua new file mode 100644 index 0000000..0cdab16 --- /dev/null +++ b/lua/plugin/telescope.lua @@ -0,0 +1,19 @@ +local telescope = require('telescope') + + +telescope.setup { + 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" + -- the default case_mode is "smart_case" + } + }, + pickers = { + find_files = { + hidden = true + } + } +} diff --git a/lua/plugin/treesitter.lua b/lua/plugin/treesitter.lua new file mode 100644 index 0000000..a57997c --- /dev/null +++ b/lua/plugin/treesitter.lua @@ -0,0 +1,34 @@ +require 'nvim-treesitter'.setup() + +local parser_config = require "nvim-treesitter.parsers".get_parser_configs() + +parser_config.csharp = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-c-sharp", -- local path or git repo + files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc + branch = "master", -- default branch in case of git repo if different from master + generate_requires_npm = false, -- if stand-alone parser without npm dependencies + requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c + }, + filetype = "cs", -- if filetype does not match the parser name +} + +require'nvim-treesitter.configs'.setup { + ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "haskell", "python", "bash", "clojure", "nix", "dockerfile", "latex", "csharp", "markdown", "json", "vue", "typescript" }, + sync_install = false, + auto_install = true, + ignore_install = { "javascript" }, + + highlight = { + enable = true, + + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + additional_vim_regex_highlighting = false, + }, +} diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..28efd63 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,102 @@ +return { + { + 'm4xshen/autoclose.nvim', + }, + { + "Mofiqul/dracula.nvim" + }, + { + "BurntSushi/ripgrep", + }, + { + 'kevinhwang91/rnvimr', + }, + { + 'ggandor/leap.nvim', + }, + { + 'gfanto/fzf-lsp.nvim', + }, + { + "folke/which-key.nvim", + }, + { + "folke/neodev.nvim", + }, + { + "mfussenegger/nvim-dap", + }, + { + 'neovim/nvim-lspconfig' + }, + { + 'hrsh7th/cmp-nvim-lsp' + }, + { + 'hrsh7th/nvim-cmp' + }, + { + "folke/neoconf.nvim", + cmd = "Neoconf" + }, + { + "lukas-reineke/indent-blankline.nvim", + main = "ibl", + opts = {} + }, + { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x' + }, + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' + }, + { "junegunn/fzf" }, + { + "L3MON4D3/LuaSnip", + version = "v2.*", + dependencies = { + "rafamadriz/friendly-snippets", + "molleweide/LuaSnip-snippets.nvim", + "saadparwaiz1/cmp_luasnip" + }, + build = "make install_jsregexp" + }, + { + "gbprod/substitute.nvim", + opts = {} + }, + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate" + }, + { + 'nvim-telescope/telescope.nvim', + tag = '0.1.6', + dependencies = { + 'nvim-lua/plenary.nvim' + } + }, + { + "kdheepak/lazygit.nvim", + cmd = { + "LazyGit", + "LazyGitConfig", + "LazyGitCurrentFile", + "LazyGitFilter", + "LazyGitFilterCurrentFile", + }, + dependencies = { + "nvim-lua/plenary.nvim", + }, + keys = { + { "gg", "LazyGit", desc = "LazyGit" } + } + }, + { + 'numToStr/Comment.nvim', + opts = {}, + lazy = false, + }, +}