Still more

This commit is contained in:
Daniel Flanagan 2021-06-13 11:02:27 -05:00
parent aeddca41b1
commit a037661cf4
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
6 changed files with 254 additions and 246 deletions

View file

@ -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, '<Esc>')
end
kmapnore('n', '<C-q>', ':qa<cr>')
kmapnore('n', '<C-q>', '<Esc><C-q>')
kmapnore('n', '<C-p>', '<cmd>Telescope git_files<cr>')
kmapnore('n', '<C-g>', '<cmd>Telescope live_grep<cr>')
kmapnore('n', '<C-b>', '<cmd>Telescope buffers<cr>')
-- kmapnore('n', '???', '<cmd>Telescope help_tags<cr>')
kmapnore('n', '<C-h>', ':TmuxNavigateLeft<cr>')
kmapnore('n', '<C-j>', ':TmuxNavigateDown<cr>')
kmapnore('n', '<C-k>', ':TmuxNavigateUp<cr>')
kmapnore('n', '<C-l>', ':TmuxNavigateRight<cr>')
kmapnore('t', '<C-h>', '<C-\\><C-n>:TmuxNavigateLeft<cr>')
kmapnore('t', '<C-j>', '<C-\\><C-n>:TmuxNavigateDown<cr>')
kmapnore('t', '<C-k>', '<C-\\><C-n>:TmuxNavigateUp<cr>')
kmapnore('t', '<C-l>', '<C-\\><C-n>:TmuxNavigateRight<cr>')
kmap('', ',w', '<Plug>CamelCaseMotion_w', {silent=true})
kmap('', ',b', '<Plug>CamelCaseMotion_b', {silent=true})
kmap('', ',e', '<Plug>CamelCaseMotion_e', {silent=true})
kmap('', ',ge', '<Plug>CamelCaseMotion_ge', {silent=true})
kmap('o', 'ib', '<Plug>CamelCaseMotion_ib', {silent=true})
kmap('x', 'ib', '<Plug>CamelCaseMotion_ib', {silent=true})
kmap('o', 'ie', '<Plug>CamelCaseMotion_ie', {silent=true})
kmap('x', 'ie', '<Plug>CamelCaseMotion_ie', {silent=true})
kmap('', '<F3>', 'mw:%s/\\s\\+$//<cr>:let @/ = ""<cr>\'w')
kmap('', '<F4>', ':setlocal spell!<cr>')
kmapnore('n', '<expr> n', "'Nn'[v:searchforward]")
kmapnore('n', '<expr> N', "'nN'[v:searchforward]")
kmapnore('c', '<c-n>', '<down>')
kmapnore('c', '<c-p>', '<up>')
kmapnore('x', '<', '<gv')
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('', '<Space>', '<Nop>', {noremap=true, silent=true})
-- TODO: what is `let &fcs = 'eob: '` for?
kmap('n', '<leader>r', ':luafile '..vim.g.vimdir..'/init.lua<cr>:echo \'Reloaded init.lua\'<cr>', {silent=true})
kmap('n', '<leader>gv', ':e '..vim.g.vimdir..'/init.lua<cr>', {silent=true})
kmap('n', '<leader>w', ':bd<cr>', {silent=true})
kmap('n', '<leader>h', ':b#<cr>', {silent=true})
kmap('n', '<leader>k', ':bnext<cr>', {silent=true})
kmap('n', '<leader>j', ':bprevious<cr>', {silent=true})
kmap('n', '<leader>/', ':let @/ = ""<cr>:<BACKSPACE>', {silent=true})
kmapnore('n', '<leader>t', ':split<cr>:term<cr>:resize 24<cr>:startinsert<cr>', {silent=true})
kmapnore('t', '<C-w>', '<C-\\><C-n>:q!<cr>', {silent=true})
local evalvim = function(vimscript, output)
if (output == nil) then
output = false
end
nvim_exec(vimscript, output)
end
kmap('i', '<c-n>', '<Plug>(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={
['<C-u>']=false,
['<C-d>']=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

View file

View file

@ -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, '<Esc>', {}) end
local m = {
s = {silent = true},
n = {noremap = true},
sn = {silent = true, noremap = true},
}
local keymap = {
n = {
['<leader>r'] = {':luafile ' .. vimdir .. '/init.lua<cr>:echo \'Reloaded init.lua\'<cr>', m.s},
['<leader>gv'] = {':e ' .. vimdir .. '/init.lua<cr>', m.s},
['<leader>w'] = {':bd<cr>', m.s},
['<leader>h'] = {'b#<cr>', m.s},
['<leader>k'] = {':bnext<cr>', m.s},
['<leader>j'] = {':bprevious<cr>', m.s},
['<leader>/'] = {':let @/ = ""<cr>:<BACKSPACE>', m.s},
['<c-q>'] = ':qa<cr>',
['<c-p>'] = '<cmd>Telescope git_files<cr>',
['<c-g>'] = '<cmd>Telescope live_grep<cr>',
['<c-b>'] = '<cmd>Telescope buffers<cr>',
['<leader>t'] = '<cmd>Telescope help_tags<cr>',
['<c-h>'] = ':TmuxNavigateLeft<cr>',
['<c-j>'] = ':TmuxNavigateDown<cr>',
['<c-k>'] = ':TmuxNavigateUp<cr>',
['<c-l>'] = ':TmuxNavigateRight<cr>',
['<expr> n'] = "'Nn'[v:searchforward]",
['<expr> N'] = "'nN'[v:searchforward]",
},
t = {},
[''] = {
['<space>'] = {'<nop>', m.sn},
['<f3>'] = 'mw:%s/\\s\\+$//<cr>:let @/ = ""<cr>\'w',
['<f4>'] = ':setlocal spell!<cr>',
[',w'] = {'<Plug>CamelCaseMotion_w', m.s},
[',b'] = {'<Plug>CamelCaseMotion_b', m.s},
[',e'] = {'<Plug>CamelCaseMotion_e', m.s},
[',ge'] = {'<Plug>CamelCaseMotion_ge', m.s},
},
o = {
['ib'] = {'<Plug>CamelCaseMotion_ib', m.s},
['ie'] = {'<Plug>CamelCaseMotion_ie', m.s},
},
x = {
['<'] = '<gv',
['>'] = '>gv',
['ib'] = {'<Plug>CamelCaseMotion_ib', m.s},
['ie'] = {'<Plug>CamelCaseMotion_ie', m.s},
},
c = {
['<c-n>'] = '<down>',
['<c-p>'] = '<up>',
},
i = {
['<c-q>'] = '<esc><c-q>',
['<c-n>'] = {'<Plug>(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

View file

@ -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)

View file

@ -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}

View file

@ -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
}