nvim_config/init.lua

164 lines
7.2 KiB
Lua
Raw Normal View History

2021-09-06 23:34:51 +02:00
-- Blallo neovim configuration
local g = vim.g
local cmd = vim.cmd
local o, wo, bo = vim.o, vim.wo, vim.bo
local utils = require 'config.utils'
local opt = utils.opt
local autocmd = utils.autocmd
local map = utils.map
local let = utils.let
local tilde = os.getenv('HOME')
-- Copied from https://medium.com/geekculture/neovim-configuration-for-beginners-b2116dbbde84
opt('compatible', false)
opt('showmatch', true)
opt('ignorecase', true)
opt('hlsearch', true)
opt('incsearch', true)
opt('tabstop', 4)
opt('softtabstop', 4)
opt('expandtab', true)
opt('shiftwidth', 4)
opt('textwidth', 0)
opt('autoindent', true)
opt('number', true)
opt('wildmode', 'longest,list')
opt('cc', '88')
cmd [[filetype plugin indent on]]
opt('smartindent', true, buffer)
cmd [[syntax on]]
opt('clipboard', 'unnamedplus')
cmd [[filetype plugin on]]
opt('cursorline', true)
opt('ttyfast', true)
opt('hidden', true)
opt('termguicolors', true)
opt('autoread', true)
-- opt('mouse', v)
-- opt('mouse', a)
-- opt('spell', true)
-- Configure swap
opt('swapfile', true)
opt('directory', tilde .. '/.cache/nvim/swap')
-- Configure backup
opt('backupdir', tilde .. '/.cache/nvim/backup')
-- Configure undo
opt('undofile', true)
opt('undodir', tilde .. '/.cache/nvim/undo')
opt('undolevels', 1000)
opt('undoreload', 100000)
-- cmd([[set listchars=tab:\ ,trail:•,extends:#,nbsp:.•]])
2021-10-23 00:41:31 +02:00
-- set showbreak=↪\
2021-09-06 23:34:51 +02:00
cmd([[
2021-10-23 00:41:31 +02:00
set listchars=tab:\ ,nbsp:,trail:,extends:,precedes:
set list
2021-09-06 23:34:51 +02:00
]])
cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerCompile
augroup end
]])
2021-11-19 23:40:37 +01:00
-- Reopen file to last cursor position, if possible
cmd([[
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
endif
]])
2021-09-06 23:34:51 +02:00
cmd [[command! WhatHighlight :call util#syntax_stack()]]
cmd [[command! PackerInstall packadd packer.nvim | lua require('plugins').install()]]
cmd [[command! PackerUpdate packadd packer.nvim | lua require('plugins').update()]]
cmd [[command! PackerSync packadd packer.nvim | lua require('plugins').sync()]]
cmd [[command! PackerClean packadd packer.nvim | lua require('plugins').clean()]]
cmd [[command! PackerCompile packadd packer.nvim | lua require('plugins').compile()]]
-- Colortheme
require('config.theme')
-- Treesitter configuration
require('config.treesitter')
-- LSP configuration
require('config.lspconfig')
-- Keybinds
let(nil, 'mapleader', ',')
Mapper = require("nvim-mapper")
local map = Mapper.map
-- - Telescope-related
local opts = {noremap = true, silent = true}
map('n', '<Leader>ff', '<cmd>Telescope find_files<cr>', opts, "Telescope", "find_files", "Find files from current position")
map('n', '<Leader>fg', '<cmd>Telescope git_files<cr>', opts, "Telescope", "git_files", "Find git-tracked files")
map('n', '<Leader>fb', '<cmd>Telescope buffers<cr>', opts, "Telescope", "buffers", "Search in current opened buffers")
map('n', '<Leader>fc', '<cmd>Telescope grep_string<cr>', opts, "Telescope", "grep_string", "Search string from current position")
map('n', '<Leader>fr', '<cmd>Telescope live_grep<cr>', opts, "Telescope", "live_grep", "Search string in real time")
map('n', '<Leader>fR', '<cmd>Telescope live_grep grep_open_files=true<cr>', opts, "Telescope", "live_grep_open_buffers", "Search string in real time (only on the open buffers)")
map('n', '<Leader>ft', '<cmd>Telescope treesitter<cr>', opts, "Telescope", "treesitter", "Explore treesitter")
map('n', '<Leader>fC', '<cmd>Telescope git_bcommits<cr>', opts, "Telescope", "git_bcommits", "Show diff of current buffer")
map('n', '<Leader>fh', '<cmd>Telescope builtin<cr>', opts, "Telescope", "builtin", "Show Telescope builtins")
map('n', '<Leader>lr', '<cmd>Telescope lsp_references<cr>', opts, "Telescope", "lsp_references", "Show references using LSP")
map('n', '<Leader>li', '<cmd>Telescope lsp_implementations<cr>', opts, "Telescope", "lsp_implementations", "Show implementations using LSP")
map('n', '<Leader>ld', '<cmd>Telescope lsp_definitions<cr>', opts, "Telescope", "lsp_definitions", "Show definitions using LSP")
map('n', '<Leader>ls', '<cmd>Telescope lsp_document_symbols<cr>', opts, "Telescope", "lsp_document_symbols", "Show symbols in document using LSP")
-- Undo tree
map('n', '<Leader>u', '<cmd>UndotreeToggle<cr><cmd>UndotreeFocus<cr>', {noremap = true}, "UndoTree", "undo_tree_toggle", "Toggle UndoTree browser")
-- Split maximizer
map('n', '<Leader>mm', '<cmd>MaximizerToggle<cr>', opts, "MaximizerToggle", "maximizer_toggle_n", "Toggle maximal view of current split")
map('v', '<Leader>mm', '<cmd>MaximizerToggle<cr>', opts, "MaximizerToggle", "maximizer_toggle_v", "Toggle maximal view of current split")
-- Split movement and management
map('n', '<C-l>', '<C-w>l', opts, "Movement", "move_right_n", "Move to the split to the right")
map('v', '<C-l>', '<C-w>l', opts, "Movement", "move_right_v", "Move to the split to the right")
map('i', '<C-l>', '<C-w>l', opts, "Movement", "move_right_i", "Move to the split to the right")
map('n', '<C-k>', '<C-w>k', opts, "Movement", "move_up_n", "Move to the upper split")
map('v', '<C-k>', '<C-w>k', opts, "Movement", "move_up_v", "Move to the upper split")
map('i', '<C-k>', '<C-w>k', opts, "Movement", "move_up_i", "Move to the upper split")
map('n', '<C-j>', '<C-w>j', opts, "Movement", "move_down_n", "Move to the lower split")
map('v', '<C-j>', '<C-w>j', opts, "Movement", "move_down_v", "Move to the lower split")
map('i', '<C-j>', '<C-w>j', opts, "Movement", "move_down_i", "Move to the lower split")
map('n', '<C-h>', '<C-w>h', opts, "Movement", "move_left_n", "Move to the split to the left")
map('v', '<C-h>', '<C-w>h', opts, "Movement", "move_left_v", "Move to the split to the left")
map('i', '<C-h>', '<C-w>h', opts, "Movement", "move_left_i", "Move to the split to the left")
map('n', '<C-d>', '<cmd>bd<cr>', opts, "Management", "full_close_n", "Close current split and associated buffer")
map('v', '<C-d>', '<cmd>bd<cr>', opts, "Management", "full_close_v", "Close current split and associated buffer")
map('i', '<C-d>', '<cmd>bd<cr>', opts, "Management", "full_close_i", "Close current split and associated buffer")
map('n', '<Leader><Tab>', '<cmd>bnext<cr>', {}, "Movement", "go_to_next_buf", "Switch to the next buffer")
map('n', '<Leader>\\', '<cmd>bprev<cr>', {}, "Movement", "go_to_prev_buf", "Switch to the previous buffer")
-- Move selection around
cmd ([[
nnoremap <silent> <C-Down> :m .+1<CR>==
nnoremap <silent> <C-Up> :m .-2<CR>==
inoremap <silent> <C-Down> <Esc>:m .+1<CR>==gi
inoremap <silent> <C-Up> <Esc>:m .-2<CR>==gi
vnoremap <silent> <C-Down> :m '>+1<CR>gv=gv
vnoremap <silent> <C-Up> :m '<-2<CR>gv=gv
]])
-- map('n', '<C-Down>', '<cmd>m .+1<CR>==', opts, "MoveText", "move_text_up_n", "")
-- map('n', '<C-Up>', '<cmd>m .-2<CR>==', opts, "MoveText", "move_text_down_n", "")
-- map('i', '<C-Down>', '<Esc><cmd>m .+1<CR>==gi', opts, "MoveText", "move_text_up_i", "")
-- map('i', '<C-Up>', '<Esc><cmd>m .-2<CR>==gi', opts, "MoveText", "move_text_down_i", "")
-- map('v', '<C-Down>', "<cmd>m '>+1<CR>gv=gv", opts, "MoveText", "move_text_up_v", "")
-- map('v', '<C-Up>', "<cmd>m '<-2<CR>gv=gv", opst, "MoveText", "move_text_down_v", "")
-- Clean highlight
map('n', '<leader><esc>', '<cmd>nohls<CR><cmd>call clearmatches()<cr>', opts, "CleanHighlights", "clear_all", "Clear all highlights and matches")