From fd947ffd03cd296bed075ee0ac2e785542e95e64 Mon Sep 17 00:00:00 2001 From: zwergius Date: Fri, 12 Jan 2024 17:23:52 +0100 Subject: [PATCH] Adds my basic setup --- auto-mkdir.vim | 11 ++++ init.lua | 85 +++++++++++++++++++++++++++---- lazy-lock.json | 36 +++++++++++++ lua/custom/plugins/autopairs.lua | 15 ++++++ lua/custom/plugins/devicons.lua | 3 ++ lua/custom/plugins/filetree.lua | 26 ++++++++++ lua/custom/plugins/formatting.lua | 38 ++++++++++++++ 7 files changed, 203 insertions(+), 11 deletions(-) create mode 100644 auto-mkdir.vim create mode 100644 lazy-lock.json create mode 100644 lua/custom/plugins/autopairs.lua create mode 100644 lua/custom/plugins/devicons.lua create mode 100644 lua/custom/plugins/filetree.lua create mode 100644 lua/custom/plugins/formatting.lua diff --git a/auto-mkdir.vim b/auto-mkdir.vim new file mode 100644 index 00000000..a7fbf0bb --- /dev/null +++ b/auto-mkdir.vim @@ -0,0 +1,11 @@ +augroup vimrc-auto-mkdir + autocmd! + autocmd BufWritePre * call s:auto_mkdir(expand(':p:h'), v:cmdbang) + function! s:auto_mkdir(dir, force) + if !isdirectory(a:dir) + \ && (a:force + \ || input("'" . a:dir . "' does not exist. Create? [y/N]") =~? '^y\%[es]$') + call mkdir(iconv(a:dir, &encoding, &termencoding), 'p') + endif + endfunction +augroup END diff --git a/init.lua b/init.lua index a7667ddc..bb080877 100644 --- a/init.lua +++ b/init.lua @@ -110,7 +110,7 @@ require('lazy').setup({ }, -- Useful plugin to show you pending keybinds. - { 'folke/which-key.nvim', opts = {} }, + { 'folke/which-key.nvim', opts = {} }, { -- Adds git related signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', @@ -152,10 +152,11 @@ require('lazy').setup({ { -- Theme inspired by Atom - 'navarasu/onedark.nvim', + -- 'navarasu/onedark.nvim', + 'rmehri01/onenord.nvim', priority = 1000, config = function() - vim.cmd.colorscheme 'onedark' + vim.cmd.colorscheme 'onenord' end, }, @@ -166,10 +167,17 @@ require('lazy').setup({ opts = { options = { icons_enabled = false, - theme = 'onedark', + theme = 'onenord', component_separators = '|', section_separators = '', }, + sections = { + lualine_c = { + { + 'filename', path = 4 + } + } + } }, }, @@ -218,8 +226,8 @@ require('lazy').setup({ -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart -- These are some example plugins that I've included in the kickstart repository. -- Uncomment any of the lines below to enable them. - -- require 'kickstart.plugins.autoformat', - -- require 'kickstart.plugins.debug', + require 'kickstart.plugins.autoformat', + require 'kickstart.plugins.debug', -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping @@ -227,15 +235,27 @@ require('lazy').setup({ -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, }, {}) -- [[ Setting options ]] -- See `:help vim.o` -- NOTE: You can change these options as you wish! +-- Line & relative line numbers +vim.opt.number = true +vim.opt.relativenumber = true + +-- Indents +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true +vim.opt.smartindent = true + -- Set highlight on search vim.o.hlsearch = false +vim.opt.incsearch = true -- Make line numbers default vim.wo.number = true @@ -271,12 +291,29 @@ vim.o.completeopt = 'menuone,noselect' -- NOTE: You should make sure your terminal supports this vim.o.termguicolors = true +-- Filetype overrides +vim.filetype.add({ + extension = { + postcss = 'css', + } +}) + -- [[ Basic Keymaps ]] -- Keymaps for better default experience -- See `:help vim.keymap.set()` vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) +-- Easy save with CTRL + s +vim.keymap.set('n', '', ':update', { noremap = true }) +vim.keymap.set({ 'i', 'v' }, '', ':update', { noremap = true }) + +-- Split Movement +vim.keymap.set('n', '', 'h', { noremap = true, silent = true }) +vim.keymap.set('n', '', 'j', { noremap = true, silent = true }) +vim.keymap.set('n', '', 'k', { noremap = true, silent = true }) +vim.keymap.set('n', '', 'l', { noremap = true, silent = true }) + -- Remap for dealing with word wrap vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) @@ -297,9 +334,19 @@ vim.api.nvim_create_autocmd('TextYankPost', { require('telescope').setup { defaults = { mappings = { + -- for input mode i = { [''] = false, [''] = false, + [""] = require('telescope.actions').move_selection_next, + [""] = require('telescope.actions').move_selection_previous, + [""] = require('telescope.actions').cycle_history_next, + [""] = require('telescope.actions').cycle_history_prev, + }, + -- for normal mode + n = { + [""] = require('telescope.actions').move_selection_next, + [""] = require('telescope.actions').move_selection_previous, }, }, }, @@ -333,7 +380,18 @@ vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = vim.defer_fn(function() require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' }, + ensure_installed = { + "bash", + "javascript", + "json", + "lua", + "typescript", + "tsx", + "css", + "rust", + "yaml", + "svelte", + }, -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) auto_install = false, @@ -399,8 +457,8 @@ end, 0) -- Diagnostic keymaps vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) +vim.keymap.set('n', 'do', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) +vim.keymap.set('n', 'dd', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) -- [[ Configure LSP ]] -- This function gets run when an LSP connects to a particular buffer. @@ -478,7 +536,9 @@ local servers = { -- rust_analyzer = {}, -- tsserver = {}, -- html = { filetypes = { 'html', 'twig', 'hbs'} }, - + -- prettierd = { + -- }, + -- lua_ls = { Lua = { workspace = { checkThirdParty = false }, @@ -562,3 +622,6 @@ cmp.setup { -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et + +-- Autocommand create folder(s) for new file +vim.cmd 'source ~/.config/nvim/auto-mkdir.vim' diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 00000000..eb493550 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,36 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "0df29db3543837f8b41597f2640397c5ec792b7b" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "conform.nvim": { "branch": "master", "commit": "2c1e852fbf723b7d89b14fd28089472d92edeeb9" }, + "fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" }, + "friendly-snippets": { "branch": "main", "commit": "43727c2ff84240e55d4069ec3e6158d74cb534b6" }, + "gitsigns.nvim": { "branch": "main", "commit": "ff01d34daaed72f271a8ffa088a7e839a60c640f" }, + "indent-blankline.nvim": { "branch": "master", "commit": "0ac5dfe835ec0f201ef6af17d4737d43b4bfce0d" }, + "lazy.nvim": { "branch": "main", "commit": "ed6c9ffe2174bcfe4c17199ec4535aa4d4be1e62" }, + "lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "e7b64c11035aa924f87385b72145e0ccf68a7e0a" }, + "mason-nvim-dap.nvim": { "branch": "main", "commit": "6148b51db945b55b3b725da39eaea6441e59dff8" }, + "mason.nvim": { "branch": "main", "commit": "cd7835b15f5a4204fc37e0aa739347472121a54c" }, + "neo-tree.nvim": { "branch": "main", "commit": "6f8c49956c89e9fefae6acdfe1d57c6293b0a03d" }, + "neodev.nvim": { "branch": "main", "commit": "24b403eabde652904077f84fd55441744e77a109" }, + "nui.nvim": { "branch": "main", "commit": "c0c8e347ceac53030f5c1ece1c5a5b6a17a25b32" }, + "nvim-autopairs": { "branch": "master", "commit": "f6c71641f6f183427a651c0ce4ba3fb89404fa9e" }, + "nvim-cmp": { "branch": "main", "commit": "5dce1b778b85c717f6614e3f4da45e9f19f54435" }, + "nvim-dap": { "branch": "master", "commit": "92dc531eea2c9a3ef504a5c8ac0decd1fa59a6a3" }, + "nvim-dap-go": { "branch": "main", "commit": "a5cc8dcad43f0732585d4793deb02a25c4afb766" }, + "nvim-dap-ui": { "branch": "master", "commit": "34160a7ce6072ef332f350ae1d4a6a501daf0159" }, + "nvim-lspconfig": { "branch": "master", "commit": "e49b1e90c1781ce372013de3fa93a91ea29fc34a" }, + "nvim-treesitter": { "branch": "master", "commit": "49e71322db582147ce8f4df1853d9dab08da0826" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "78c49ca7d2f7ccba2115c11422c037713c978ad1" }, + "nvim-web-devicons": { "branch": "master", "commit": "3af745113ea537f58c4b1573b64a429fefad9e07" }, + "onenord.nvim": { "branch": "main", "commit": "3679fb93aaf473c1dd63222ac88577a909f6b41c" }, + "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "7011eaae0ac1afe036e30c95cf80200b8dc3f21a" }, + "vim-fugitive": { "branch": "master", "commit": "cbe9dfa162c178946afa689dd3f42d4ea8bf89c1" }, + "vim-rhubarb": { "branch": "master", "commit": "ee69335de176d9325267b0fd2597a22901d927b1" }, + "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }, + "which-key.nvim": { "branch": "main", "commit": "6962dae3565369363b59dd51fb206051555fcb4d" } +} \ No newline at end of file diff --git a/lua/custom/plugins/autopairs.lua b/lua/custom/plugins/autopairs.lua new file mode 100644 index 00000000..d271227f --- /dev/null +++ b/lua/custom/plugins/autopairs.lua @@ -0,0 +1,15 @@ +return { + "windwp/nvim-autopairs", + -- Optional dependency + dependencies = { 'hrsh7th/nvim-cmp' }, + config = function() + require("nvim-autopairs").setup {} + -- If you want to automatically add `(` after selecting a function or method + local cmp_autopairs = require('nvim-autopairs.completion.cmp') + local cmp = require('cmp') + cmp.event:on( + 'confirm_done', + cmp_autopairs.on_confirm_done() + ) + end, +} diff --git a/lua/custom/plugins/devicons.lua b/lua/custom/plugins/devicons.lua new file mode 100644 index 00000000..a439815a --- /dev/null +++ b/lua/custom/plugins/devicons.lua @@ -0,0 +1,3 @@ +return { + "nvim-tree/nvim-web-devicons", lazy = true +} diff --git a/lua/custom/plugins/filetree.lua b/lua/custom/plugins/filetree.lua new file mode 100644 index 00000000..18169c83 --- /dev/null +++ b/lua/custom/plugins/filetree.lua @@ -0,0 +1,26 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + version = "*", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + }, + config = function() + require('neo-tree').setup { + filesystem = { + filtered_items = { + visible = true, + hide_dotfiles = false, + hide_gitignored = true, + hide_by_name = { + -- '.git', + -- '.DS_Store', + -- 'thumbs.db', + } + } + } + } + vim.keymap.set('n', 'e', 'Neotree toggle', { desc = 'Open filetree explorer' }) + end, +} diff --git a/lua/custom/plugins/formatting.lua b/lua/custom/plugins/formatting.lua new file mode 100644 index 00000000..572a3145 --- /dev/null +++ b/lua/custom/plugins/formatting.lua @@ -0,0 +1,38 @@ +return { + "stevearc/conform.nvim", + lazy = true, + event = { "BufReadPre", "BufNewFile" }, -- to disable comment this out + config = function() + local conform = require("conform") + + conform.setup({ + formatters_by_ft = { + css = { { --[[ "prettierd", ]] "prettier" } }, + graphql = { { --[[ "prettierd", ]] "prettier" } }, + html = { { --[[ "prettierd", ]] "prettier" } }, + javascript = { { --[[ "prettierd", ]] "prettier" } }, + javascriptreact = { { --[[ "prettierd", ]] "prettier" } }, + json = { { --[[ "prettierd", ]] "prettier" } }, + less = { { --[[ "prettierd", ]] "prettier" } }, + markdown = { { --[[ "prettierd", ]] "prettier" } }, + scss = { { --[[ "prettierd", ]] "prettier" } }, + svelte = { { --[[ "prettierd", ]] "prettier" } }, + typescript = { { --[[ "prettierd", ]] "prettier" } }, + typescriptreact = { { --[[ "prettierd", ]] "prettier" } }, + yaml = { { --[[ "prettierd", ]] "prettier" } }, + }, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 500 + } + }) + vim.keymap.set({ "n", "v" }, "f", function() + conform.format({ + lsp_fallback = true, + async = false, + timeout_ms = 1000, + }) + end, { desc = "Format file or range (in visual mode)" }) + end +}