I did way too much in this one commit

Vimconf2021 inspired me a lot and I'm not done yet
This commit is contained in:
Fabian Schmidt 2021-11-26 23:38:04 +01:00
parent aa4d71c989
commit bebd4c1ff9
10 changed files with 250 additions and 124 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
spell/

View File

@ -1,7 +1,6 @@
-- init.lua
require('plugins')
require('settings')
require('maps')
require('commands')
require('utils')
require'plugins'.init()
require'settings'.init()
require'maps'.init()
require'commands'

View File

@ -1,10 +1,8 @@
-- commands.lua
-- autocmd! User GoyoEnter Limelight
-- autocmd! User GoyoLeave Limelight!
-- command W :execute ':silent w !sudo tee % > /dev/null' | :edit!
vim.cmd'autocmd! User GoyoEnter Limelight'
vim.cmd'autocmd! User GoyoLeave Limelight!'
vim.cmd 'autocmd! User GoyoEnter Limelight'
vim.cmd 'autocmd! User GoyoLeave Limelight!'
vim.cmd'autocmd BufRead,BufNewFile *.wiki,*.md,*.tex set wrap'
vim.cmd 'command W :execute \':silent w !sudo tee % > /dev/null\' | :edit!'
vim.cmd'command W :execute \':silent w !sudo tee % > /dev/null\' | :edit!'

View File

@ -1,35 +1,71 @@
-- maps.lua
local maps = {}
local function map(mode, lhs, rhs, opts)
local options = {noremap = true}
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
vim.g.mapleader = " "
-- Toggle Goyo
map('n', '<C-g>', ':Goyo<Enter>', {noremap = false})
-- Open and move to resized terminal
map('n', '<leader>t', '<C-w>s<C-w>j :terminal<CR>:res 5<CR>i', {noremap = false})
-- Enter normal mode in terminal
map('t', 'ß<C-N>', '<C-\\><C-N>')
-- Clear highlight
map('n', '<C-l>', '<cmd>noh<CR>')
-- Telescope
map('n', '<Leader>ff', '<cmd>lua require(\'telescope.builtin\').git_files()<CR>')
map('n', '<Leader>fg', '<cmd>lua require(\'telescope.builtin\').live_grep()<CR>')
map('n', '<Leader>fb', '<cmd>lua require(\'telescope.builtin\').buffers()<CR>')
map('n', '<Leader>fh', '<cmd>lua require(\'telescope.builtin\').help_tags()<CR>')
-- Move to window in any mode
-- map('t', 'ª', '<C-\\><C-N><C-w>h')
-- map('t', 'º', '<C-\\><C-N><C-w>j')
-- map('t', '∆', '<C-\\><C-N><C-w>k')
-- map('t', '@', '<C-\\><C-N><C-w>l')
-- map('i', 'ª', '<C-\\><C-N><C-w>h')
-- map('i', 'º', '<C-\\><C-N><C-w>j')
-- map('i', '∆', '<C-\\><C-N><C-w>k')
-- map('i', '@', '<C-\\><C-N><C-w>l')
-- map('n', 'ª', '<C-w>h')
-- map('n', 'º', '<C-w>j')
-- map('n', '∆', '<C-w>k')
-- map('n', '@', '<C-w>l')
function maps.toggleGoyo()
map('n', '<C-g>', ':Goyo<Enter>', {noremap = false})
end
function maps.term()
-- Open and move to resized terminal
map('n', '<leader>t', '<C-w>s<C-w>j :terminal<CR>:res 5<CR>i', {noremap = false})
-- Enter normal mode in terminal
map('t', 'ß<C-N>', '<C-\\><C-N>')
end
function maps.telescope()
map('n', '<Leader>ff', '<cmd>lua require(\'telescope.builtin\').git_files()<CR>')
map('n', '<Leader>fg', '<cmd>lua require(\'telescope.builtin\').live_grep()<CR>')
map('n', '<Leader>fb', '<cmd>lua require(\'telescope.builtin\').buffers()<CR>')
map('n', '<Leader>fh', '<cmd>lua require(\'telescope.builtin\').help_tags()<CR>')
end
function maps.fixIndent()
map('v', '<', '<gv')
map('v', '>', '>gv')
end
function maps.moveByRow()
-- When text is wrapped, move by terminal rows, not lines, unles a count is provided
map('n', 'j', 'v:count == 0 ? \'gj\' : \'j\'', {silent = true, expr = true})
map('n', 'k', 'v:count == 0 ? \'gk\' : \'k\'', {silent = true, expr = true})
end
function maps.centeredSearch()
map('n', 'n', 'nzzzv')
map('n', 'N', 'Nzzzv')
end
function maps.moveToWindow()
map('t', 'ª', '<C-\\><C-N><C-w>h')
map('t', 'º', '<C-\\><C-N><C-w>j')
map('t', '', '<C-\\><C-N><C-w>k')
map('t', '@', '<C-\\><C-N><C-w>l')
map('i', 'ª', '<C-\\><C-N><C-w>h')
map('i', 'º', '<C-\\><C-N><C-w>j')
map('i', '', '<C-\\><C-N><C-w>k')
map('i', '@', '<C-\\><C-N><C-w>l')
map('n', 'ª', '<C-w>h')
map('n', 'º', '<C-w>j')
map('n', '', '<C-w>k')
map('n', '@', '<C-w>l')
end
function maps.init()
vim.g.mapleader = " "
maps.toggleGoyo()
maps.term()
maps.telescope()
maps.fixIndent()
maps.moveByRow()
maps.centeredSearch()
maps.moveToWindow()
end
return maps

View File

@ -1,28 +1,49 @@
-- plugin.lua
vim.cmd 'packadd paq-nvim'
local paq = require'paq-nvim'.paq
paq{'savq/paq-nvim', opt=true}
local plugins = {}
-- Theme
paq 'akinsho/nvim-bufferline.lua'
paq 'hoob3rt/lualine.nvim'
paq 'airblade/vim-gitgutter'
paq 'kyazdani42/nvim-web-devicons'
paq 'doums/darcula'
paq 'junegunn/goyo.vim'
paq 'junegunn/limelight.vim'
function plugins.load(pluginList)
for _, plugin in pairs(pluginList) do
require'paq-nvim'.paq(plugin)
end
end
-- Utils
paq 'nvim-lua/popup.nvim'
paq 'nvim-lua/plenary.nvim'
local pluginList = {
-- Handle itself
{'savq/paq-nvim', opt=true},
-- File Navigation
paq 'kyazdani42/nvim-tree.lua'
paq 'nvim-telescope/telescope.nvim'
-- Theme
'kyazdani42/nvim-web-devicons',
'rktjmp/lush.nvim',
'briones-gabriel/darcula-solid.nvim',
-- lsp
paq 'neovim/nvim-lspconfig'
-- treesitter
'nvim-treesitter/nvim-treesitter',
-- treesitter
-- paq 'nvim-treesitter/nvim-treesitter'
-- Utils
'akinsho/nvim-bufferline.lua',
'hoob3rt/lualine.nvim',
'airblade/vim-gitgutter',
'nvim-lua/popup.nvim',
'nvim-lua/plenary.nvim',
-- File Navigation
'kyazdani42/nvim-tree.lua',
'nvim-telescope/telescope.nvim',
-- lsp
'neovim/nvim-lspconfig',
'williamboman/nvim-lsp-installer',
-- writing
'vimwiki/vimwiki',
'junegunn/goyo.vim',
'junegunn/limelight.vim',
}
function plugins.init()
vim.cmd 'packadd paq-nvim'
plugins.load(pluginList)
end
return plugins

View File

@ -1,64 +0,0 @@
-- settings.lua
local cmd = vim.cmd
local scopes = {o = vim.o, bo = vim.bo, wo = vim.wo}
local function opt(scope, key, value)
scopes[scope][key] = value
if scope ~= 'o' then scopes['o'][key] = value end
end
---- Misc Options
-- global options
opt('o', 'backup', false)
opt('o', 'undodir', '/Users/fschmidt/.cache/nvim/undodir')
opt('o', 'smartcase', true)
opt('o', 'laststatus', 2)
opt('o', 'hidden', true)
opt('o', 'hlsearch', false)
opt('o', 'incsearch', true)
opt('o', 'ignorecase', true)
opt('o', 'scrolloff', 12)
opt('o', 'mouse', 'a')
opt('o', 'autochdir', true)
-- window-local options
opt('wo', 'number', true)
opt('wo', 'wrap', false)
opt('wo', 'signcolumn', 'yes')
-- buffer-local options
opt('bo', 'shiftwidth', 4)
opt('bo', 'tabstop', 4)
opt('bo', 'softtabstop', 4)
opt('bo', 'expandtab', true)
opt('bo', 'autoindent', true)
opt('bo', 'swapfile', false)
opt('bo', 'undofile', true)
---- Theme
-- Font
opt('o', 'guifont', 'Source Code Pro for Powerline')
-- Statusline
require'lualine'.setup {
options = {
theme = 'onedark'
}
}
-- Bufferline
local bufferline = require('bufferline')
bufferline.setup()
local function ColorDarcula()
vim.g.limelight_conceal_ctermfg = 'gray'
cmd 'colorscheme darcula'
end
opt('bo', 'syntax', 'on')
ColorDarcula()
-- File Navigation

44
lua/settings/init.lua Normal file
View File

@ -0,0 +1,44 @@
-- settings.lua
local settings = {}
function settings.initMisc()
vim.opt.backup = false
vim.opt.undodir = '/Users/fschmidt/.cache/nvim/undodir'
vim.opt.swapfile = false
vim.opt.undofile = true
vim.opt.smartcase = true
vim.opt.ignorecase = true
vim.opt.laststatus = 2
vim.opt.hidden = true
vim.opt.hlsearch = false
vim.opt.incsearch = true
vim.opt.scrolloff = 12
vim.opt.sidescrolloff = 8
vim.opt.mouse = 'a'
vim.opt.autochdir = true
vim.opt.clipboard = 'unnamed,unnamedplus'
vim.opt.number = true
vim.opt.wrap = false
vim.opt.signcolumn = 'yes:2'
vim.opt.list = true
vim.opt.listchars = 'tab:▸ ,trail:·'
vim.opt.shiftwidth = 4
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.expandtab = false
vim.opt.autoindent = true
end
function settings.initVimWiki()
vim.g.vimwiki_list = {{path = '~/Documents/Buch/wiki', syntax = 'markdown', ext = '.md'}}
end
function settings.init()
settings.initMisc()
settings.initVimWiki()
require'settings.theme'.init()
require'settings.lsp'.init()
end
return settings

55
lua/settings/lsp.lua Normal file
View File

@ -0,0 +1,55 @@
-- LSP Config
local lsp = {}
local on_attach = function(_, 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')
local opts = { noremap=true, silent=true }
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', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workleader_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workleader_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workleader_folders()))<CR>', opts)
buf_set_keymap('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<leader>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', '<leader>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', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
function lsp.init()
local lsp_installer = require'nvim-lsp-installer'
lsp_installer.on_server_ready(function(server)
local opts = {}
if server.name == 'sumneko_lua' then
opts.settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
}
}
}
end
opts.on_attach = on_attach
opts.flags = {
debounce_text_changes = 150,
}
server:setup(opts)
end)
end
return lsp

36
lua/settings/theme.lua Normal file
View File

@ -0,0 +1,36 @@
-- Theming
local theme = {}
function theme.initFont()
vim.opt.guifont = 'Source Code Pro for Powerline'
end
function theme.initStatusline()
require'lualine'.setup {
options = {
theme = 'onedark'
}
}
end
function theme.initBufferline()
local bufferline = require'bufferline'
bufferline.setup()
end
function theme.initColorscheme()
vim.g.limelight_conceal_ctermfg = 'gray'
vim.cmd'colorscheme darcula-solid'
vim.cmd'set termguicolors'
vim.opt.syntax = 'on'
end
function theme.init()
theme.initFont()
theme.initStatusline()
theme.initBufferline()
theme.initColorscheme()
end
return theme

View File