diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f8f2b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +backup/* diff --git a/Makefile b/Makefile index 60424bc..3173dc2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ -.PHONY: install_config install_packer +.PHONY: backup clean update install_packer -install_config: - @./helpers/install-neovim-config.sh +backup: + @bash ./helpers/config backup + +update: + @bash ./helpers/config update + +clean: backup + @bash ./helpers/config clean install_packer: - @./helpers/install-plugins.sh \ No newline at end of file + @bash ./helpers/nvim-packer diff --git a/helpers/config b/helpers/config new file mode 100755 index 0000000..6bf2d43 --- /dev/null +++ b/helpers/config @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -euo pipefail + +ROOT_DIR="$( cd "$( dirname $0 )/.." && pwd )" +NEOVIM_CONFIG_SOURCE_DIR="${ROOT_DIR}/neovim" +NEOVIM_CONFIG_DESTINATION_DIR="${XDG_CONFIG_HOME}/nvim" + +action="$1" + +function backup { + if [ -d "${NEOVIM_CONFIG_DESTINATION_DIR}" ]; then + echo "INFO: backing up existing config..." + timestamp=$( date +"%Y.%m.%dT%H.%M.%S" ) + backup_dir="${ROOT_DIR}/backup" + mkdir -p ${backup_dir} + cd ${NEOVIM_CONFIG_DESTINATION_DIR} + tar czf "${backup_dir}/neovim-config-${timestamp}.tar.gz" . + fi +} + +function clean { + rm -f ${NEOVIM_CONFIG_DESTINATION_DIR}/init.lua + find ${NEOVIM_CONFIG_DESTINATION_DIR} -maxdepth 1 -mindepth 1 -type d -not -iwholename "*/plugin" | xargs rm -rf +} + +function update { + mkdir -p ${NEOVIM_CONFIG_DESTINATION_DIR} + + # Syncing the neovim configuration files + echo "INFO: syncing ${NEOVIM_CONFIG_SOURCE_DIR} to ${NEOVIM_CONFIG_DESTINATION_DIR}..." + rsync -avh ${NEOVIM_CONFIG_SOURCE_DIR}/ ${NEOVIM_CONFIG_DESTINATION_DIR} + chmod a-rwx,u+rwx ${NEOVIM_CONFIG_DESTINATION_DIR} + + # Ensuring the data directories are present + mkdir -p ${XDG_DATA_HOME}/nvim/{backup,swap,undo,view,spell} + chmod 0700 ${XDG_DATA_HOME}/nvim/{backup,swap,undo,view,spell} +} + +case ${action} in + backup) + backup + ;; + clean) + clean + ;; + update) + update + ;; + *) + echo "ERROR: Unknown action ${action}" + exit 1 + ;; +esac diff --git a/helpers/install-neovim-config.sh b/helpers/install-neovim-config.sh deleted file mode 100755 index aa909f4..0000000 --- a/helpers/install-neovim-config.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -ROOT_DIR="$( cd "$( dirname $0 )/.." && pwd )" -NEOVIM_CONFIG_SOURCE_DIR="${ROOT_DIR}/neovim" -NEOVIM_CONFIG_DESTINATION_DIR="${XDG_CONFIG_HOME}/nvim" - -mkdir -p ${NEOVIM_CONFIG_DESTINATION_DIR} - -# Syncing the neovim configuration files -echo "INFO: syncing ${NEOVIM_CONFIG_SOURCE_DIR} to ${NEOVIM_CONFIG_DESTINATION_DIR}" -rsync -avh ${NEOVIM_CONFIG_SOURCE_DIR}/ ${NEOVIM_CONFIG_DESTINATION_DIR} -chmod a-rwx,u+rwx ${NEOVIM_CONFIG_DESTINATION_DIR} - -# Ensuring the data directories are present -mkdir -p ${XDG_DATA_HOME}/nvim/{backup,swap,undo,view,spell} -chmod 0700 ${XDG_DATA_HOME}/nvim/{backup,swap,undo,view,spell} diff --git a/helpers/install-plugins.sh b/helpers/nvim-packer similarity index 100% rename from helpers/install-plugins.sh rename to helpers/nvim-packer diff --git a/neovim/after/plugin/plugins.lua b/neovim/after/plugin/plugins.lua deleted file mode 100644 index 33842b7..0000000 --- a/neovim/after/plugin/plugins.lua +++ /dev/null @@ -1,8 +0,0 @@ -return require("packer").startup(function(use) - -- Packer can manage itself - use "wbthomason/packer.nvim" - - use "folke/tokyonight.nvim" - use "neovim/nvim-lspconfig" - use { "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" } -end) diff --git a/neovim/after/plugin/statusline.lua b/neovim/after/plugin/statusline.lua deleted file mode 100644 index 3b3f972..0000000 --- a/neovim/after/plugin/statusline.lua +++ /dev/null @@ -1,2 +0,0 @@ -local statusline = require("statusline") -vim.opt.statusline = statusline.output() diff --git a/neovim/init.lua b/neovim/init.lua index a05afd5..0347199 100644 --- a/neovim/init.lua +++ b/neovim/init.lua @@ -1,67 +1,7 @@ -local set = vim.opt -local g = vim.g -local cmd = vim.cmd +require("plugins") +require("options") +require("keybindings") -g.mapleader = "," - --- Backups, Undos and Swaps -set.backup = true -set.writebackup = true -set.backupdir = vim.fn.stdpath("data").."/backup" -set.swapfile = true -set.directory = vim.fn.stdpath("data").."/swap" -set.undofile = true -set.undodir = vim.fn.stdpath("data").."/undo" -set.viewdir = vim.fn.stdpath("data").."/view" -set.spellfile = vim.fn.stdpath("data").."/spell/en.utf-8.add" - --- Searching -set.ignorecase = true -- ignore case when searching. -set.smartcase = true -- override ignorecase when upper case characters are used when searching. -set.incsearch = true -- set incremental searching. - --- Default tabs and spaces -set.expandtab = true -- turn tabs into spaces -set.tabstop = 2 -- number of spaces per tab -set.softtabstop = 2 -- number of spaces per tab while editing -set.shiftwidth = 2 -- specifies the amount of whitespaces to insert/remove using indentation commands in normal mode. - --- File format and encoding -set.fileformat = "unix" -set.encoding = "utf-8" -set.fileencoding = "utf-8" -set.fileencodings = "utf-8" - --- Colour scheme -set.termguicolors = true -set.background = "dark" -g.tokyonight_style = "night" -g.tokyonight_sidebars = {"packer", "terminal"} -cmd "colorscheme tokyonight" - --- UI and UX -set.number = true -- enable line numbers -set.relativenumber = true -- enable releative line numbers -set.lazyredraw = true -- do not redraw screen when executing macros, registers, etc that have not been typed -set.splitright = true -- split vertical windows to the right -set.splitbelow = true -- split horizontal windows below -g.pastetoggle = "" -- Use to toggle paste/nopaste -set.confirm = true -- raise a dialogue to confirm if you wish to save a file before continuing. -set.cmdheight = 2 -- set the height of the command window to 2 lines. -set.modelines = 5 -- the first 5 lines are checked for modelines. -set.cursorline = true -- highlight the line that the cursor is on -set.smartindent = true -- smart autoidenting -set.scrolloff = 5 -set.signcolumn = "number" -set.completeopt = "longest,menuone" - --- Netrw settings -g.netrw_banner = 0 -- disable the banner -g.netrw_liststyle = 3 -- display files and folders in a tree style -g.netrw_browse_split = 2 -- open files in a vertical split by default -g.netrw_altv = 1 -- open split to the right -g.netrw_winsize = 10 -- set the size of the Explorer window -g.netrw_keepdir = 0 -- keep the browsing directory the same as the current directory - ---- Configure Omnifunc to use the LSP client. -set.omnifunc = "v:lua.vim.lsp.omnifunc" +-- load the status line +local statusline = require("statusline") +vim.opt.statusline = statusline.output() diff --git a/neovim/after/plugin/lsp.lua b/neovim/lua/config/lsp.lua similarity index 70% rename from neovim/after/plugin/lsp.lua rename to neovim/lua/config/lsp.lua index a758864..0f452fd 100644 --- a/neovim/after/plugin/lsp.lua +++ b/neovim/lua/config/lsp.lua @@ -1,6 +1,6 @@ local custom_attach = function(client, bufnr) local function buf_set_keymap(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) + vim.api.nvim_buf_set_keymap(bufnr, ...) end local function buf_set_option(...) @@ -57,45 +57,45 @@ require("lspconfig").golangci_lint_ls.setup{} -- Terraform require("lspconfig").terraformls.setup{ on_attach = custom_attach, - cmd = {"terraform-ls", "serve"}, + cmd = {"terraform-ls", "serve"}, filetypes = {"terraform", "hcl", "tf"}, - root_dir = require("lspconfig").util.root_pattern{".terraform", ".git", "main.tf"}, + root_dir = require("lspconfig").util.root_pattern{".terraform", ".git", "main.tf"}, } -- Python require("lspconfig").pylsp.setup{ on_attach = custom_attach, - cmd = { "pylsp" }, + cmd = { "pylsp" }, filetypes = { "python" }, } -- Lua -HOME = vim.fn.expand('$HOME') -local sumneko_root_path = HOME .. "/Git/github.com/sumneko/lua-language-server" +local sumneko_root_path = vim.fn.expand('$HOME') .. "/Git/github.com/sumneko/lua-language-server" local sumneko_binary = sumneko_root_path .. "/bin/Linux/lua-language-server" -require'lspconfig'.sumneko_lua.setup { - cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}, - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - -- Setup your lua path - path = vim.split(package.path, ';') - }, - diagnostics = { - -- Get the language server to recognize the vim and awesome globals - globals = {'vim', 'awesome'} - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - telemetry = { - -- Do not send telemetry data containing a randomized but unique identifier - enable = false, - }, - } +require("lspconfig").sumneko_lua.setup { + on_attach = custom_attach, + cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = vim.split(package.path, ';') + }, + diagnostics = { + -- Get the language server to recognize the vim and awesome globals + globals = {'vim', 'awesome'} + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + -- Do not send telemetry data containing a randomized but unique identifier + enable = false, + }, } + } } diff --git a/neovim/after/plugin/treesitter.lua b/neovim/lua/config/treesitter.lua similarity index 95% rename from neovim/after/plugin/treesitter.lua rename to neovim/lua/config/treesitter.lua index 8f0adf2..e8c2411 100644 --- a/neovim/after/plugin/treesitter.lua +++ b/neovim/lua/config/treesitter.lua @@ -2,6 +2,7 @@ require("nvim-treesitter.configs").setup { ensure_installed = { "bash", "go", + "gomod", "hcl", "json", "lua", diff --git a/neovim/after/plugin/keybindings.lua b/neovim/lua/keybindings.lua similarity index 100% rename from neovim/after/plugin/keybindings.lua rename to neovim/lua/keybindings.lua diff --git a/neovim/lua/options.lua b/neovim/lua/options.lua new file mode 100644 index 0000000..a05afd5 --- /dev/null +++ b/neovim/lua/options.lua @@ -0,0 +1,67 @@ +local set = vim.opt +local g = vim.g +local cmd = vim.cmd + +g.mapleader = "," + +-- Backups, Undos and Swaps +set.backup = true +set.writebackup = true +set.backupdir = vim.fn.stdpath("data").."/backup" +set.swapfile = true +set.directory = vim.fn.stdpath("data").."/swap" +set.undofile = true +set.undodir = vim.fn.stdpath("data").."/undo" +set.viewdir = vim.fn.stdpath("data").."/view" +set.spellfile = vim.fn.stdpath("data").."/spell/en.utf-8.add" + +-- Searching +set.ignorecase = true -- ignore case when searching. +set.smartcase = true -- override ignorecase when upper case characters are used when searching. +set.incsearch = true -- set incremental searching. + +-- Default tabs and spaces +set.expandtab = true -- turn tabs into spaces +set.tabstop = 2 -- number of spaces per tab +set.softtabstop = 2 -- number of spaces per tab while editing +set.shiftwidth = 2 -- specifies the amount of whitespaces to insert/remove using indentation commands in normal mode. + +-- File format and encoding +set.fileformat = "unix" +set.encoding = "utf-8" +set.fileencoding = "utf-8" +set.fileencodings = "utf-8" + +-- Colour scheme +set.termguicolors = true +set.background = "dark" +g.tokyonight_style = "night" +g.tokyonight_sidebars = {"packer", "terminal"} +cmd "colorscheme tokyonight" + +-- UI and UX +set.number = true -- enable line numbers +set.relativenumber = true -- enable releative line numbers +set.lazyredraw = true -- do not redraw screen when executing macros, registers, etc that have not been typed +set.splitright = true -- split vertical windows to the right +set.splitbelow = true -- split horizontal windows below +g.pastetoggle = "" -- Use to toggle paste/nopaste +set.confirm = true -- raise a dialogue to confirm if you wish to save a file before continuing. +set.cmdheight = 2 -- set the height of the command window to 2 lines. +set.modelines = 5 -- the first 5 lines are checked for modelines. +set.cursorline = true -- highlight the line that the cursor is on +set.smartindent = true -- smart autoidenting +set.scrolloff = 5 +set.signcolumn = "number" +set.completeopt = "longest,menuone" + +-- Netrw settings +g.netrw_banner = 0 -- disable the banner +g.netrw_liststyle = 3 -- display files and folders in a tree style +g.netrw_browse_split = 2 -- open files in a vertical split by default +g.netrw_altv = 1 -- open split to the right +g.netrw_winsize = 10 -- set the size of the Explorer window +g.netrw_keepdir = 0 -- keep the browsing directory the same as the current directory + +--- Configure Omnifunc to use the LSP client. +set.omnifunc = "v:lua.vim.lsp.omnifunc" diff --git a/neovim/lua/plugins.lua b/neovim/lua/plugins.lua new file mode 100644 index 0000000..adbed3e --- /dev/null +++ b/neovim/lua/plugins.lua @@ -0,0 +1,17 @@ +return require("packer").startup(function(use) + -- Packer can manage itself + use "wbthomason/packer.nvim" + + use "folke/tokyonight.nvim" + + use { + "neovim/nvim-lspconfig", + config = require("config.lsp"), + } + + use { + "nvim-treesitter/nvim-treesitter", + config = require("config.treesitter"), + run = ":TSUpdate", + } +end)