From e1b0a35e04546333634c3ceb6ed84cb21ef90c38 Mon Sep 17 00:00:00 2001 From: Aleksa Vučković Date: Tue, 4 Jan 2022 10:04:47 +0100 Subject: Initial commit --- lua/lsp/init.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++ lua/mappings.lua | 35 +++++++++++++++++++++++ lua/plugins.lua | 21 ++++++++++++++ lua/plugins/autopairs.lua | 7 +++++ lua/plugins/bufferline.lua | 2 ++ lua/plugins/compe.lua | 70 ++++++++++++++++++++++++++++++++++++++++++++++ lua/settings.lua | 22 +++++++++++++++ 7 files changed, 225 insertions(+) create mode 100644 lua/lsp/init.lua create mode 100644 lua/mappings.lua create mode 100644 lua/plugins.lua create mode 100644 lua/plugins/autopairs.lua create mode 100644 lua/plugins/bufferline.lua create mode 100644 lua/plugins/compe.lua create mode 100644 lua/settings.lua (limited to 'lua') diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua new file mode 100644 index 0000000..7b30b6c --- /dev/null +++ b/lua/lsp/init.lua @@ -0,0 +1,68 @@ +local nvim_lsp = require('lspconfig') + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + --Enable completion triggered by + 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) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + +end + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { "bashls", "texlab", "html", "cssls" } +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + } + } +end + + +local lspconfig = require'lspconfig' +lspconfig.ccls.setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + }; + init_options = { + compilationDatabaseDirectory = "build"; + cache = { + directory = "/tmp/ccls-cache"; + }; + index = { + threads = 0; + }; + clang = { + excludeArgs = { "-frounding-math"}; + extraArgs = { "--sysroot=/home/aleksa/mygit/mykernel/sysroot", "--gcc-toolchain=/usr/bin/i686-elf-gcc", "-ffreestanding", "-nobuiltininc"}; + }; + } +} diff --git a/lua/mappings.lua b/lua/mappings.lua new file mode 100644 index 0000000..1b1be6b --- /dev/null +++ b/lua/mappings.lua @@ -0,0 +1,35 @@ +vim.api.nvim_set_keymap('n', '', '', { noremap = true, silent = true}) +vim.api.nvim_set_keymap('n', '', '', { noremap = true, silent = true}) +vim.g.mapleader = ' ' + +-- no hl +vim.api.nvim_set_keymap('n', 'h', ':set hlsearch!', { noremap = true, silent = true }) + +-- NvimTree + +-- Don't copy the replaced text after pasting in visual mode +vim.api.nvim_set_keymap("v", "p", '"_dP', { noremap = true, silent = true}) + +-- Indenting +vim.api.nvim_set_keymap('v', '<', '', '>gv', { noremap = true, silent = true}) + + +-- nvim-compe +vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", {expr = true}) + + +-- nvim-bufferline +vim.api.nvim_set_keymap("n", "", ":BufferLineCycleNext", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "", ":BufferLineCyclePrev", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "", ":bdelete", { noremap = true; silent= true}) + + +-- nvim-telescope +vim.api.nvim_set_keymap("n", "ff", ":Telescope find_files", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "fg", ":Telescope live_grep", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "fb", ":Telescope buffers", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "fh", ":Telescope help_tags", { noremap = true; silent= true}) diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..8ac9044 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,21 @@ +local execute = vim.api.nvim_command +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', 'https://github.com/wbthomason/packer.nvim', install_path}) + execute 'packadd packer.nvim' +end + + +return require('packer').startup(function(use) + use 'wbthomason/packer.nvim' + use "neovim/nvim-lspconfig" + use "hrsh7th/nvim-compe" + use 'hrsh7th/vim-vsnip' + use 'windwp/nvim-autopairs' + use 'kyazdani42/nvim-web-devicons' + use "kyazdani42/nvim-tree.lua" + use { 'akinsho/nvim-bufferline.lua', requires = 'kyazdani42/nvim-web-devicons'} +end) diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua new file mode 100644 index 0000000..e1aa126 --- /dev/null +++ b/lua/plugins/autopairs.lua @@ -0,0 +1,7 @@ +require('nvim-autopairs').setup{} + +require("nvim-autopairs.completion.compe").setup({ + map_cr = true, -- map on insert mode + map_complete = true, -- it will auto insert `(` after select function or method item + auto_select = false, -- auto select first item +}) diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..a30a561 --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,2 @@ +--vim.opt.termguicolors = true +require("bufferline").setup{} diff --git a/lua/plugins/compe.lua b/lua/plugins/compe.lua new file mode 100644 index 0000000..8700a7a --- /dev/null +++ b/lua/plugins/compe.lua @@ -0,0 +1,70 @@ +vim.o.completeopt = "menuone,noselect" + +require'compe'.setup { + enabled = true; + autocomplete = true; + debug = false; + min_length = 1; + preselect = 'enable'; + throttle_time = 80; + source_timeout = 200; + resolve_timeout = 800; + incomplete_delay = 400; + max_abbr_width = 100; + max_kind_width = 100; + max_menu_width = 100; + documentation = { + border = { '', '' ,'', ' ', '', '', '', ' ' }, -- the border option is the same as `|help nvim_open_win|` + winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", + max_width = 120, + min_width = 60, + max_height = math.floor(vim.o.lines * 0.3), + min_height = 1, + }; + + source = { + path = true; + buffer = true; + calc = true; + nvim_lsp = true; + nvim_lua = true; + vsnip = true; + ultisnips = true; + luasnip = true; + }; +} + + +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local check_back_space = function() + local col = vim.fn.col('.') - 1 + return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil +end + +-- Use (s-)tab to: +--- move to prev/next item in completion menuone +--- jump to prev/next snippet's placeholder +_G.tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "" + elseif vim.fn['vsnip#available'](1) == 1 then + return t "(vsnip-expand-or-jump)" + elseif check_back_space() then + return t "" + else + return vim.fn['compe#complete']() + end +end +_G.s_tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "" + elseif vim.fn['vsnip#jumpable'](-1) == 1 then + return t "(vsnip-jump-prev)" + else + -- If is not working in your terminal, change it to + return t "" + end +end diff --git a/lua/settings.lua b/lua/settings.lua new file mode 100644 index 0000000..df21e3d --- /dev/null +++ b/lua/settings.lua @@ -0,0 +1,22 @@ +vim.opt.fileencoding = "utf-8" +vim.opt.wrap = false +vim.opt.cmdheight = 1 +-- vim.opt.mouse = "a" +vim.opt.cursorline = true +vim.opt.splitbelow = true +vim.opt.splitright = true +vim.opt.showtabline = 2 +vim.opt.shiftwidth = 4 +vim.opt.smartindent = true +vim.opt.relativenumber = true +vim.opt.number = true +vim.opt.signcolumn = "yes" +vim.opt.updatetime = 300 +vim.opt.timeoutlen = 1000 +vim.opt.undofile = true +vim.opt.clipboard = "unnamedplus" +-- vim.opt.termguicolors = true +vim.opt.shortmess:append("sI") + +-- Open a file from its last left off position +vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]] -- cgit v1.2.3