From 0f08d04698c814955116b6bae50752e64b774d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Thu, 23 Dec 2021 18:28:03 +0000 Subject: Thu Dec 23 06:28:03 PM UTC 2021 --- .config/nvim/lua/ftplugin/common-markup.lua | 3 + .config/nvim/lua/ftplugin/common-space.lua | 5 + .config/nvim/lua/ftplugin/init.lua | 2 + .config/nvim/lua/keymaps.lua | 24 +++++ .config/nvim/lua/lsp.lua | 17 ++++ .config/nvim/lua/plugins.lua | 145 ++++++++++++++++++++++++++++ .config/nvim/lua/settings.lua | 30 ++++++ .config/nvim/lua/statusline.lua | 54 +++++++++++ .config/nvim/lua/utils.lua | 46 +++++++++ 9 files changed, 326 insertions(+) create mode 100755 .config/nvim/lua/ftplugin/common-markup.lua create mode 100755 .config/nvim/lua/ftplugin/common-space.lua create mode 100755 .config/nvim/lua/ftplugin/init.lua create mode 100755 .config/nvim/lua/keymaps.lua create mode 100755 .config/nvim/lua/lsp.lua create mode 100755 .config/nvim/lua/plugins.lua create mode 100755 .config/nvim/lua/settings.lua create mode 100755 .config/nvim/lua/statusline.lua create mode 100755 .config/nvim/lua/utils.lua (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/ftplugin/common-markup.lua b/.config/nvim/lua/ftplugin/common-markup.lua new file mode 100755 index 0000000..956a163 --- /dev/null +++ b/.config/nvim/lua/ftplugin/common-markup.lua @@ -0,0 +1,3 @@ +bo.expandtab = true +bo.shiftwidth = 2 +bo.tabstop = 2 diff --git a/.config/nvim/lua/ftplugin/common-space.lua b/.config/nvim/lua/ftplugin/common-space.lua new file mode 100755 index 0000000..ccefb94 --- /dev/null +++ b/.config/nvim/lua/ftplugin/common-space.lua @@ -0,0 +1,5 @@ +bo.tabstop=4 +bo.shiftwidth=4 +bo.textwidth=0 +bo.wrapmargin=0 +bo.expandtab = true diff --git a/.config/nvim/lua/ftplugin/init.lua b/.config/nvim/lua/ftplugin/init.lua new file mode 100755 index 0000000..906b7a1 --- /dev/null +++ b/.config/nvim/lua/ftplugin/init.lua @@ -0,0 +1,2 @@ +package.path = package.path .. ';' .. vim.fn.stdpath('config') .. '/ftplugin/?.lua' +package.path = package.path .. ';' .. vim.fn.stdpath('config') .. '/after/ftplugin/?.lua' diff --git a/.config/nvim/lua/keymaps.lua b/.config/nvim/lua/keymaps.lua new file mode 100755 index 0000000..070ddc9 --- /dev/null +++ b/.config/nvim/lua/keymaps.lua @@ -0,0 +1,24 @@ +--[[ +-- Keymaps +--]] + +local map = vim.api.nvim_set_keymap +local cmd = vim.cmd + +options = {noremap=true} + +map('i', '', '', options) +map('i', '', '', options) +map('i', '', '', options) +map('i', '', '', options) +map('i', '', '', options) + +map('', '', ':NvimTreeToggle', options) + +--[[ +map('n', '', '', 'compe#complete()', options) +map('n', '', '', 'compe#confirm(\'\'', options) +map('n', '', '', 'compe#close(\'\'', options) +map('n', '', '', 'compe#scroll({\'delta\': +4}', options) +map('n', '', '', 'compe#scroll({\'delta\': -4}', options) +--]] diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua new file mode 100755 index 0000000..95d9409 --- /dev/null +++ b/.config/nvim/lua/lsp.lua @@ -0,0 +1,17 @@ +--[[ +-- lsp +--]] + +local lsp = vim.lsp + +lsp.handlers["textDocument/publishDiagnostics"] = lsp.with( + lsp.diagnostic.on_publish_diagnostics, + { + underline = false, + virtual_text = { + prefix = "▒ ", + spacing = 8, + }, + signs = true, + } +) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua new file mode 100755 index 0000000..24736eb --- /dev/null +++ b/.config/nvim/lua/plugins.lua @@ -0,0 +1,145 @@ +--[[ +-- Plugins +--]] + +-- Bootstrap for Paq +local install_path = vim.fn.stdpath('data')..'/site/pack/paqs/start/paq-nvim' +if vim.fn.empty(vim.fn.glob(install_path)) > 0 then + vim.fn.system({ + 'git', 'clone', '--depth=1', + 'https://github.com/savq/paq-nvim.git', + install_path + }) + vim.cmd 'packadd paq-nvim' +end + +-- Enable Paq +vim.cmd 'packadd paq-nvim' + +-- Plugin list +require('paq') { + {'savq/paq-nvim'}; + + -- lsp + { + 'nvim-treesitter/nvim-treesitter', + run=':TSUpdate' + }; + { + 'neovim/nvim-lspconfig', + run='python3 -m pipx install python-lsp-server[all]' + }; + { + 'numirias/semshi', + run=':UpdateRemotePlugins' + }; + + -- utils + {'folke/trouble.nvim'}; + {'hrsh7th/nvim-compe'}; + + -- org + {'TimUntersberger/neogit'}; + {'kyazdani42/nvim-tree.lua'}; + + -- indent + {'lewis6991/gitsigns.nvim'}; + {'glepnir/indent-guides.nvim'}; + {'darazaki/indent-o-matic'}; + + -- dep + {'nvim-lua/plenary.nvim'}; +} + +-- Treesitter + +local parser_configs = require('nvim-treesitter.parsers').get_parser_configs() + +require('nvim-treesitter.configs').setup { + ensure_installed = 'maintained', + ignore_install = { + 'verilog', + 'kotlin' + }, + highlight = { + enable = true, + } +} + +-- completion + +require('compe').setup { + enabled = true, + source = { + path = true; + buffer = true; + calc = true; + nvim_lsp = true; + nvim_lua = true; + vsnip = true; + ultisnips = true; + luasnip = true; + neorg = true; + }; +} + +-- LSP configuration + +local lsputil = require('lspconfig/util') +local python_venv = require('utils').get_python_venv() +require('lspconfig').pylsp.setup{ + cmd = {'pylsp', '-v'}, + cmd_env = { + VIRTUAL_ENV = python_venv, + PATH = lsputil.path.join(python_venv, 'bin') .. ':' .. vim.env.PATH + }, +} + +require('lspconfig').clangd.setup{} +require('lspconfig').eslint.setup{} +require('lspconfig').terraformls.setup{} + +-- org + +require('trouble').setup{} +require('neogit').setup{} + +-- syntactic sugar + +require('indent_guides').setup{ + indent_enable=true; + exclude_filetypes={ + 'help', + 'calendar', + 'NvimTree' + }; +} + +require('indent-o-matic').setup { + max_lines = 0, + standard_widths = { 2, 4, 8 }, + + filetype_typescript = { + max_lines = 4096, + }, + + filetype_javascript = { + max_lines = 4096, + }, + + filetype_ = { + standard_widths = { 2, 4 }, + }, +} + +vim.g['semshi#update_delay_factor'] = 0.0001 + +require('gitsigns').setup{ + signs = { + add = {hl = 'GitSignsAdd' , text = '▍', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'}, + change = {hl = 'GitSignsChange', text = '▍', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, + delete = {hl = 'GitSignsDelete', text = '▍', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, + topdelete = {hl = 'GitSignsDelete', text = '▍', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, + changedelete = {hl = 'GitSignsChange', text = '▍', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, + } +} diff --git a/.config/nvim/lua/settings.lua b/.config/nvim/lua/settings.lua new file mode 100755 index 0000000..2741c99 --- /dev/null +++ b/.config/nvim/lua/settings.lua @@ -0,0 +1,30 @@ +bo.expandtab = false +bo.shiftwidth = 8 +bo.softtabstop = 8 + +o.completeopt = 'longest,menuone' +o.shell = '/bin/sh' +o.encoding = 'utf-8' +o.scrolloff = 3 +o.lazyredraw = true +o.autochdir = true +o.smarttab = true +o.number = true +o.list = true + +o.swapfile = false + +-- o.foldmethod = 'expr' +-- o.foldexpr = 'nvim_treesitter#foldexpr()' + +cmd 'syntax enable' +cmd 'filetype on' +cmd 'filetype plugin on' +cmd 'filetype indent on' +cmd 'colorscheme colorscheme' + +vim.cmd([[ +au BufNewFile,BufRead *.Dockerfile,Dockerfile.* setlocal filetype=dockerfile +au BufNewFile,BufRead *.j2*,*.jinja* setlocal filetype=django +au BufNewFile,BufRead *.env* setlocal filetype=sh +]]) diff --git a/.config/nvim/lua/statusline.lua b/.config/nvim/lua/statusline.lua new file mode 100755 index 0000000..099d930 --- /dev/null +++ b/.config/nvim/lua/statusline.lua @@ -0,0 +1,54 @@ +--[[ +-- Statusline +--]] + +local api = vim.api +local cmd = vim.cmd +local utils = require('utils') + +function _(str) + return '[' .. str .. ']' +end + +function set_split() + return '%m%=' +end + +function get_separator() + return ' ' +end + +function get_file() + return '%f' +end + +function get_fileformat() + return '%{&fileformat}' +end + +function get_fileencoding() + return '%{&fileencoding?&fileencoding:&encoding}' +end + +function get_scrollposition() + return '%p%%' +end + +function get_cursorposition() + return '%l:%c' +end + +function get_statusline() + return table.concat({ + get_file(), + set_split(), + _(get_fileencoding()), + _(get_fileformat()), + _(get_scrollposition()), + _(get_cursorposition()), + }) +end + +-- Enable statusline +utils.opt('o', 'laststatus', 2) +utils.opt('o', 'statusline', get_statusline()) diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua new file mode 100755 index 0000000..ae164e8 --- /dev/null +++ b/.config/nvim/lua/utils.lua @@ -0,0 +1,46 @@ +local utils = {} + +local scopes = {o = vim.o, b = vim.bo, w = vim.wo} + +--- Apply a setting with a specified scope +function utils.opt(scope, key, value) + scopes[scope][key] = value + if scope ~= 'o' then scopes['o'][key] = value end +end + +--- Apply an array of settings +function utils.opts(params) + for i, item in ipairs(params) do + utils.opt(item[1], item[2], item[3]) + end +end + +--- Key mapping +function utils.map(mode, lhs, rhs, opts) + local options = {noremap = true} + if opts then options = vim.tbl_extend('force', options, opts) end + vim.api.nvim_set_keymap(mode, lhs, rhs, options) +end + +function utils.get_python_venv() + local lsputil = require('lspconfig/util') + local match + + if vim.env.VIRTUAL_ENV then + return vim.env.VIRTUAL_ENV + end + + match = vim.fn.glob(lsputil.path.join(vim.fn.getcwd(), 'Pipfile')) + if match ~= '' then + return vim.fn.trim(vim.fn.system('PIPENV_PIPFILE=' .. match .. ' pipenv --venv')) + end + + match = vim.fn.system('test -f poetry.lock && poetry env info -p') + if vim.v.shell_error then + return vim.fn.trim(match) + end + + return '' +end + +return utils -- cgit v1.2.3