From 0eb2af20164f3281b9981386d7ac03713e2f3e01 Mon Sep 17 00:00:00 2001 From: Aleksa Vučković Date: Tue, 4 Jan 2022 22:21:17 +0100 Subject: New begining --- lua/keymaps.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++ lua/lsp/init.lua | 68 -------------------------------------------- lua/mappings.lua | 35 ----------------------- lua/options.lua | 49 ++++++++++++++++++++++++++++++++ lua/plugins.lua | 63 +++++++++++++++++++++++++++++++---------- lua/plugins/autopairs.lua | 7 ----- lua/plugins/bufferline.lua | 2 -- lua/plugins/compe.lua | 70 ---------------------------------------------- lua/settings.lua | 22 --------------- 9 files changed, 166 insertions(+), 218 deletions(-) create mode 100644 lua/keymaps.lua delete mode 100644 lua/mappings.lua create mode 100644 lua/options.lua delete mode 100644 lua/plugins/autopairs.lua delete mode 100644 lua/plugins/bufferline.lua delete mode 100644 lua/plugins/compe.lua delete mode 100644 lua/settings.lua (limited to 'lua') diff --git a/lua/keymaps.lua b/lua/keymaps.lua new file mode 100644 index 0000000..be9bb45 --- /dev/null +++ b/lua/keymaps.lua @@ -0,0 +1,68 @@ +local opts = { noremap = true, silent = true } + +local term_opts = { silent = true } + +-- Shorten function name +local keymap = vim.api.nvim_set_keymap + +--Remap space as leader key +keymap("", "", "", opts) +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- Modes +-- normal_mode = "n", +-- insert_mode = "i", +-- visual_mode = "v", +-- visual_block_mode = "x", +-- term_mode = "t", +-- command_mode = "c", + +-- Normal -- +-- Better window navigation +keymap("n", "", "h", opts) +keymap("n", "", "j", opts) +keymap("n", "", "k", opts) +keymap("n", "", "l", opts) + +-- Resize with arrows +keymap("n", "", ":resize -2", opts) +keymap("n", "", ":resize +2", opts) +keymap("n", "", ":vertical resize -2", opts) +keymap("n", "", ":vertical resize +2", opts) + +-- Navigate buffers +keymap("n", "", ":bnext", opts) +keymap("n", "", ":bprevious", opts) + +-- Move text up and down +keymap("n", "", ":m .+1==gi", opts) +keymap("n", "", ":m .-2==gi", opts) + +-- Insert -- +-- Press jk fast to enter +-- keymap("i", "jk", "", opts) + +-- Visual -- +-- Stay in indent mode +keymap("v", "<", "", ">gv", opts) + +-- Move text up and down +keymap("v", "", ":m .+1==", opts) +keymap("v", "", ":m .-2==", opts) +keymap("v", "p", '"_dP', opts) + +-- Visual Block -- +-- Move text up and down +keymap("x", "J", ":move '>+1gv-gv", opts) +keymap("x", "K", ":move '<-2gv-gv", opts) +keymap("x", "", ":move '>+1gv-gv", opts) +keymap("x", "", ":move '<-2gv-gv", opts) + +-- Terminal -- +-- Better terminal navigation +-- keymap("t", "", "h", term_opts) +-- keymap("t", "", "j", term_opts) +-- keymap("t", "", "k", term_opts) +-- keymap("t", "", "l", term_opts) diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 7b30b6c..e69de29 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,68 +0,0 @@ -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 deleted file mode 100644 index 1b1be6b..0000000 --- a/lua/mappings.lua +++ /dev/null @@ -1,35 +0,0 @@ -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/options.lua b/lua/options.lua new file mode 100644 index 0000000..9ae3141 --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,49 @@ +local options = { + backup = false, -- creates a backup file + clipboard = "unnamedplus", -- allows neovim to access the system clipboard + cmdheight = 2, -- more space in the neovim command line for displaying messages + completeopt = { "menuone", "noselect" }, -- mostly just for cmp + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = "utf-8", -- the encoding written to a fie + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + -- mouse = "a", -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + showtabline = 2, -- always show tabs + smartcase = true, -- smart case + smartindent = true, -- make indenting smarter again + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = false, -- creates a swapfile + -- termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) + undofile = true, -- enable persistent undo + updatetime = 300, -- faster completion (4000ms default) + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = false, -- convert tabs to spaces + shiftwidth = 4, -- the number of spaces inserted for each indentation + tabstop = 4, -- insert 2 spaces for a tab + cursorline = true, -- highlight the current line + number = true, -- set numbered lines + relativenumber = true, -- set relative numbered lines + numberwidth = 4, -- set number column width to 2 {default 4} + signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + wrap = false, -- display lines as one long line + scrolloff = 8, -- is one of my fav + sidescrolloff = 8, + guifont = "monospace:h17", -- the font used in graphical neovim applications +} + +vim.opt.shortmess:append "c" + +for k, v in pairs(options) do + vim.opt[k] = v +end + +-- vim.cmd "set whichwrap+=<,>,[,],h,l" +vim.cmd [[set iskeyword+=-]] +vim.cmd [[set formatoptions-=cro]] -- TODO: this doesn't seem to work + +-- 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 ]] diff --git a/lua/plugins.lua b/lua/plugins.lua index 8ac9044..39d0c8a 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,21 +1,56 @@ -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' + packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) +end + +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerSync + augroup end +]]) + +local status, packer = pcall(require, "packer") +if not status then + return end +packer.init { + display = { + open_fn = function() + return require("packer.util").float { border = "rounded" } + end, + }, +} + +return packer.startup(function(use) +-- Packer + use 'wbthomason/packer.nvim' + +-- cmp + use 'hrsh7th/nvim-cmp' + use 'hrsh7th/cmp-nvim-lsp' + use 'hrsh7th/cmp-buffer' + use 'hrsh7th/cmp-path' + use 'hrsh7th/cmp-cmdline' + +-- snippets + use 'hrsh7th/vim-vsnip' + use 'hrsh7th/cmp-vsnip' +-- +-- LSP + use "neovim/nvim-lspconfig" + use "williamboman/nvim-lsp-installer" + +-- Other + use "kyazdani42/nvim-web-devicons" + use "kyazdani42/nvim-tree.lua" + use "akinsho/bufferline.nvim" -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'} + -- 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) diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua deleted file mode 100644 index e1aa126..0000000 --- a/lua/plugins/autopairs.lua +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index a30a561..0000000 --- a/lua/plugins/bufferline.lua +++ /dev/null @@ -1,2 +0,0 @@ ---vim.opt.termguicolors = true -require("bufferline").setup{} diff --git a/lua/plugins/compe.lua b/lua/plugins/compe.lua deleted file mode 100644 index 8700a7a..0000000 --- a/lua/plugins/compe.lua +++ /dev/null @@ -1,70 +0,0 @@ -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 deleted file mode 100644 index df21e3d..0000000 --- a/lua/settings.lua +++ /dev/null @@ -1,22 +0,0 @@ -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