diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f84e7ed --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +spell/ diff --git a/init.lua b/init.lua index 46b19a3..5652627 100644 --- a/init.lua +++ b/init.lua @@ -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' diff --git a/lua/commands.lua b/lua/commands.lua index 67f3f4f..cbdc598 100644 --- a/lua/commands.lua +++ b/lua/commands.lua @@ -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!' diff --git a/lua/maps.lua b/lua/maps.lua index d004900..23e59ab 100644 --- a/lua/maps.lua +++ b/lua/maps.lua @@ -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', '', ':Goyo', {noremap = false}) --- Open and move to resized terminal -map('n', 't', 'sj :terminal:res 5i', {noremap = false}) --- Enter normal mode in terminal -map('t', 'ß', '') --- Clear highlight -map('n', '', 'noh') --- Telescope -map('n', 'ff', 'lua require(\'telescope.builtin\').git_files()') -map('n', 'fg', 'lua require(\'telescope.builtin\').live_grep()') -map('n', 'fb', 'lua require(\'telescope.builtin\').buffers()') -map('n', 'fh', 'lua require(\'telescope.builtin\').help_tags()') --- Move to window in any mode --- map('t', 'ª', 'h') --- map('t', 'º', 'j') --- map('t', '∆', 'k') --- map('t', '@', 'l') --- map('i', 'ª', 'h') --- map('i', 'º', 'j') --- map('i', '∆', 'k') --- map('i', '@', 'l') --- map('n', 'ª', 'h') --- map('n', 'º', 'j') --- map('n', '∆', 'k') --- map('n', '@', 'l') +function maps.toggleGoyo() + map('n', '', ':Goyo', {noremap = false}) +end +function maps.term() + -- Open and move to resized terminal + map('n', 't', 'sj :terminal:res 5i', {noremap = false}) + -- Enter normal mode in terminal + map('t', 'ß', '') +end + +function maps.telescope() + map('n', 'ff', 'lua require(\'telescope.builtin\').git_files()') + map('n', 'fg', 'lua require(\'telescope.builtin\').live_grep()') + map('n', 'fb', 'lua require(\'telescope.builtin\').buffers()') + map('n', 'fh', 'lua require(\'telescope.builtin\').help_tags()') +end + +function maps.fixIndent() + 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', 'ª', 'h') + map('t', 'º', 'j') + map('t', '∆', 'k') + map('t', '@', 'l') + map('i', 'ª', 'h') + map('i', 'º', 'j') + map('i', '∆', 'k') + map('i', '@', 'l') + map('n', 'ª', 'h') + map('n', 'º', 'j') + map('n', '∆', 'k') + map('n', '@', '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 diff --git a/lua/plugins.lua b/lua/plugins.lua index 4662c80..139315b 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -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 diff --git a/lua/settings.lua b/lua/settings.lua deleted file mode 100644 index 146f928..0000000 --- a/lua/settings.lua +++ /dev/null @@ -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 diff --git a/lua/settings/init.lua b/lua/settings/init.lua new file mode 100644 index 0000000..a3f5b02 --- /dev/null +++ b/lua/settings/init.lua @@ -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 diff --git a/lua/settings/lsp.lua b/lua/settings/lsp.lua new file mode 100644 index 0000000..d25e71b --- /dev/null +++ b/lua/settings/lsp.lua @@ -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 + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + local opts = { noremap=true, silent=true } + + 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_workleader_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workleader_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workleader_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 + +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 diff --git a/lua/settings/theme.lua b/lua/settings/theme.lua new file mode 100644 index 0000000..2460e1f --- /dev/null +++ b/lua/settings/theme.lua @@ -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 diff --git a/lua/utils.lua b/lua/utils.lua deleted file mode 100644 index e69de29..0000000