From 48cebf1f8f6056fae6d2abfa698cb367b6e8c832 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Fri, 29 Oct 2021 16:09:55 +0300 Subject: [PATCH] feat: initial commit --- init.lua | 13 +++++ lua/config/fugitive.lua | 3 ++ lua/options.lua | 0 lua/plugins.lua | 75 +++++++++++++++++++++++++++++ lua/utils/autocmd.lua | 11 +++++ lua/utils/init.lua | 6 +++ lua/utils/map.lua | 8 ++++ lua/utils/opt.lua | 6 +++ plugin/packer-compiled.lua | 98 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 220 insertions(+) create mode 100644 init.lua create mode 100644 lua/config/fugitive.lua create mode 100644 lua/options.lua create mode 100644 lua/plugins.lua create mode 100644 lua/utils/autocmd.lua create mode 100644 lua/utils/init.lua create mode 100644 lua/utils/map.lua create mode 100644 lua/utils/opt.lua create mode 100644 plugin/packer-compiled.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..6ac22b4 --- /dev/null +++ b/init.lua @@ -0,0 +1,13 @@ +local g = vim.g + +-- Allow loading */init.lua files +package.path = "./?/init.lua;"..package.path + +-- Leader/local leader +g.mapleader = [[ ]] +g.maplocalleader = [[,]] + +require("impatient") +require("plugins") + + diff --git a/lua/config/fugitive.lua b/lua/config/fugitive.lua new file mode 100644 index 0000000..da0ce8d --- /dev/null +++ b/lua/config/fugitive.lua @@ -0,0 +1,3 @@ +local map = require 'utils.map' + +map('n', 'gg', ':G', { silent = true }) diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..5b130f3 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,75 @@ +local function usePlugins(use) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + -- Improve startup time when loading lua files. + -- Temporary solution before PR gets merges. https://github.com/neovim/neovim/pull/15436 + use 'lewis6991/impatient.nvim' + + -- Git integration + use { 'tpope/vim-fugitive', config = [[require 'config.fugitive']] } +end + + +-- Register custom commands for plugin manager +vim.cmd [[command! PackerInstall packadd packer.nvim | lua require('plugins').install()]] +vim.cmd [[command! PackerUpdate packadd packer.nvim | lua require('plugins').update()]] +vim.cmd [[command! PackerSync packadd packer.nvim | lua require('plugins').sync()]] +vim.cmd [[command! PackerClean packadd packer.nvim | lua require('plugins').clean()]] +vim.cmd [[command! PackerCompile packadd packer.nvim | lua require('plugins').compile()]] + +-- Run "PackerCompile" whenever this file is updated +vim.cmd [[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerCompile + augroup end +]] + +-- Bootstrap packer.nvim. If packer.nvim is not installed, install it. +local function bootstrap() + local fn = vim.fn + local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' + local packer_bootstrap + if fn.empty(fn.glob(install_path)) > 0 then + return fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + end +end + +local packer = nil +local function init() + -- Perform bootstrap + local packer_bootstrap = bootstrap() + + -- Initialize packer + if packer == nil then + packer = require 'packer' + local util = require 'packer.util' + packer.init { + compile_path = util.join_paths(vim.fn.stdpath('config'), 'plugin', 'packer-compiled.lua'), + disable_commands = true + } + end + + -- Reset plugins if already loaded + packer.reset() + + -- Use plugins + usePlugins(packer.use, packer.use_rocks) + + -- 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 + +local plugins = setmetatable({}, { + __index = function(_, key) + init() + return packer[key] + end, +}) + +return plugins + diff --git a/lua/utils/autocmd.lua b/lua/utils/autocmd.lua new file mode 100644 index 0000000..a32be94 --- /dev/null +++ b/lua/utils/autocmd.lua @@ -0,0 +1,11 @@ +local cmd = vim.cmd + +return function(group, cmds, clear) + clear = clear == nil and false or clear + if type(cmds) == 'string' then cmds = {cmds} end + cmd('augroup ' .. group) + if clear then cmd [[au!]] end + for _, c in ipairs(cmds) do cmd('autocmd ' .. c) end + cmd [[augroup END]] +end + diff --git a/lua/utils/init.lua b/lua/utils/init.lua new file mode 100644 index 0000000..37589ac --- /dev/null +++ b/lua/utils/init.lua @@ -0,0 +1,6 @@ +local path = ... +return { + map = require(... .. ".map"), + opt = require(... .. ".opt"), + autocmd = require(... .. ".autocmd"), +} diff --git a/lua/utils/map.lua b/lua/utils/map.lua new file mode 100644 index 0000000..479c92d --- /dev/null +++ b/lua/utils/map.lua @@ -0,0 +1,8 @@ +local map_key = vim.api.nvim_set_keymap + +return function(modes, lhs, rhs, opts) + opts = opts or {} + opts.noremap = opts.noremap == nil and true or opts.noremap + if type(modes) == 'string' then modes = {modes} end + for _, mode in ipairs(modes) do map_key(mode, lhs, rhs, opts) end +end diff --git a/lua/utils/opt.lua b/lua/utils/opt.lua new file mode 100644 index 0000000..9ae1aba --- /dev/null +++ b/lua/utils/opt.lua @@ -0,0 +1,6 @@ +local o_s = vim.o + +return function(o, v, scopes) + scopes = scopes or {o_s} + for _, s in ipairs(scopes) do s[o] = v end +end diff --git a/plugin/packer-compiled.lua b/plugin/packer-compiled.lua new file mode 100644 index 0000000..cb4d4c8 --- /dev/null +++ b/plugin/packer-compiled.lua @@ -0,0 +1,98 @@ +-- 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() + + 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 + + _G._packer = _G._packer or {} + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "/home/puzonas/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/home/puzonas/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/home/puzonas/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/home/puzonas/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/puzonas/.cache/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)) + 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 = { + ["impatient.nvim"] = { + loaded = true, + path = "/home/puzonas/.local/share/nvim/site/pack/packer/start/impatient.nvim" + }, + ["packer.nvim"] = { + loaded = true, + path = "/home/puzonas/.local/share/nvim/site/pack/packer/start/packer.nvim" + }, + ["vim-fugitive"] = { + config = { "require 'config.fugitive'" }, + loaded = true, + path = "/home/puzonas/.local/share/nvim/site/pack/packer/start/vim-fugitive" + } +} + +time([[Defining packer_plugins]], false) +-- Config for: vim-fugitive +time([[Config for vim-fugitive]], true) +require 'config.fugitive' +time([[Config for vim-fugitive]], false) +if should_profile then save_profiles() end + +end) + +if not no_errors then + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end