From 69da6d248476c15db2f69455efe9cb91580cc866 Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Mon, 2 Jan 2023 02:13:33 +1100 Subject: [PATCH] initial neovim config --- README.md | 1 + after/plugin/fugitive.lua | 12 +++ after/plugin/gruvbox.lua | 3 + after/plugin/harpoon.lua | 9 ++ after/plugin/lualine.lua | 15 +++ after/plugin/mason_lsp_config.lua | 38 +++++++ after/plugin/nvim-tree.lua | 7 ++ after/plugin/telescope.lua | 13 +++ after/plugin/undotree.lua | 2 + init.lua | 3 + lua/julz/globals.lua | 21 ++++ lua/julz/init.lua | 6 ++ lua/julz/packer.lua | 48 +++++++++ lua/julz/remap.lua | 50 ++++++++++ lua/julz/set.lua | 32 ++++++ lua/julz/utils.lua | 67 +++++++++++++ plugin/packer_compiled.lua | 159 ++++++++++++++++++++++++++++++ 17 files changed, 486 insertions(+) create mode 100644 README.md create mode 100644 after/plugin/fugitive.lua create mode 100644 after/plugin/gruvbox.lua create mode 100644 after/plugin/harpoon.lua create mode 100644 after/plugin/lualine.lua create mode 100644 after/plugin/mason_lsp_config.lua create mode 100644 after/plugin/nvim-tree.lua create mode 100644 after/plugin/telescope.lua create mode 100644 after/plugin/undotree.lua create mode 100644 init.lua create mode 100644 lua/julz/globals.lua create mode 100644 lua/julz/init.lua create mode 100644 lua/julz/packer.lua create mode 100644 lua/julz/remap.lua create mode 100644 lua/julz/set.lua create mode 100644 lua/julz/utils.lua create mode 100644 plugin/packer_compiled.lua diff --git a/README.md b/README.md new file mode 100644 index 0000000..b1f6518 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +neovim configuration diff --git a/after/plugin/fugitive.lua b/after/plugin/fugitive.lua new file mode 100644 index 0000000..82ca1b9 --- /dev/null +++ b/after/plugin/fugitive.lua @@ -0,0 +1,12 @@ +local keymap = vim.keymap + +vim.keymap.set("n", "gs", vim.cmd.Git) +vim.keymap.set("n", "ga", vim.cmd.Gwrite, { desc = "Git add" }) +vim.keymap.set("n", "gd", vim.cmd.Gdiffsplit) +keymap.set("n", "gpl", "Git pull", { desc = "Git pull"}) +keymap.set("n", "gpu", "15 split | term git push", {desc = "Git push" }) + +-- convert git to Git in command line mode +-- vim.fn['utils#Cabbrev']('git', 'Git') + + diff --git a/after/plugin/gruvbox.lua b/after/plugin/gruvbox.lua new file mode 100644 index 0000000..01812fe --- /dev/null +++ b/after/plugin/gruvbox.lua @@ -0,0 +1,3 @@ +vim.o.termguicolors = true +vim.cmd [[ colorscheme gruvbox ]] + diff --git a/after/plugin/harpoon.lua b/after/plugin/harpoon.lua new file mode 100644 index 0000000..f1940bb --- /dev/null +++ b/after/plugin/harpoon.lua @@ -0,0 +1,9 @@ +local mark = require("harpoon.mark") +local ui = require("harpoon.ui") + +vim.keymap.set("n", "a", mark.add_file) +vim.keymap.set("n", "", ui.toggle_quick_menu) + +vim.keymap.set("n", "", function() ui.nav_file(1) end) +vim.keymap.set("n", "", function() ui.nav_file(2) end) + diff --git a/after/plugin/lualine.lua b/after/plugin/lualine.lua new file mode 100644 index 0000000..72526f3 --- /dev/null +++ b/after/plugin/lualine.lua @@ -0,0 +1,15 @@ +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'gruvbox', + }, + sections = { + lualine_a = { + { + 'filename', + path = 1, + } + } + } +} + diff --git a/after/plugin/mason_lsp_config.lua b/after/plugin/mason_lsp_config.lua new file mode 100644 index 0000000..0bc930b --- /dev/null +++ b/after/plugin/mason_lsp_config.lua @@ -0,0 +1,38 @@ +require("mason").setup() +require("mason-lspconfig").setup({ + ensure_installed = { "sumneko_lua" } +}) + +local on_attach = function(_,_) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, {}) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, {}) + + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {}) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, {}) + vim.keymap.set('n', 'gr', require('telescope.builtin').lsp_references, {}) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, {}) + +end + +require("lspconfig").sumneko_lua.setup({ + on_attach = on_attach, + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + globals = {'vim'}, + }, + telemetry = { + enable = false, + }, + }, + }, +}) + +require("lspconfig").elixirls.setup({ + on_attach = on_attach, + cmd = {"C:/users/sleek/AppData/Roaming/elixir-ls/language_server.bat"}, +}) + diff --git a/after/plugin/nvim-tree.lua b/after/plugin/nvim-tree.lua new file mode 100644 index 0000000..26ba66b --- /dev/null +++ b/after/plugin/nvim-tree.lua @@ -0,0 +1,7 @@ +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +require("nvim-tree").setup() + +vim.keymap.set('n', '', ':NvimTreeFindFileToggle') + diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua new file mode 100644 index 0000000..b5608d3 --- /dev/null +++ b/after/plugin/telescope.lua @@ -0,0 +1,13 @@ + +local builtin = require('telescope.builtin') +vim.keymap.set('n', 'pf', builtin.find_files, {}) +vim.keymap.set('n', '', builtin.oldfiles, {}) +vim.keymap.set('n', '', builtin.git_files, {}) + +vim.keymap.set('n', 'ps', function() + builtin.grep_string({ search = vim.fn.input("Grep > ") }); +end) + +vim.keymap.set('n', 'fh', builtin.help_tags, {}) + + diff --git a/after/plugin/undotree.lua b/after/plugin/undotree.lua new file mode 100644 index 0000000..7e442f2 --- /dev/null +++ b/after/plugin/undotree.lua @@ -0,0 +1,2 @@ +vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..b7fd16b --- /dev/null +++ b/init.lua @@ -0,0 +1,3 @@ +require("julz") +-- print("Hello from init.lua") + diff --git a/lua/julz/globals.lua b/lua/julz/globals.lua new file mode 100644 index 0000000..c6acb52 --- /dev/null +++ b/lua/julz/globals.lua @@ -0,0 +1,21 @@ + +local fn = vim.fn +local utils = require("julz.utils") + +vim.g.is_win = (utils.has("win32") or utils.has("win64")) and true or false +vim.is_linux = (utils.has("unix") and (not utils.has("macunix"))) and true or false +vim.g.is_bsd = (jit.os == "BSD") and true or false + +if vim.g.is_bsd then + print("OS is BSD. nvim version:" .. utils.get_nvim_version()) +end + +if vim.g.is_win then + print("OS is Windows. nvim version:" .. utils.get_nvim_version()) +end + +if vim.g.is_linux then + print("OS is Linux. nvim version:" .. utils.get_nvim_version()) +end + + diff --git a/lua/julz/init.lua b/lua/julz/init.lua new file mode 100644 index 0000000..d20fedd --- /dev/null +++ b/lua/julz/init.lua @@ -0,0 +1,6 @@ +require("julz.globals") +require("julz.remap") +require("julz.set") + +-- print("hello from julz") + diff --git a/lua/julz/packer.lua b/lua/julz/packer.lua new file mode 100644 index 0000000..d492d4c --- /dev/null +++ b/lua/julz/packer.lua @@ -0,0 +1,48 @@ + +-- This file can be loaded by calling `lua require('plugins')` from your init.vim + +-- Only required if you have packer configured as `opt` +vim.cmd [[packadd packer.nvim]] + +return require('packer').startup(function(use) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.0', + -- or , branch = '0.1.x', + requires = { {'nvim-lua/plenary.nvim'} } + } + + -- use({ + -- 'rose-pine/neovim', + -- as = 'rose-pine', + -- config = function() + -- vim.cmd('colorscheme rose-pine') + -- end + -- }) + + use 'ellisonleao/gruvbox.nvim' + use({ + 'nvim-tree/nvim-tree.lua', + }) + use 'nvim-tree/nvim-web-devicons' + use 'nvim-lualine/lualine.nvim' + + --use 'nvim-treesitter/nvim-treesitter' + --use( 'nvim-treesitter/nvim-treesitter', {run = ':TSUpdate'} ) + + use( 'tpope/vim-fugitive') + + use { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "neovim/nvim-lspconfig" + } + + use( 'theprimeagen/harpoon' ) + use( 'mbbill/undotree' ) + + +end) + diff --git a/lua/julz/remap.lua b/lua/julz/remap.lua new file mode 100644 index 0000000..2985bae --- /dev/null +++ b/lua/julz/remap.lua @@ -0,0 +1,50 @@ +vim.g.mapleader = " " +vim.keymap.set("n", "pv", vim.cmd.Ex) + +vim.keymap.set("n", "u", ":Undotreeshow") + +-- Save key strokes (don't require shift to enter command mode) +vim.keymap.set({ "n", "x"}, ";", ":") + +-- Turn word under cursor to upper case +vim.keymap.set("i", "", "viwUea") + +-- Turn the current word into title case +vim.keymap.set("i", "", "b~lea") + + +vim.keymap.set("n", "cd", "lcd %:p:hpwd", {desc = "change cwd"}) + +-- Switch windows +vim.keymap.set("n", "", "h") +vim.keymap.set("n", "", "l") +vim.keymap.set("n", "", "k") +vim.keymap.set("n", "", "j") + +-- Go to start and end of current line quickly (when in insert mode) +vim.keymap.set({"n", "i"}, "", "") +vim.keymap.set({"n","i"}, "", "") + +-- Go to start of command in command-line mode +vim.keymap.set("c", "", "") + +vim.keymap.set("n", "cb", function() + local cnt = 0 + local blink_times = 7 + local timer = vim.loop.new_timer() + + timer:start(0, 100, vim.schedule_wrap(function() + vim.cmd[[ + set cursorcolumn! + set cursorline! + ]] + + if cnt == blink_times then + timer:close() + end + + cnt = cnt + 1 + end)) +end) + + diff --git a/lua/julz/set.lua b/lua/julz/set.lua new file mode 100644 index 0000000..135428b --- /dev/null +++ b/lua/julz/set.lua @@ -0,0 +1,32 @@ +--vim.opt.guicursor = "" + +vim.opt.nu = true +vim.opt.relativenumber = true + +vim.opt.wrap = false + +vim.opt.backspace = '2' +vim.opt.showcmd = true +vim.opt.laststatus = 2 + +-- use spaces for tabs etc +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.shiftround = true +vim.opt.expandtab = true + +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undodir = os.getenv("HOME").. "/.neovim/undodir" +vim.opt.undofile = true + +vim.opt.termguicolors = true + +vim.opt.scrolloff = 8 +vim.opt.signcolumn = "yes" +vim.opt.isfname:append("@-@") + +vim.opt.updatetime = 50 +vim.opt.colorcolumn = "80" + + diff --git a/lua/julz/utils.lua b/lua/julz/utils.lua new file mode 100644 index 0000000..3dbc1d8 --- /dev/null +++ b/lua/julz/utils.lua @@ -0,0 +1,67 @@ +local fn = vim.fn + +local M = {} + +function M.executable(name) + if fn.executable(name) > 0 then + return true + end + return false +end + +--- check whether a feature exists in Nvim +--- @feat: string +--- the feature name, like `nvim-0.7` or `unix`. +--- return: bool +M.has = function(feat) + if fn.has(feat) == 1 then + return true + end + + + return false +end + +--- Create a dir if it does not exist +function M.may_create_dir(dir) + local res = fn.isdirectory(dir) + + if res == 0 then + fn.mkdir(dir, "p") + end +end + +function M.get_nvim_version() + local actual_ver = vim.version() + + local nvim_ver_str = string.format("%d.%d.%d", actual_ver.major, actual_ver.minor, actual_ver.patch) + return nvim_ver_str +end + +--- Generate random integers in the range [Low, High], inclusive, +--- adapted from https://stackoverflow.com/a/12739441/6064933 +--- @low: the lower value for this range +--- @high: the upper value for this range +function M.rand_int(low, high) + -- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933 + math.randomseed(os.time()) + + return math.random(low, high) +end + +--- Select a random element from a sequence/list. +--- @seq: the sequence to choose an element +function M.rand_element(seq) + local idx = M.rand_int(1, #seq) + + return seq[idx] +end + +function M.add_pack(name) + local status, error = pcall(vim.cmd, "packadd " .. name) + + return status +end + +return M + diff --git a/plugin/packer_compiled.lua b/plugin/packer_compiled.lua new file mode 100644 index 0000000..5cbf58a --- /dev/null +++ b/plugin/packer_compiled.lua @@ -0,0 +1,159 @@ +-- Automatically generated packer.nvim plugin loader code + +if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then + vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') + return +end + +vim.api.nvim_command('packadd packer.nvim') + +local no_errors, error_msg = pcall(function() + +_G._packer = _G._packer or {} +_G._packer.inside_compile = true + +local time +local profile_info +local should_profile = false +if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 + end + end +else + time = function(chunk, start) end +end + +local function save_profiles(threshold) + local sorted_times = {} + for chunk_name, time_taken in pairs(profile_info) do + sorted_times[#sorted_times + 1] = {chunk_name, time_taken} + end + table.sort(sorted_times, function(a, b) return a[2] > b[2] end) + local results = {} + for i, elem in ipairs(sorted_times) do + if not threshold or threshold and elem[2] > threshold then + results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' + end + end + if threshold then + table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') + end + + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "C:\\Users\\sleek\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\share\\lua\\5.1\\?.lua;C:\\Users\\sleek\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\share\\lua\\5.1\\?\\init.lua;C:\\Users\\sleek\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\lib\\luarocks\\rocks-5.1\\?.lua;C:\\Users\\sleek\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\lib\\luarocks\\rocks-5.1\\?\\init.lua" +local install_cpath_pattern = "C:\\Users\\sleek\\AppData\\Local\\Temp\\nvim\\packer_hererocks\\2.1.0-beta3\\lib\\lua\\5.1\\?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +time([[Luarocks path setup]], false) +time([[try_loadstring definition]], true) +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) + if not success then + vim.schedule(function() + vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) + end) + end + return result +end + +time([[try_loadstring definition]], false) +time([[Defining packer_plugins]], true) +_G.packer_plugins = { + ["gruvbox.nvim"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\gruvbox.nvim", + url = "https://github.com/ellisonleao/gruvbox.nvim" + }, + harpoon = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\harpoon", + url = "https://github.com/theprimeagen/harpoon" + }, + ["lualine.nvim"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\lualine.nvim", + url = "https://github.com/nvim-lualine/lualine.nvim" + }, + ["mason-lspconfig.nvim"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\mason-lspconfig.nvim", + url = "https://github.com/williamboman/mason-lspconfig.nvim" + }, + ["mason.nvim"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\mason.nvim", + url = "https://github.com/williamboman/mason.nvim" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, + ["nvim-tree.lua"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\nvim-tree.lua", + url = "https://github.com/nvim-tree/nvim-tree.lua" + }, + ["nvim-web-devicons"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\nvim-web-devicons", + url = "https://github.com/nvim-tree/nvim-web-devicons" + }, + ["packer.nvim"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\packer.nvim", + url = "https://github.com/wbthomason/packer.nvim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\plenary.nvim", + url = "https://github.com/nvim-lua/plenary.nvim" + }, + ["telescope.nvim"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\telescope.nvim", + url = "https://github.com/nvim-telescope/telescope.nvim" + }, + undotree = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\undotree", + url = "https://github.com/mbbill/undotree" + }, + ["vim-fugitive"] = { + loaded = true, + path = "C:\\Users\\sleek\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\vim-fugitive", + url = "https://github.com/tpope/vim-fugitive" + } +} + +time([[Defining packer_plugins]], false) + +_G._packer.inside_compile = false +if _G._packer.needs_bufread == true then + vim.cmd("doautocmd BufRead") +end +_G._packer.needs_bufread = false + +if should_profile then save_profiles() end + +end) + +if not no_errors then + error_msg = error_msg:gsub('"', '\\"') + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end