diff options
| author | Aleksa Vučković <aleksav013@gmail.com> | 2022-01-04 10:04:47 +0100 |
|---|---|---|
| committer | Aleksa Vučković <aleksav013@gmail.com> | 2022-01-04 10:04:47 +0100 |
| commit | e1b0a35e04546333634c3ceb6ed84cb21ef90c38 (patch) | |
| tree | 573ddfa23750192cbc95ac0f7eeaea262ecca14c | |
| parent | 0a1fd3601928a82135822829641a109cb5948a8c (diff) | |
Initial commit
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | init.lua | 11 | ||||
| -rw-r--r-- | lua/lsp/init.lua | 68 | ||||
| -rw-r--r-- | lua/mappings.lua | 35 | ||||
| -rw-r--r-- | lua/plugins.lua | 21 | ||||
| -rw-r--r-- | lua/plugins/autopairs.lua | 7 | ||||
| -rw-r--r-- | lua/plugins/bufferline.lua | 2 | ||||
| -rw-r--r-- | lua/plugins/compe.lua | 70 | ||||
| -rw-r--r-- | lua/settings.lua | 22 | ||||
| -rwxr-xr-x | sync.sh | 7 |
10 files changed, 244 insertions, 1 deletions
@@ -1,2 +1,2 @@ # nvim -my neovim dotfiles +My neovim dotfiles diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..b33a17f --- /dev/null +++ b/init.lua @@ -0,0 +1,11 @@ +require "settings" +require "mappings" +require "plugins" + +-- Plugins +require "plugins.compe" +require "plugins.autopairs" +require "plugins.bufferline" + +-- LSP +require "lsp" 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 <c-x><c-o> + 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', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) + buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) + buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) + buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) + buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) + buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) + buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) + buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) + buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) + buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) + buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) + buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) + buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) + buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) + buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) + buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) + buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', 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', '<Space>', '<NOP>', { noremap = true, silent = true}) +vim.api.nvim_set_keymap('n', '<Backspace>', '<NOP>', { noremap = true, silent = true}) +vim.g.mapleader = ' ' + +-- no hl +vim.api.nvim_set_keymap('n', '<Leader>h', ':set hlsearch!<CR>', { 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}) +vim.api.nvim_set_keymap('v', '>', '>gv', { noremap = true, silent = true}) + + +-- nvim-compe +vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true}) + + +-- nvim-bufferline +vim.api.nvim_set_keymap("n", "<TAB>", ":BufferLineCycleNext<CR>", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "<S-TAB>", ":BufferLineCyclePrev<CR>", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "<C-x>", ":bdelete<CR>", { noremap = true; silent= true}) + + +-- nvim-telescope +vim.api.nvim_set_keymap("n", "<Leader>ff", ":Telescope find_files<CR>", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "<Leader>fg", ":Telescope live_grep<CR>", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "<Leader>fb", ":Telescope buffers<CR>", { noremap = true; silent= true}) +vim.api.nvim_set_keymap("n", "<Leader>fh", ":Telescope help_tags<CR>", { 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 <CR> 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 "<C-n>" + elseif vim.fn['vsnip#available'](1) == 1 then + return t "<Plug>(vsnip-expand-or-jump)" + elseif check_back_space() then + return t "<Tab>" + else + return vim.fn['compe#complete']() + end +end +_G.s_tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "<C-p>" + elseif vim.fn['vsnip#jumpable'](-1) == 1 then + return t "<Plug>(vsnip-jump-prev)" + else + -- If <S-Tab> is not working in your terminal, change it to <C-h> + return t "<S-Tab>" + 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 ]] @@ -0,0 +1,7 @@ +#!/bin/bash + +NVIM_DIR=~/.config/nvim + +rm -r $NVIM_DIR +mkdir -p $NVIM_DIR +stow --no-folding --ignore="LICENCE|README.md|sync.sh" -t $NVIM_DIR . |
