diff --git a/config/nvim/init.lua b/config/nvim/init.lua new file mode 100644 index 0000000..ce1e156 --- /dev/null +++ b/config/nvim/init.lua @@ -0,0 +1,125 @@ +require("packer").startup(function(use) + use({ "wbthomason/packer.nvim" }) + + -- Colorscheme + use({ "EdenEast/nightfox.nvim" }) + + -- Treesitter + use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate", { + { "p00f/nvim-ts-rainbow" }, + { "JoosepAlviste/nvim-ts-context-commentstring" }, + { "nvim-treesitter/playground" } + }}) + + -- Make commenting code great + use({ "tpope/vim-commentary" }) + + -- File tree + use({ "kyazdani42/nvim-tree.lua", requires = { "kyazdani42/nvim-web-devicons" } }) + + -- Automatically close brackets and quotes + use({ "windwp/nvim-autopairs" }) + + -- Telescope + use({ "nvim-telescope/telescope.nvim", requires = { "nvim-lua/plenary.nvim" } }) + use({ "nvim-telescope/telescope-symbols.nvim" }) + + -- Statusline + use({ "nvim-lualine/lualine.nvim", requires = { "kyazdani42/nvim-web-devicons" } }) + + use({ "iamcco/markdown-preview.nvim", run = "cd app && yarn install" }) + + -- Highlight colors in editor + use({ "norcalli/nvim-colorizer.lua" }) + + -- LSP + use({ "neovim/nvim-lspconfig" }) + use({ "hrsh7th/nvim-cmp" }) + use({ "L3MON4D3/LuaSnip" }) + use({ + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "hrsh7th/cmp-nvim-lua", + "saadparwaiz1/cmp_luasnip" + }) + use({ "ray-x/lsp_signature.nvim" }) + use({ "dense-analysis/ale" }) + + -- Tabs + use({ "romgrk/barbar.nvim" }) +end) + +require("nightfox").load() + +vim.o.tabstop = 2 +vim.o.shiftwidth = 2 +vim.o.expandtab = true +vim.o.autoindent = true +vim.o.number = true +vim.o.relativenumber = true +vim.o.wrap = true +vim.o.swapfile = true +vim.o.encoding = "utf-8" +vim.o.hidden = true +vim.o.writebackup = false +vim.o.cmdheight = 2 +vim.o.updatetime = 300 +vim.o.shortmess = "filnxtToOFc" +vim.o.mouse = "a" +vim.o.cursorline = true +vim.o.clipboard = "unnamedplus" +vim.o.splitright = true +vim.o.splitbelow = true +vim.o.termguicolors = true +vim.o.signcolumn = "yes" + +vim.g.mapleader = " " + +require("lsp") + +vim.cmd("let g:ale_fixers = {'javascript': ['prettier', 'eslint'], 'typescript': ['prettier', 'eslint'], 'python': ['autopep8', 'remove_trailing_lines', 'reorder-python-imports', 'trim_whitespace']}") +vim.cmd("let g:ale_fix_on_save = 1") + +require("nvim-treesitter.configs").setup({ + ensure_installed = "maintained", + highlight = { + enable = true + }, + rainbow = { + enable = true, + extended_mode = true, + disable = { "html" } + }, + context_commentstring = { + enable = true + } +}) + +require("nvim-tree").setup({ + open_on_setup = true, + hijack_cursor = true, + update_cwd = true, + update_focused_file = { enable = true }, + view = { width = 30, side = "left", auto_resize = true }, + filters = { custom = { ".git" } } +}) +vim.g.nvim_tree_add_trailing = 1 +vim.g.nvim_tree_indent_markers = 1 +vim.g.nvim_tree_show_icons = { git = 0, folders = 0, files = 0, folder_arrows = 0 } + +require("telescope").setup({ + defaults = { + sorting_strategy = "ascending", + file_ignore_patterns = { ".git", "node_modules" } + } +}) + +require("nvim-autopairs").setup() + +require("lualine").setup() + +require("colorizer").setup() + +require("remaps") diff --git a/config/nvim/lua/lsp.lua b/config/nvim/lua/lsp.lua new file mode 100644 index 0000000..df4a838 --- /dev/null +++ b/config/nvim/lua/lsp.lua @@ -0,0 +1,150 @@ +local nvim_lsp = require("lspconfig") +local cmp = require("cmp") + +local kind_icons = { + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "ﴯ", Interface = "", + Module = "", + Property = "ﰠ", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "" +} + +cmp.setup({ + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end + }, + mapping = { + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.confirm({ select = true, behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.confirm({ select = true, behavior = cmp.SelectBehavior.Insert }) + }, + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "nvim_lua" } + }, { + { name = "path" }, + { name = "buffer" } + }), + completion = { + completeopt = "menu,menuone,noselect,noinsert" + }, + experimental = { + ghost_text = true + }, + sorting = { + comparators = { + cmp.config.compare.exact, + cmp.config.compare.score, + cmp.config.compare.recently_used, + cmp.config.compare.kind, + cmp.config.compare.offset + } + }, + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + zindex = 999 + }, + formatting = { + format = function(entry, vim_item) + vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) + vim_item.menu = ({ buffer = "[Buffer]", nvim_lsp = "[LSP]", luasnip = "[Snippet]", nvim_lua = "[Lua]", path = "[File]" })[entry.source.name] + return vim_item + end + } +}) + +cmp.setup.cmdline("/", { + sources = { + { name = "buffer" } + } +}) + +cmp.setup.cmdline(":", { + sources = { + { name = "path" }, + { name = "cmdline" } + } +}) + +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + +local on_attach = function(_, bufnr) + require("lsp_signature").on_attach({}, bufnr) +end + +local servers = { "tsserver", "pyright" } + +for _, server in ipairs(servers) do + nvim_lsp[server].setup({ + capabilities = capabilities, + on_attach = on_attach, + flags = { + debounce_text_changes = 150 + } + }) +end + +nvim_lsp.gopls.setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { + gopls = { + } + } +}) + +local runtime_path = vim.split(package.path, ';') +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") +nvim_lsp.sumneko_lua.setup({ + capabilities = capabilities, + on_attach = on_attach, + cmd = { "/sbin/lua-language-server", "-E", "/usr/lib/lua-language-server/main.lua" }, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + path = runtime_path + }, + diagnostics = { + globals = { "vim" } + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true) + }, + telemetry = { + enable = false + } + } + } +}) + +require("luasnip/loaders/from_vscode").lazy_load() + +-- Auto formatting +vim.cmd([[autocmd BufWritePre * lua vim.lsp.buf.formatting_sync(nil, 1000)]]) +vim.cmd([[autocmd BufWritePre *.ts,*.js,*.jsx,*.tsx,*.py ALEFix]]) diff --git a/config/nvim/lua/remaps.lua b/config/nvim/lua/remaps.lua new file mode 100644 index 0000000..3939164 --- /dev/null +++ b/config/nvim/lua/remaps.lua @@ -0,0 +1,68 @@ +local function map(mode, shortcut, command) + vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true }) +end + +local function nmap(shortcut, command) + map("n", shortcut, command) +end + +local function vmap(shortcut, command) + map("v", shortcut, command) +end + +-- Quickly save/quit vim +nmap("w", ":w") +nmap("q", ":q") + +-- Move line under the cursor up and down +nmap("", ":m .-2==") +nmap("", ":m .+1==") +vmap("K", ":m '<-2gv=gv") +vmap("J", ":m '>+1gv=gv") + +-- Remove search highlighting +nmap("nh", ":nohl") + +-- Escape from terminal +map("t", "", "") + +-- Open splits +nmap("sv", ":vs") +nmap("sh", ":sp") + +-- Move focus between splits +nmap("h", "h") +nmap("j", "j") +nmap("k", "k") +nmap("l", "l") + +-- Resize splits +nmap("", ":resize -2") +nmap("", ":resize +2") +nmap("", ":vert resize -10") +nmap("", ":vert resize +10") + +-- File Tree +nmap("b", ":NvimTreeToggle") + +-- Telescope +nmap("p", ":Telescope") +nmap("f", ":Telescope find_files") + +-- LSP +nmap("K", ":lua vim.lsp.buf.hover()") +nmap("gd", ":lua vim.lsp.buf.definition()") +nmap("gr", ":lua vim.lsp.buf.references()") +nmap(".", ":lua vim.lsp.buf.code_action()") + +-- Tabs +nmap("1", ":BufferGoto 1") +nmap("2", ":BufferGoto 2") +nmap("3", ":BufferGoto 3") +nmap("4", ":BufferGoto 4") +nmap("5", ":BufferGoto 5") +nmap("6", ":BufferGoto 6") +nmap("7", ":BufferGoto 7") +nmap("8", ":BufferGoto 8") +nmap("9", ":BufferGoto 9") +nmap("e", ":BufferClose")