From a037661cf43d164b4afe63453ced8d236e81b40e Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Sun, 13 Jun 2021 11:02:27 -0500 Subject: [PATCH] Still more --- common/neovim/init.lua | 260 ++++--------------------------- common/neovim/lua/config.moon | 0 common/neovim/lua/keymap.lua | 68 ++++++++ common/neovim/lua/options.lua | 89 +++++++++++ common/neovim/lua/plugins.lua | 43 +++++ common/neovim/lua/statusline.lua | 40 ++--- 6 files changed, 254 insertions(+), 246 deletions(-) create mode 100644 common/neovim/lua/config.moon create mode 100644 common/neovim/lua/keymap.lua create mode 100644 common/neovim/lua/options.lua create mode 100644 common/neovim/lua/plugins.lua diff --git a/common/neovim/init.lua b/common/neovim/init.lua index 1dbaddc..001b02e 100644 --- a/common/neovim/init.lua +++ b/common/neovim/init.lua @@ -1,233 +1,41 @@ -vim.g.vimdir = vim.fn.getenv('XDG_CONFIG_HOME')..'/nvim' - --- plugin manager -local packer_install_path = vim.fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' - -local execute = vim.api.nvim_command - -if vim.fn.empty(vim.fn.glob(packer_install_path)) > 0 then - vim.fn.system{'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_install_path} - execute'packadd packer.nvim' -end - -vim.api.nvim_exec([[ - augroup Packer - autocmd! - autocmd BufWritePost init.lua PackerCompile - augroup end -]], false) - -local use = require('packer').use - -require('packer').startup(function() - use 'wbthomason/packer.nvim' - use 'editorconfig/editorconfig-vim' - use 'tpope/vim-sleuth' - use 'vim-scripts/LargeFile' - use 'vim-scripts/restore_view.vim' - use 'christoomey/vim-tmux-navigator' - use 'tpope/vim-fugitive' - use 'tpope/vim-rhubarb' - use 'tpope/vim-commentary' - use 'tpope/vim-repeat' - use 'machakann/vim-sandwich' - use 'michaeljsmith/vim-indent-object' - use 'wellle/targets.vim' - use 'bkad/CamelCaseMotion' - use 'ludovicchabant/vim-gutentags' - use 'tpope/vim-obsession' - use 'dhruvasagar/vim-prosession' - use {'nvim-telescope/telescope.nvim', requires={{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}}} - use 'joshdick/onedark.vim' - use {'lukas-reineke/indent-blankline.nvim', branch='lua'} - use {'lewis6991/gitsigns.nvim', requires={'nvim-lua/plenary.nvim'}} - use 'neovim/nvim-lspconfig' - use 'hrsh7th/nvim-compe' - use 'sheerun/vim-polyglot' - use {'neoclide/coc.nvim', branch='release'} -end) - -local globals = { - mapleader=' ', - maplocalleader=' ', - completion_enable_auto_popup=0, - skipview_files={'COMMIT_EDITMSG'}, - indent_blankline_char='▏', - indent_blankline_filetype_exclude={'help', 'packer'}, - indent_blankline_buftype_exclude={'terminal', 'nofile'}, - indent_blankline_char_highlight='LineNr', -} - -for k,v in pairs(globals) do - vim.g[k] = v -end - -local options = { - inccommand='nosplit', - tabstop=2, - softtabstop=2, - shiftwidth=2, - smartindent=true, - list=true, - listchars='trail:·,tab: ,trail:~', - linebreak=true, - formatoptions='crql1jn', - synmaxcol=200, - lazyredraw=true, - scrolloff=8, - sidescrolloff=15, - mouse='a', - splitright=true, - splitbelow=true, - errorbells=false, - visualbell=true, - backup=false, - writebackup=false, - swapfile=false, - timeout=true, - timeoutlen=150, - hidden=true, - shortmess='filnxToOFIac', - history=1000, - undofile=true, - undodir=vim.g.vimdir..'/undo', - undolevels=1000, - undoreload=1000, - spellfile=vim.g.vimdir..'/spell/en.utf-8.add', - ignorecase=true, - smartcase=true, - incsearch=true, - wrapscan=true, - hlsearch=true, - foldmethod='syntax', - foldlevel=99, - foldnestmax=10, - foldlevelstart=99, - autowrite=false, - autochdir=true, - autoread=true, - modeline=false, - showmode=false, - showcmd=false, - laststatus=2, - ruler=false, - termguicolors=true, -} - -for k,v in pairs(options) do - -- print(tostring(k)..tostring(v)) - vim.o[k] = v -end - --- let &fcs = 'eob: ' - -vim.cmd[[colorscheme base16-donokai]] - -vim.cmd[[ -hi Search cterm=NONE ctermbg=blue ctermfg=black -hi LineNr ctermbg=none ctermfg=8 -hi CursorLineNr ctermbg=18 ctermfg=gray -hi IndentGuidesEven ctermbg=18 -hi Normal ctermbg=NONE -hi ColorColumn ctermbg=18 -hi TooLongColorColumn ctermbg=18 ctermfg=1 -hi ActiveBuffer ctermbg=4 ctermfg=0 -hi DirtyBuffer ctermbg=3 ctermfg=0 -hi StatusLine ctermbg=18 ctermfg=7 -hi StatusLineNC ctermbg=18 ctermfg=7 -]] - -execute[[call matchadd('ColorColumn', '\\%81v', 100)]] -execute[[call matchadd('TooLongColorColumn', '\\%121v', 200)]] - -vim.cmd[[command! W write]] - -function kmap(mode, keys, command, opts) - if opts == nil then opts = {} end - vim.api.nvim_set_keymap(mode, keys, command, opts) -end - -function kmapnore(mode, keys, command) - kmap(mode, keys, command, {noremap=true}) -end - -local escapes = {'jj', 'jJ', 'Jj', 'JJ', 'jk', 'jK', 'Jk', 'JK'} -for _,keys in ipairs(escapes) do - kmap('i', keys, '') -end - -kmapnore('n', '', ':qa') -kmapnore('n', '', '') - -kmapnore('n', '', 'Telescope git_files') -kmapnore('n', '', 'Telescope live_grep') -kmapnore('n', '', 'Telescope buffers') --- kmapnore('n', '???', 'Telescope help_tags') - -kmapnore('n', '', ':TmuxNavigateLeft') -kmapnore('n', '', ':TmuxNavigateDown') -kmapnore('n', '', ':TmuxNavigateUp') -kmapnore('n', '', ':TmuxNavigateRight') -kmapnore('t', '', ':TmuxNavigateLeft') -kmapnore('t', '', ':TmuxNavigateDown') -kmapnore('t', '', ':TmuxNavigateUp') -kmapnore('t', '', ':TmuxNavigateRight') - -kmap('', ',w', 'CamelCaseMotion_w', {silent=true}) -kmap('', ',b', 'CamelCaseMotion_b', {silent=true}) -kmap('', ',e', 'CamelCaseMotion_e', {silent=true}) -kmap('', ',ge', 'CamelCaseMotion_ge', {silent=true}) -kmap('o', 'ib', 'CamelCaseMotion_ib', {silent=true}) -kmap('x', 'ib', 'CamelCaseMotion_ib', {silent=true}) -kmap('o', 'ie', 'CamelCaseMotion_ie', {silent=true}) -kmap('x', 'ie', 'CamelCaseMotion_ie', {silent=true}) - -kmap('', '', 'mw:%s/\\s\\+$//:let @/ = ""\'w') -kmap('', '', ':setlocal spell!') -kmapnore('n', ' n', "'Nn'[v:searchforward]") -kmapnore('n', ' N', "'nN'[v:searchforward]") -kmapnore('c', '', '') -kmapnore('c', '', '') -kmapnore('x', '<', '', '>gv') +local kmap = vim.api.nvim_set_keymap +local excmd = vim.api.nvim_command +local nvim_exec = vim.api.nvim_exec -- TODO: learn about the wildmenu `q:` -kmap('', '', '', {noremap=true, silent=true}) +-- TODO: what is `let &fcs = 'eob: '` for? -kmap('n', 'r', ':luafile '..vim.g.vimdir..'/init.lua:echo \'Reloaded init.lua\'', {silent=true}) -kmap('n', 'gv', ':e '..vim.g.vimdir..'/init.lua', {silent=true}) -kmap('n', 'w', ':bd', {silent=true}) -kmap('n', 'h', ':b#', {silent=true}) -kmap('n', 'k', ':bnext', {silent=true}) -kmap('n', 'j', ':bprevious', {silent=true}) -kmap('n', '/', ':let @/ = "":', {silent=true}) -kmapnore('n', 't', ':split:term:resize 24:startinsert', {silent=true}) -kmapnore('t', '', ':q!', {silent=true}) +local evalvim = function(vimscript, output) + if (output == nil) then + output = false + end + nvim_exec(vimscript, output) +end -kmap('i', '', '(completion_trigger)', {silent=true}) +require('plugins').setup() +require'options' +require'keymap' -execute[[au BufReadPost * | if stridx(&ft, 'commit') >= 0 | exe "startinsert!" | endif]] - -vim.api.nvim_exec([[ -augroup slime - au! - autocmd BufNewFile,BufRead *.slimleex set syntax=slim -augroup END -]], false) - -require('telescope').setup{ - defaults={ - mappings={ - i={ - ['']=false, - ['']=false, - }, +do + local plugin_setups = { + telescope = { + defaults = { + mappings = {i = {['c-u'] = false, ['c-d'] = false}}, + generic_sorter = require('telescope.sorters').get_fzy_sorter, + file_sorter = require('telescope.sorters').get_fzy_sorter, + } }, - generic_sorter=require'telescope.sorters'.get_fzy_sorter, - file_sorter=require'telescope.sorters'.get_fzy_sorter, + fold = true, + statusline = true, + lsp = true, } -} - -require('./fold').setup() -require('./statusline').setup() -require('./lsp').setup() + for k,v in pairs(plugin_setups) do + if type(v) == 'function' then + v(require(k)) + elseif type(v) == 'table' then + require(k).setup(v) + elseif v == true then + require(k).setup() + end + end +end diff --git a/common/neovim/lua/config.moon b/common/neovim/lua/config.moon new file mode 100644 index 0000000..e69de29 diff --git a/common/neovim/lua/keymap.lua b/common/neovim/lua/keymap.lua new file mode 100644 index 0000000..0bdc213 --- /dev/null +++ b/common/neovim/lua/keymap.lua @@ -0,0 +1,68 @@ +local vimdir = os.getenv('XDG_CONFIG_HOME') .. '/nvim' + +for _,keys in ipairs{'jj', 'jJ', 'Jj', 'JJ', 'jk', 'jK', 'Jk', 'JK'} do kmap('i', keys, '', {}) end + +local m = { + s = {silent = true}, + n = {noremap = true}, + sn = {silent = true, noremap = true}, +} +local keymap = { + n = { + ['r'] = {':luafile ' .. vimdir .. '/init.lua:echo \'Reloaded init.lua\'', m.s}, + ['gv'] = {':e ' .. vimdir .. '/init.lua', m.s}, + ['w'] = {':bd', m.s}, + ['h'] = {'b#', m.s}, + ['k'] = {':bnext', m.s}, + ['j'] = {':bprevious', m.s}, + ['/'] = {':let @/ = "":', m.s}, + [''] = ':qa', + [''] = 'Telescope git_files', + [''] = 'Telescope live_grep', + [''] = 'Telescope buffers', + ['t'] = 'Telescope help_tags', + [''] = ':TmuxNavigateLeft', + [''] = ':TmuxNavigateDown', + [''] = ':TmuxNavigateUp', + [''] = ':TmuxNavigateRight', + [' n'] = "'Nn'[v:searchforward]", + [' N'] = "'nN'[v:searchforward]", + }, + t = {}, + [''] = { + [''] = {'', m.sn}, + [''] = 'mw:%s/\\s\\+$//:let @/ = ""\'w', + [''] = ':setlocal spell!', + [',w'] = {'CamelCaseMotion_w', m.s}, + [',b'] = {'CamelCaseMotion_b', m.s}, + [',e'] = {'CamelCaseMotion_e', m.s}, + [',ge'] = {'CamelCaseMotion_ge', m.s}, + }, + o = { + ['ib'] = {'CamelCaseMotion_ib', m.s}, + ['ie'] = {'CamelCaseMotion_ie', m.s}, + }, + x = { + ['<'] = ''] = '>gv', + ['ib'] = {'CamelCaseMotion_ib', m.s}, + ['ie'] = {'CamelCaseMotion_ie', m.s}, + }, + c = { + [''] = '', + [''] = '', + }, + i = { + [''] = '', + [''] = {'(completion_trigger)', m.s}, + }, +} +for mode,mappings in pairs(keymap) do + for key,bind in pairs(mappings) do + if type(bind) == 'table' then + vim.api.nvim_set_keymap(mode, key, bind[1], bind[2]) + else + vim.api.nvim_set_keymap(mode, key, bind, {}) + end + end +end diff --git a/common/neovim/lua/options.lua b/common/neovim/lua/options.lua new file mode 100644 index 0000000..3a48dd4 --- /dev/null +++ b/common/neovim/lua/options.lua @@ -0,0 +1,89 @@ +local globals = { + mapleader = ' ', + maplocalleader = ' ', + completion_enable_auto_popup = 0, + skipview_files = {'COMMIT_EDITMSG'}, + indent_blankline_char = '▏', + indent_blankline_filetype_exclude = {'help', 'packer'}, + indent_blankline_buftype_exclude = {'terminal', 'nofile'}, + indent_blankline_char_highlight = 'LineNr', +} +for k,v in pairs(globals) do vim.g[k] = v end + +local options = { + inccommand = 'nosplit', + tabstop = 2, + softtabstop = 2, + shiftwidth = 2, + smartindent = true, + list = true, + listchars = 'trail:·,tab: ', + linebreak = true, + formatoptions = 'crql1jn', + synmaxcol = 200, + lazyredraw = true, + scrolloff = 8, + sidescrolloff = 15, + mouse = 'a', + splitright = true, + splitbelow = true, + errorbells = false, + visualbell = true, + backup = false, + writebackup = false, + swapfile = false, + timeout = true, + timeoutlen = 150, + hidden = true, + shortmess = 'filnxToOFIac', + history = 1000, + undofile = true, + undodir = vimdir .. '/undo', + undolevels = 1000, + undoreload = 1000, + spellfile = vimdir .. '/spell/en.utf-8.add', + ignorecase = true, + smartcase = true, + incsearch = true, + wrapscan = true, + hlsearch = true, + foldmethod = 'syntax', + foldlevel = 99, + foldnestmax = 10, + foldlevelstart = 99, + autowrite = false, + autochdir = true, + autoread = true, + modeline = false, + showmode = false, + showcmd = false, + laststatus = 2, + ruler = false, + termguicolors = true, +} +for k,v in pairs(options) do + vim.o[k] = v +end + +vim.api.nvim_exec([[ + hi Search cterm=NONE ctermbg=blue ctermfg=black + hi LineNr ctermbg=0 ctermfg=8 + hi CursorLineNr ctermbg=18 ctermfg=gray + hi IndentGuidesEven ctermbg=18 + hi Normal ctermbg=NONE + hi ActiveBuffer ctermbg=4 ctermfg=0 + hi DirtyBuffer ctermbg=3 ctermfg=0 + hi StatusLine ctermbg=1 ctermfg=7 + hi StatusLineNC ctermbg=2 ctermfg=7 + command! W write + augroup oncommit + au! BufReadPost * + if stridx(&ft, 'commit') >= 0 + exe "startinsert!" + endif + augroup END + augroup slime + au! BufNewFile,BufRead *.slimleex set syntax=slim + augroup END + colorscheme base16-donokai +]], false) diff --git a/common/neovim/lua/plugins.lua b/common/neovim/lua/plugins.lua new file mode 100644 index 0000000..f406bfd --- /dev/null +++ b/common/neovim/lua/plugins.lua @@ -0,0 +1,43 @@ +local setup = function() + local packer_install_path = "#{fn.stdpath 'data'}/site/pack/packer/start/packer.nvim" + if #vim.fn.glob(packer_install_path) > 0 then + vim.fn.system {'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_install_path} + vim.api.nvim_command'packadd packer.nvim' + end + + local packer = require'packer' + packer.startup(function() + local plugins = { + 'wbthomason/packer.nvim', + 'editorconfig/editorconfig-vim', + 'tpope/vim-sleuth', + 'vim-scripts/LargeFile', + 'vim-scripts/restore_view.vim', + 'christoomey/vim-tmux-navigator', + 'tpope/vim-fugitive', + 'tpope/vim-rhubarb', + 'tpope/vim-commentary', + 'tpope/vim-repeat', + 'machakann/vim-sandwich', + 'michaeljsmith/vim-indent-object', + 'wellle/targets.vim', + 'bkad/CamelCaseMotion', + 'ludovicchabant/vim-gutentags', + 'tpope/vim-obsession', + 'dhruvasagar/vim-prosession', + {'nvim-telescope/telescope.nvim', requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}}}, + 'joshdick/onedark.vim', + {'lukas-reineke/indent-blankline.nvim', branch = 'lua'}, + {'lewis6991/gitsigns.nvim', requires = {'nvim-lua/plenary.nvim'}}, + 'neovim/nvim-lspconfig', + 'hrsh7th/nvim-compe', + 'sheerun/vim-polyglot', + {'neoclide/coc.nvim', branch = 'release'}, + } + for _,plugin in ipairs(plugins) do + packer.use(plugin) + end + end) +end + +return {setup = setup} diff --git a/common/neovim/lua/statusline.lua b/common/neovim/lua/statusline.lua index c8b34e5..87522f8 100644 --- a/common/neovim/lua/statusline.lua +++ b/common/neovim/lua/statusline.lua @@ -1,10 +1,10 @@ --- TODO: make override-able -vim.g.status_line_max_length = 5 +local fn = vim.fn +local api = vim.api +local status_line_max_length = 5 -- TODO: only update this portion when needed instead of every render? - -function StatusLineBufferByNum(bufnum) - local bufinfo = vim.fn.getbufinfo(bufnum) +local status_line_buffer_by_num = function(bufnum) + local bufinfo = fn.getbufinfo(bufnum) local prefix = ' %#InactiveBuffer#' local suffix = '%* ' @@ -13,7 +13,7 @@ function StatusLineBufferByNum(bufnum) suffix = ' %*' end - if bufinfo.hidden == 0 and vim.fn.index(bufinfo.windows, vim.g.statusline_winid) >= 0 then + if bufinfo.hidden == 0 and fn.index(bufinfo.windows, vim.g.statusline_winid) >= 0 then prefix = '%#ActiveBuffer# ' suffix = ' %*' if bufinfo.changed then @@ -22,31 +22,31 @@ function StatusLineBufferByNum(bufnum) end end - return prefix..vim.fn.fnamemodify(vim.fn.bufname(bufnum), ':t')..suffix + return prefix .. fn.fnamemodify(fn.bufname(bufnum), ':t') .. suffix end -function StatusLineBuffers() +local status_line_buffers = function() -- TODO: mark buffers with unsaved changes local active_index = -1 local acc = {} - for _,bufnum in ipairs(vim.api.nvim_list_bufs()) do - local bufinfo = vim.fn.getbufinfo(bufnum) + for _,bufnum in ipairs(api.nvim_list_bufs()) do + local bufinfo = fn.getbufinfo(bufnum) if bufinfo.listed ~= 0 then - local entry = StatusLineBufferByNum(bufnum) + local entry = status_line_buffer_by_num(bufnum) table.insert(acc, entry) - if vim.fn.matchstr(entry, '^%#ActiveBuffer#') then - active_index = vim.fn.index(acc, entry) + if fn.matchstr(entry, '^%#ActiveBuffer#') then + active_index = fn.index(acc, entry) end end end if active_index >= 0 then -- TODO: instead implement this as a wraparound carousel? - local offset = vim.g.status_line_max_length / 2 + local offset = status_line_max_length / 2 local min_buf_num = math.max(0, (active_index - offset)) - local max_buf_num = math.min(#acc - 1, min_buf_num + vim.g.status_line_max_length - 1) - min_buf_num = math.max(0, max_buf_num - vim.g.status_line_max_length + 1) - local buflist = table.concat({unpack(acc, min_buf_num, max_buf_num)}, '') + local max_buf_num = math.min(#acc - 1, min_buf_num + status_line_max_length - 1) + min_buf_num = math.max(0, max_buf_num - status_line_max_length + 1) + local buflist = table.concat({unpack(acc, min_buf_num+1, max_buf_num+1)}, '') local prefix = '' local suffix = '' if min_buf_num > 0 then @@ -55,18 +55,18 @@ function StatusLineBuffers() if max_buf_num < (#acc - 1) then suffix = ' >' end - return prefix..buflist..suffix + return prefix .. buflist .. suffix else return table.concat(acc, '') end end function StatusLine() - return StatusLineBuffers()..'%*%=%c,%l/%L (%p%%)' + return status_line_buffers() .. '%*%=%c,%l/%L (%p%%)' end return { setup=function() - vim.o.statusline = ''..StatusLine() + vim.o.statusline = '%!v:lua.StatusLine()' end }