nvim_config/init.lua

208 lines
8.1 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
2022-02-22 00:02:44 +01:00
-- local autocmd = utils.autocmd
-- local map = utils.map
2021-09-06 23:34:51 +02:00
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:.•]])
2022-10-02 00:47:43 +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()]]
2022-02-22 00:02:44 +01:00
-- issue with python 3.10 (https://github.com/neovim/neovim/issues/14586)
2022-03-07 22:16:18 +01:00
-- g.python3_host_prog = '/usr/bin/python3'
2022-02-22 00:02:44 +01:00
2021-09-06 23:34:51 +02:00
-- Colortheme
require('config.theme')
-- Treesitter configuration
require('config.treesitter')
-- LSP configuration
require('config.lspconfig')
2022-02-22 00:03:07 +01:00
-- Custom
Custom = require('config.custom')
2022-10-02 00:47:43 +02:00
cmd([[
au BufRead,BufNewFile *.ha set filetype=hare
au BufRead,BufNewFile *.conf set filetype=config
]])
g["do_filetype_lua"] = 1
2022-02-22 00:03:07 +01:00
2021-09-06 23:34:51 +02:00
-- Keybinds
let(nil, 'mapleader', ',')
Mapper = require("nvim-mapper")
local map = Mapper.map
-- - Telescope-related
2022-02-22 00:02:44 +01:00
local opts = { noremap = true, silent = true }
2022-10-02 00:47:43 +02:00
map('n', '<Leader>ff', '<cmd>Telescope find_files<cr>', opts, "Telescope", "find_files",
"Find files from current position")
2021-09-06 23:34:51 +02:00
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")
2022-10-02 00:47:43 +02:00
map('n', '<Leader>fc', '<cmd>Telescope grep_string<cr>', opts, "Telescope", "grep_string",
"Search string from current position")
2021-09-06 23:34:51 +02:00
map('n', '<Leader>fr', '<cmd>Telescope live_grep<cr>', opts, "Telescope", "live_grep", "Search string in real time")
2022-10-02 00:47:43 +02:00
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)")
2021-09-06 23:34:51 +02:00
map('n', '<Leader>ft', '<cmd>Telescope treesitter<cr>', opts, "Telescope", "treesitter", "Explore treesitter")
2022-10-02 00:47:43 +02:00
map('n', '<Leader>fC', '<cmd>Telescope git_bcommits<cr>', opts, "Telescope", "git_bcommits",
"Show diff of current buffer")
2021-09-06 23:34:51 +02:00
map('n', '<Leader>fh', '<cmd>Telescope builtin<cr>', opts, "Telescope", "builtin", "Show Telescope builtins")
2022-10-02 00:47:43 +02:00
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")
2021-09-06 23:34:51 +02:00
-- Undo tree
2022-10-02 00:47:43 +02:00
map('n', '<Leader>u', '<cmd>UndotreeToggle<cr><cmd>UndotreeFocus<cr>', { noremap = true }, "UndoTree", "undo_tree_toggle"
, "Toggle UndoTree browser")
2021-09-06 23:34:51 +02:00
-- Split maximizer
2022-10-02 00:47:43 +02:00
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")
2021-09-06 23:34:51 +02:00
-- 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")
2022-10-02 00:47:43 +02:00
-- Search niceties
map('v', '<Leader>/', '<esc>:\\%V', {}, "Search", "search_in_visual_selection",
"Search only in the current visual selection")
2021-09-06 23:34:51 +02:00
-- Move selection around
2022-02-22 00:02:44 +01:00
cmd([[
2021-09-06 23:34:51 +02:00
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
2022-10-02 00:47:43 +02:00
map('n', '<leader><esc>', '<cmd>nohls<CR><cmd>call clearmatches()<cr>', opts, "CleanHighlights", "clear_all",
"Clear all highlights and matches")
2022-02-22 00:03:07 +01:00
-- Open links with reader
2022-10-02 00:47:43 +02:00
map('n', 'gx', '<cmd>lua Custom.open_with_reader()<cr>', {}, "OpenWithReader", "open_with_reader",
"Open the link under the cursor with `reader` in a floating tab")
-- cder
map('n', '<leader>cd', '<cmd>Telescope cder<cr>', {}, "Cder", "cder", "Change base directory interactively")
-- vgit
require('config.vgit')
-- coc
require('config.coc')