commit 56cb5b3c25c3a934c0313fcaf1d9e8a4ba36c6f3 Author: Blallo Date: Mon Sep 6 23:34:51 2021 +0200 IT'S ALIVE! diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b55872 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# neovim on archlinux + +Install neovim and some useful packages + +``` +pikaur -Sy neovim-bin python-pynvim python-neovim nodejs-neovim +``` + +Install `packer.nvim`: + +``` +git clone --depth 1 https://github.com/wbthomason/packer.nvim\ + ~/.local/share/nvim/site/pack/packer/start/packer.nvim +``` + +Install language servers: + +``` +pikaur -Sy community/python-lsp-server +``` diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..393616e --- /dev/null +++ b/init.lua @@ -0,0 +1,155 @@ +-- Blallo neovim configuration + +local g = vim.g +local cmd = vim.cmd +local o, wo, bo = vim.o, vim.wo, vim.bo +local utils = require 'config.utils' +local opt = utils.opt +local autocmd = utils.autocmd +local map = utils.map +local let = utils.let +local tilde = os.getenv('HOME') + +-- Copied from https://medium.com/geekculture/neovim-configuration-for-beginners-b2116dbbde84 +opt('compatible', false) +opt('showmatch', true) +opt('ignorecase', true) +opt('hlsearch', true) +opt('incsearch', true) +opt('tabstop', 4) +opt('softtabstop', 4) +opt('expandtab', true) +opt('shiftwidth', 4) +opt('textwidth', 0) +opt('autoindent', true) +opt('number', true) +opt('wildmode', 'longest,list') +opt('cc', '88') +cmd [[filetype plugin indent on]] +opt('smartindent', true, buffer) +cmd [[syntax on]] +opt('clipboard', 'unnamedplus') +cmd [[filetype plugin on]] +opt('cursorline', true) +opt('ttyfast', true) +opt('hidden', true) +opt('termguicolors', true) +opt('autoread', true) +-- opt('mouse', v) +-- opt('mouse', a) +-- opt('spell', true) +-- Configure swap +opt('swapfile', true) +opt('directory', tilde .. '/.cache/nvim/swap') +-- Configure backup +opt('backupdir', tilde .. '/.cache/nvim/backup') +-- Configure undo +opt('undofile', true) +opt('undodir', tilde .. '/.cache/nvim/undo') +opt('undolevels', 1000) +opt('undoreload', 100000) + +-- cmd([[set listchars=tab:›\ ,trail:•,extends:#,nbsp:.•]]) +cmd([[ + set showbreak=↪\ + set listchars=tab:›\ ,eol:↲,nbsp:␣,trail:•,extends:⟩,precedes:⟨ +]]) + +cmd([[ +augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerCompile +augroup end +]]) + +cmd [[command! WhatHighlight :call util#syntax_stack()]] +cmd [[command! PackerInstall packadd packer.nvim | lua require('plugins').install()]] +cmd [[command! PackerUpdate packadd packer.nvim | lua require('plugins').update()]] +cmd [[command! PackerSync packadd packer.nvim | lua require('plugins').sync()]] +cmd [[command! PackerClean packadd packer.nvim | lua require('plugins').clean()]] +cmd [[command! PackerCompile packadd packer.nvim | lua require('plugins').compile()]] + +-- Colortheme + +require('config.theme') + +-- Treesitter configuration + +require('config.treesitter') + + +-- LSP configuration + +require('config.lspconfig') + +-- Keybinds + +let(nil, 'mapleader', ',') +Mapper = require("nvim-mapper") +local map = Mapper.map + +-- - Telescope-related +local opts = {noremap = true, silent = true} +map('n', 'ff', 'Telescope find_files', opts, "Telescope", "find_files", "Find files from current position") +map('n', 'fg', 'Telescope git_files', opts, "Telescope", "git_files", "Find git-tracked files") +map('n', 'fb', 'Telescope buffers', opts, "Telescope", "buffers", "Search in current opened buffers") +map('n', 'fc', 'Telescope grep_string', opts, "Telescope", "grep_string", "Search string from current position") +map('n', 'fr', 'Telescope live_grep', opts, "Telescope", "live_grep", "Search string in real time") +map('n', 'fR', 'Telescope live_grep grep_open_files=true', opts, "Telescope", "live_grep_open_buffers", "Search string in real time (only on the open buffers)") +map('n', 'ft', 'Telescope treesitter', opts, "Telescope", "treesitter", "Explore treesitter") +map('n', 'fC', 'Telescope git_bcommits', opts, "Telescope", "git_bcommits", "Show diff of current buffer") +map('n', 'fh', 'Telescope builtin', opts, "Telescope", "builtin", "Show Telescope builtins") +map('n', 'lr', 'Telescope lsp_references', opts, "Telescope", "lsp_references", "Show references using LSP") +map('n', 'li', 'Telescope lsp_implementations', opts, "Telescope", "lsp_implementations", "Show implementations using LSP") +map('n', 'ld', 'Telescope lsp_definitions', opts, "Telescope", "lsp_definitions", "Show definitions using LSP") +map('n', 'ls', 'Telescope lsp_document_symbols', opts, "Telescope", "lsp_document_symbols", "Show symbols in document using LSP") + +-- Undo tree +map('n', 'u', 'UndotreeToggleUndotreeFocus', {noremap = true}, "UndoTree", "undo_tree_toggle", "Toggle UndoTree browser") + +-- Split maximizer +map('n', 'mm', 'MaximizerToggle', opts, "MaximizerToggle", "maximizer_toggle_n", "Toggle maximal view of current split") +map('v', 'mm', 'MaximizerToggle', opts, "MaximizerToggle", "maximizer_toggle_v", "Toggle maximal view of current split") + +-- Split movement and management +map('n', '', 'l', opts, "Movement", "move_right_n", "Move to the split to the right") +map('v', '', 'l', opts, "Movement", "move_right_v", "Move to the split to the right") +map('i', '', 'l', opts, "Movement", "move_right_i", "Move to the split to the right") + +map('n', '', 'k', opts, "Movement", "move_up_n", "Move to the upper split") +map('v', '', 'k', opts, "Movement", "move_up_v", "Move to the upper split") +map('i', '', 'k', opts, "Movement", "move_up_i", "Move to the upper split") + +map('n', '', 'j', opts, "Movement", "move_down_n", "Move to the lower split") +map('v', '', 'j', opts, "Movement", "move_down_v", "Move to the lower split") +map('i', '', 'j', opts, "Movement", "move_down_i", "Move to the lower split") + +map('n', '', 'h', opts, "Movement", "move_left_n", "Move to the split to the left") +map('v', '', 'h', opts, "Movement", "move_left_v", "Move to the split to the left") +map('i', '', 'h', opts, "Movement", "move_left_i", "Move to the split to the left") + +map('n', '', 'bd', opts, "Management", "full_close_n", "Close current split and associated buffer") +map('v', '', 'bd', opts, "Management", "full_close_v", "Close current split and associated buffer") +map('i', '', 'bd', opts, "Management", "full_close_i", "Close current split and associated buffer") + +map('n', '', 'bnext', {}, "Movement", "go_to_next_buf", "Switch to the next buffer") +map('n', '\\', 'bprev', {}, "Movement", "go_to_prev_buf", "Switch to the previous buffer") + +-- Move selection around +cmd ([[ +nnoremap :m .+1== +nnoremap :m .-2== +inoremap :m .+1==gi +inoremap :m .-2==gi +vnoremap :m '>+1gv=gv +vnoremap :m '<-2gv=gv +]]) +-- map('n', '', 'm .+1==', opts, "MoveText", "move_text_up_n", "") +-- map('n', '', 'm .-2==', opts, "MoveText", "move_text_down_n", "") +-- map('i', '', 'm .+1==gi', opts, "MoveText", "move_text_up_i", "") +-- map('i', '', 'm .-2==gi', opts, "MoveText", "move_text_down_i", "") +-- map('v', '', "m '>+1gv=gv", opts, "MoveText", "move_text_up_v", "") +-- map('v', '', "m '<-2gv=gv", opst, "MoveText", "move_text_down_v", "") + +-- Clean highlight +map('n', '', 'nohlscall clearmatches()', opts, "CleanHighlights", "clear_all", "Clear all highlights and matches") diff --git a/lua/config/lspconfig.lua b/lua/config/lspconfig.lua new file mode 100644 index 0000000..0890acc --- /dev/null +++ b/lua/config/lspconfig.lua @@ -0,0 +1,45 @@ +local nvim_lsp = require('lspconfig') + +local on_attach = function(client, bufrn) + Mapper = require("nvim-mapper") + local function buf_set_keymap(...) Mapper.map_buf(bufrn, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufrn, ...) end + + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings + local opts = { noremap=true, silent=true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts, "LSP", "declaration", "Go to declaration") + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts, "LSP", "definition", "Go to definition") + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts, "LSP", "hover", "Hover") + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts, "LSP", "implementation", "Go to implementation") + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts, "LSP", "signature_help", "Show signature help") + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts, "LSP", "add_workspace_folder", "Add workspace folder") + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts, "LSP", "remove_workspace_folder", "Remove workspace folder") + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts, "LSP", "list_workspace_folders", "List workspace folder") + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts, "LSP", "type_definition", "Show type definition") + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts, "LSP", "rename", "Rename") + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts, "LSP", "code_action", "Show code actions") + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts, "LSP", "references", "Show references") + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts, "LSP", "show_line_diagnostics", "Show line diagnostic") + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts, "LSP", "goto_prev", "Go to previous") + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts, "LSP", "goto_next", "Go to next") + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts, "LSP", "set_loclist", "Set loclist") + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts, "LSP", "formatting", "Format") +end + +-- Launch language servers +local servers = { 'pylsp', 'gopls', 'rls', 'tsserver', 'elixirls', 'dartls', 'denols', 'clangd' } +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + } + } +end + +-- Format on save +vim.cmd [[autocmd BufWritePre lua vim.lsp.buf.formatting_sync()]] diff --git a/lua/config/theme.lua b/lua/config/theme.lua new file mode 100644 index 0000000..3074430 --- /dev/null +++ b/lua/config/theme.lua @@ -0,0 +1,23 @@ +local cmd = vim.cmd +local utils = require 'config.utils' +local let = utils.let + +-- Nortia +-- cmd([[ +-- color nortia-nvim +-- let g:nortia_bat_light_theme=1 +-- let g:nortia_bat_dark_theme=1 +-- ]]) +-- require('nortia.theme').tint_bg(0, 0.05) +-- require('nortia.theme').tint_bg(190, 0.1) +-- require('nortia.theme').tint_fg(190, 0.1) +-- require('nortia.theme').tint(190, 0.1) + + +-- Gruvbox +let('g', 'gruvbox_italic', 1) +let('g', 'gruvbox_transparent_bg', 1) +cmd [[colorscheme gruvbox]] + +-- Airline +let('g', 'airline_powerline_fonts ', 1) diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua new file mode 100644 index 0000000..adc018f --- /dev/null +++ b/lua/config/treesitter.lua @@ -0,0 +1,26 @@ +require('nvim-treesitter.configs').setup { + highlight = { + enable = true, + custom_captures = { + -- Highlight the @foo.bar capture group with the "Identifier" highlight group. + ["foo.bar"] = "Identifier", + }, + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", + node_incremental = "grn", + scope_incremental = "grc", + node_decremental = "grm", + }, + }, + indent = { + enable = true + }, +} diff --git a/lua/config/utils.lua b/lua/config/utils.lua new file mode 100644 index 0000000..df36d8b --- /dev/null +++ b/lua/config/utils.lua @@ -0,0 +1,42 @@ +local cmd = vim.cmd +local o_s = vim.o +local map_key = vim.api.nvim_set_keymap +local set_g = vim.api.nvim_set_var + +local function opt(o, v, scopes) + scopes = scopes or {o_s} + for _, s in ipairs(scopes) do s[o] = v end +end + +local function autocmd(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 + +local function map(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 + +local function let(mode, name, value) + local assignment = 'let ' + if mode == nil then + assignment = assignment .. name .. ' = ' + else + assignment = assignment .. mode .. ':' .. name .. ' = ' + end + if type(value) == 'string' then + assignment = assignment .. '"' .. value .. '"' + else + assignment = assignment .. value + end + cmd(assignment) +end + +return {opt = opt, autocmd = autocmd, map = map, set_g = set_g, let = let} diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..a195ce7 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,76 @@ +local packer = nil +local function init() + if packer == nil then + packer = require 'packer' + packer.init { disable_commands = true } + end + + local use = packer.use + packer.reset() + + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + -- nvim-mapper to explore mappings + use { + "lazytanuki/nvim-mapper", + config = function() require("nvim-mapper").setup{} end, + before = "telescope.nvim" + } + + -- telescope.nvim + use { + 'nvim-telescope/telescope.nvim', + requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}}, + config = function() require("telescope").load_extension("mapper") end + } + + -- Highlight + use { + 'nvim-treesitter/nvim-treesitter', + requires = { + 'nvim-treesitter/nvim-treesitter-refactor', + 'nvim-treesitter/nvim-treesitter-textobjects', + }, + run = ':TSUpdate', + } + + -- Colortheme + use 'rktjmp/lush.nvim' + use 'alaric/nortia.nvim' + use 'morhetz/gruvbox' + use 'vim-airline/vim-airline' + use 'vim-airline/vim-airline-themes' + + -- Coc + use { + 'neoclide/coc.nvim', + branch = 'master', + run = 'yarn install --frozen-lockfile', + } + + -- Wrapping/delimiters + use 'andymass/vim-matchup' + use 'machakann/vim-sandwich' + + -- Undo tree + use 'mbbill/undotree' + + -- LSP stuff + use 'neovim/nvim-lspconfig' + + -- Split maximizer + use 'szw/vim-maximizer' + + -- Auto pair + use 'jiangmiao/auto-pairs' +end + +local plugins = setmetatable({}, { + __index = function(_, key) + init() + return packer[key] + end, +}) + +return plugins diff --git a/plugin/packer_compiled.lua b/plugin/packer_compiled.lua new file mode 100644 index 0000000..9af2c2f --- /dev/null +++ b/plugin/packer_compiled.lua @@ -0,0 +1,167 @@ +-- 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/leo/.cache/nvim/packer_hererocks/2.0.5/share/lua/5.1/?.lua;/home/leo/.cache/nvim/packer_hererocks/2.0.5/share/lua/5.1/?/init.lua;/home/leo/.cache/nvim/packer_hererocks/2.0.5/lib/luarocks/rocks-5.1/?.lua;/home/leo/.cache/nvim/packer_hererocks/2.0.5/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/leo/.cache/nvim/packer_hererocks/2.0.5/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 = { + ["coc.nvim"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/coc.nvim" + }, + gruvbox = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/gruvbox" + }, + ["lush.nvim"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/lush.nvim" + }, + ["nortia.nvim"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/nortia.nvim" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/nvim-lspconfig" + }, + ["nvim-mapper"] = { + config = { "\27LJ\1\2=\0\0\2\0\3\0\a4\0\0\0%\1\1\0>\0\2\0027\0\2\0002\1\0\0>\0\2\1G\0\1\0\nsetup\16nvim-mapper\frequire\0" }, + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/nvim-mapper" + }, + ["nvim-treesitter"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/nvim-treesitter" + }, + ["nvim-treesitter-refactor"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/nvim-treesitter-refactor" + }, + ["nvim-treesitter-textobjects"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/nvim-treesitter-textobjects" + }, + ["packer.nvim"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/packer.nvim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/plenary.nvim" + }, + ["popup.nvim"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/popup.nvim" + }, + ["telescope.nvim"] = { + config = { "\27LJ\1\2K\0\0\2\0\4\0\a4\0\0\0%\1\1\0>\0\2\0027\0\2\0%\1\3\0>\0\2\1G\0\1\0\vmapper\19load_extension\14telescope\frequire\0" }, + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/telescope.nvim" + }, + undotree = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/undotree" + }, + ["vim-airline"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/vim-airline" + }, + ["vim-airline-themes"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/vim-airline-themes" + }, + ["vim-matchup"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/vim-matchup" + }, + ["vim-maximizer"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/vim-maximizer" + }, + ["vim-sandwich"] = { + loaded = true, + path = "/home/leo/.local/share/nvim/site/pack/packer/start/vim-sandwich" + } +} + +time([[Defining packer_plugins]], false) +-- Config for: telescope.nvim +time([[Config for telescope.nvim]], true) +try_loadstring("\27LJ\1\2K\0\0\2\0\4\0\a4\0\0\0%\1\1\0>\0\2\0027\0\2\0%\1\3\0>\0\2\1G\0\1\0\vmapper\19load_extension\14telescope\frequire\0", "config", "telescope.nvim") +time([[Config for telescope.nvim]], false) +-- Config for: nvim-mapper +time([[Config for nvim-mapper]], true) +try_loadstring("\27LJ\1\2=\0\0\2\0\3\0\a4\0\0\0%\1\1\0>\0\2\0027\0\2\0002\1\0\0>\0\2\1G\0\1\0\nsetup\16nvim-mapper\frequire\0", "config", "nvim-mapper") +time([[Config for nvim-mapper]], 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