diff options
| author | Aleksa Vučković <aleksav013@gmail.com> | 2022-01-04 22:21:17 +0100 |
|---|---|---|
| committer | Aleksa Vučković <aleksav013@gmail.com> | 2022-01-04 22:21:17 +0100 |
| commit | 0eb2af20164f3281b9981386d7ac03713e2f3e01 (patch) | |
| tree | 6b2a0fd12382987b4265ac178b26ea5386e67759 | |
| parent | e1b0a35e04546333634c3ceb6ed84cb21ef90c38 (diff) | |
New begining
| -rw-r--r-- | init.lua | 11 | ||||
| -rw-r--r-- | lua/keymaps.lua | 68 | ||||
| -rw-r--r-- | lua/lsp/init.lua | 68 | ||||
| -rw-r--r-- | lua/mappings.lua | 35 | ||||
| -rw-r--r-- | lua/options.lua | 49 | ||||
| -rw-r--r-- | lua/plugins.lua | 63 | ||||
| -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 |
10 files changed, 168 insertions, 227 deletions
@@ -1,11 +1,4 @@ -require "settings" -require "mappings" +require "options" +require "keymaps" require "plugins" - --- Plugins -require "plugins.compe" -require "plugins.autopairs" -require "plugins.bufferline" - --- LSP require "lsp" 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("", "<Space>", "<Nop>", 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", "<C-h>", "<C-w>h", opts) +keymap("n", "<C-j>", "<C-w>j", opts) +keymap("n", "<C-k>", "<C-w>k", opts) +keymap("n", "<C-l>", "<C-w>l", opts) + +-- Resize with arrows +keymap("n", "<C-Up>", ":resize -2<CR>", opts) +keymap("n", "<C-Down>", ":resize +2<CR>", opts) +keymap("n", "<C-Left>", ":vertical resize -2<CR>", opts) +keymap("n", "<C-Right>", ":vertical resize +2<CR>", opts) + +-- Navigate buffers +keymap("n", "<S-l>", ":bnext<CR>", opts) +keymap("n", "<S-h>", ":bprevious<CR>", opts) + +-- Move text up and down +keymap("n", "<A-j>", "<Esc>:m .+1<CR>==gi", opts) +keymap("n", "<A-k>", "<Esc>:m .-2<CR>==gi", opts) + +-- Insert -- +-- Press jk fast to enter +-- keymap("i", "jk", "<ESC>", opts) + +-- Visual -- +-- Stay in indent mode +keymap("v", "<", "<gv", opts) +keymap("v", ">", ">gv", opts) + +-- Move text up and down +keymap("v", "<A-j>", ":m .+1<CR>==", opts) +keymap("v", "<A-k>", ":m .-2<CR>==", opts) +keymap("v", "p", '"_dP', opts) + +-- Visual Block -- +-- Move text up and down +keymap("x", "J", ":move '>+1<CR>gv-gv", opts) +keymap("x", "K", ":move '<-2<CR>gv-gv", opts) +keymap("x", "<A-j>", ":move '>+1<CR>gv-gv", opts) +keymap("x", "<A-k>", ":move '<-2<CR>gv-gv", opts) + +-- Terminal -- +-- Better terminal navigation +-- keymap("t", "<C-h>", "<C-\\><C-N><C-w>h", term_opts) +-- keymap("t", "<C-j>", "<C-\\><C-N><C-w>j", term_opts) +-- keymap("t", "<C-k>", "<C-\\><C-N><C-w>k", term_opts) +-- keymap("t", "<C-l>", "<C-\\><C-N><C-w>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 <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 deleted file mode 100644 index 1b1be6b..0000000 --- a/lua/mappings.lua +++ /dev/null @@ -1,35 +0,0 @@ -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/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 <afile> | 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 <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 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 "<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 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 ]] |
