commit 3f57c580d161bf0dfd6dbb934d3970401e2105ef Author: Imbus Date: Tue Nov 22 13:39:10 2022 +0100 Initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8cb205e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +plugin diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..bc36953 --- /dev/null +++ b/init.lua @@ -0,0 +1,14 @@ +local packer = require("ensure-packer"); +local plugins = require("plugins"); +local settings = require("settings"); + +-- Theme Section +vim.cmd("colorscheme onedark") + +-- Lualine Section +require('lualine').setup { + options = { theme = 'auto' } +} + +-- Comment +require('Comment').setup() diff --git a/lua/ensure-packer.lua b/lua/ensure-packer.lua new file mode 100644 index 0000000..f07b171 --- /dev/null +++ b/lua/ensure-packer.lua @@ -0,0 +1,19 @@ +local ensure_packer = function() + local fn = vim.fn + local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + vim.cmd [[packadd packer.nvim]] + return true + end + return false +end + +local packer_bootstrap = ensure_packer(); + +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerSync + augroup end +]]) diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..d77c964 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,20 @@ +require('packer').startup(function(use) + use 'wbthomason/packer.nvim' + use 'numToStr/Comment.nvim' + use 'neovim/nvim-lspconfig' + use 'glepnir/dashboard-nvim' + use 'joshdick/onedark.vim' + use 'jiangmiao/auto-pairs' + use { 'nvim-treesitter/nvim-treesitter', run = function() + local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) + ts_update() + end, + } + use { 'nvim-lualine/lualine.nvim', requires = { 'kyazdani42/nvim-web-devicons', opt = true } } + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if packer_bootstrap then + require('packer').sync() + end +end) diff --git a/lua/settings.lua b/lua/settings.lua new file mode 100644 index 0000000..8eb9a79 --- /dev/null +++ b/lua/settings.lua @@ -0,0 +1,72 @@ +local g = vim.g +local o = vim.o + +o.termguicolors = true + +-- Decrease update time +o.timeoutlen = 500 +o.updatetime = 200 + +-- Number of screen lines to keep above and below the cursor +o.scrolloff = 8 + +-- Better editor UI +o.number = true +o.numberwidth = 5 +o.relativenumber = false +o.signcolumn = 'yes:2' +o.cursorline = true + +-- Better editing experience +o.expandtab = true +-- o.smasttab = true +o.cindent = true +-- o.autoindent = true +o.wrap = false +o.textwidth = 300 +o.tabstop = 4 +o.shiftwidth = 0 +o.softtabstop = -1 -- If negative, shiftwidth value is used +o.list = true +o.listchars = 'eol:¬,space:·,lead: ,trail:·,nbsp:◇,tab:→-,extends:▸,precedes:◂,multispace:···⬝,leadmultispace:│ ,' +-- o.formatoptions = 'qrn1' + +-- Makes neovim and host OS clipboard play nicely with each other +o.clipboard = 'unnamedplus' + +-- Case insensitive searching UNLESS /C or capital in search +o.ignorecase = true +o.smartcase = true + +-- Undo and backup options +o.backup = false +o.writebackup = false +o.undofile = true +o.swapfile = false +-- o.backupdir = '/tmp/' +-- o.directory = '/tmp/' +-- o.undodir = '/tmp/' + +-- Remember 50 items in commandline history +o.history = 50 + +-- Better buffer splitting +o.splitright = true +o.splitbelow = true + +-- Preserve view while jumping +o.jumpoptions = 'view' + +-- BUG: this won't update the search count after pressing `n` or `N` +-- When running macros and regexes on a large file, lazy redraw tells neovim/vim not to draw the screen +-- o.lazyredraw = true + +-- Better folds (don't fold by default) +-- o.foldmethod = 'indent' +-- o.foldlevelstart = 99 +-- o.foldnestmax = 3 +-- o.foldminlines = 1 + +-- Map to space +g.mapleader = ' ' +g.maplocalleader = ' ' diff --git a/lua/utils.lua b/lua/utils.lua new file mode 100644 index 0000000..ab1473f --- /dev/null +++ b/lua/utils.lua @@ -0,0 +1,66 @@ +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