Created
July 21, 2023 17:46
-
-
Save andreypopp/4c3e63266be99c62556c96642a9e66f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- PRELUDE | |
-- | |
local ink = require 'ink' | |
local ink_fzf = require 'ink_fzf' | |
-- | |
-- CLIPBOARD | |
-- | |
-- use pbcopy/pbpaste everywhere | |
vim.g.clipboard = { | |
name='my', | |
copy={ | |
['+']='pbcopy', | |
['*']='pbcopy', | |
}, | |
paste= { | |
['+']='pbpaste', | |
['*']='pbpaste', | |
}, | |
cache_enabled= 1, | |
} | |
-- | |
-- GENERAL OPTIONS | |
-- | |
-- disable python/python3 provides for better startup time | |
vim.g.loaded_python_provider = false | |
vim.g.loaded_python3_provider = false | |
vim.o.modeline = false | |
vim.o.hidden = true | |
vim.o.showmode = false | |
vim.o.wrap = true | |
vim.o.cmdheight = 2 | |
vim.o.laststatus = 3 -- set to 3 for a single statusline for all splits | |
vim.o.cursorline = true | |
vim.o.backspace = 'indent,eol,start' | |
vim.o.expandtab = true | |
vim.o.diffopt = 'filler,context:9999,internal,algorithm:patience,indent-heuristic' | |
vim.o.autoindent = true | |
vim.o.copyindent = true | |
vim.o.signcolumn = 'yes' | |
vim.o.shiftwidth = 2 | |
vim.o.tabstop = 2 | |
vim.o.softtabstop = 2 | |
vim.o.textwidth = 79 | |
vim.o.shiftround = true | |
vim.o.showmatch = true | |
vim.o.smartcase = true | |
vim.o.virtualedit = 'block' | |
vim.o.smarttab = true | |
vim.o.hlsearch = true | |
vim.o.incsearch = true | |
vim.o.scrolloff = 4 | |
vim.o.history = 1000 | |
vim.o.undolevels = 1000 | |
vim.o.wildignore='*.swp,*.bak,*.pyc,*.egg-info,.git,.svn,.hg,.bzr,.env, node_modules' | |
vim.o.title = true | |
vim.o.visualbell = true | |
vim.o.errorbells = false | |
vim.o.visualbell = 't_vb=' | |
vim.o.tildeop = true | |
vim.o.backup = false | |
vim.o.backupcopy = 'yes' | |
vim.o.swapfile = false | |
vim.o.wildmenu = true | |
vim.o.wildmode = 'longest:full,full' | |
vim.o.showcmd = true | |
vim.o.shortmess = 'atIc' | |
vim.o.display = 'lastline,uhex' | |
vim.o.mouse = 'a' | |
vim.o.confirm = true | |
vim.o.ttimeout = true | |
vim.o.ttimeoutlen = 0 | |
vim.o.timeoutlen = 500 | |
vim.o.updatetime = 250 | |
vim.o.clipboard = 'unnamed' | |
vim.o.fileencodings = 'ucs-bom,utf-8,latin1,default' | |
vim.o.completeopt = 'menu,menuone,noinsert,noselect' | |
vim.o.tags = 'tags,./tags,.tags,./.tags' | |
vim.o.foldenable = false | |
vim.o.splitbelow = true | |
vim.o.splitright = true | |
-- leader config | |
vim.g.mapleader = ' ' | |
vim.g.maplocalleader = ',' | |
-- | |
-- MAPPINGS | |
-- | |
for _, key in ipairs {'<Up>', '<Down>', '<Left>', '<Right>'} do | |
ink.imap { key = key } | |
ink.nmap { key = key } | |
end | |
ink.nmap { key = ';', action = ':' } | |
ink.nmap { key = 'j', action = 'gj' } | |
ink.nmap { key = 'k', action = 'gk' } | |
ink.nmap { key = 'H', action = '0' } | |
ink.nmap { key = 'L', action = '$' } | |
ink.vmap { key = '<', action = '<gv' } | |
ink.vmap { key = '>', action = '>gv' } | |
ink.cmap { key = 'w!!', action = 'w !sudo tee % >/dev/null' } | |
ink.nmap { key = '<C-h>', action = '<C-w>h', silent = true } | |
ink.nmap { key = '<C-j>', action = '<C-w>j', silent = true } | |
ink.nmap { key = '<C-k>', action = '<C-w>k', silent = true } | |
ink.nmap { key = '<C-l>', action = '<C-w>l', silent = true } | |
ink.imap { key = '<C-h>', action = '<Esc><C-w>h', silent = true } | |
ink.imap { key = '<C-j>', action = '<Esc><C-w>j', silent = true } | |
ink.imap { key = '<C-k>', action = '<Esc><C-w>k', silent = true } | |
ink.imap { key = '<C-l>', action = '<Esc><C-w>l', silent = true } | |
ink.nmap { key = '<C-o>', action = '<C-o>zz' } | |
ink.nmap { key = '<C-i>', action = '<C-i>zz' } | |
ink.nmap { key = '<C-p>', action = ink_fzf.files } | |
ink.nmap { key = '<C-b>', action = ink_fzf.buffers } | |
ink.nmap { key = '<C-n>', action = ink_fzf.buffer_tags } | |
-- Restore cursor position when exiting visual mode with Esc | |
ink.nmap { key = 'v', action = 'm`v' } | |
ink.nmap { key = 'V', action = 'm`V' } | |
ink.nmap { key = '<C-v>', action = 'm`<C-v>' } | |
ink.vmap { key = '<Esc>', action = '<Esc>``' } | |
-- | |
-- TWEAK HIGHLIGHT SEARCH | |
-- | |
ink.nmap { | |
key = '*', | |
action = function () | |
local word = vim.fn.expand('<cword>') | |
vim.fn.setreg('/', '\\<'..word..'\\>') | |
vim.o.hlsearch = true | |
end | |
} | |
ink.nmap { | |
key = '<leader>/', | |
action = function () | |
vim.o.hlsearch = false | |
vim.fn.setreg('/', '') | |
end | |
} | |
-- | |
-- APPEARANCE | |
-- | |
vim.o.guicursor = 'n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20' | |
vim.o.termguicolors = false | |
vim.o.fillchars = 'vert:│,diff:╱' | |
vim.o.showtabline = 0 | |
vim.o.background = 'light' | |
vim.cmd 'colorscheme plain' | |
-- | |
-- DIAGNOSTICS | |
-- | |
vim.diagnostic.config { | |
virtual_text = false, | |
signs = true, | |
underline = true, | |
update_in_insert = false, | |
float = { | |
header = "", | |
prefix = "", | |
border = 'single', | |
} | |
} | |
local function errors_first(f) | |
local ERROR = vim.diagnostic.severity.ERROR | |
return function() | |
local bufnr = 0 | |
local has_errors = #vim.diagnostic.get(bufnr, { severity = ERROR }) > 0 | |
if has_errors then | |
f({ float = false, severity = ERROR }) | |
else | |
f({ float = false }) | |
end | |
end | |
end | |
ink.keymap { | |
mode = 'n', | |
noremap = true, | |
silent = true, | |
keys = { | |
['<leader>e'] = vim.diagnostic.open_float, | |
['<leader>q'] = vim.diagnostic.setloclist, | |
['mp'] = errors_first(vim.diagnostic.goto_prev), | |
['[d'] = errors_first(vim.diagnostic.goto_prev), | |
['mm'] = errors_first(vim.diagnostic.goto_next), | |
[']d'] = errors_first(vim.diagnostic.goto_next), | |
}, | |
} | |
local function diagnostics_counts(bufnr) | |
local result = {} | |
local levels = { | |
errors = vim.diagnostic.severity.ERROR, | |
warnings = vim.diagnostic.severity.WARN, | |
info = vim.diagnostic.severity.INFO, | |
hints = vim.diagnostic.severity.HINT, | |
} | |
for k, severity in pairs(levels) do | |
result[k] = #vim.diagnostic.get(bufnr, {severity=severity}) | |
end | |
return result | |
end | |
function _G.diagnostics_status() | |
local counts = diagnostics_counts(0) | |
if counts.errors == 0 and counts.warnings == 0 then | |
return "OK" | |
else | |
return "" | |
end | |
end | |
function _G.diagnostics_errors() | |
local counts = diagnostics_counts(0) | |
if counts.errors == 0 then | |
return "" | |
else | |
return "E:" .. counts.errors | |
end | |
end | |
function _G.diagnostics_warnings() | |
local counts = diagnostics_counts(0) | |
if counts.warnings == 0 then | |
return "" | |
else | |
return "W:" .. counts.warnings | |
end | |
end | |
-- | |
-- PACKAGE MANAGEMENT | |
-- | |
ink.load_packages() | |
local function do_files_instead(dir) | |
if vim.b.__fzf_entry then | |
vim.cmd 'silent bdelete' | |
else | |
vim.b.__fzf_entry = true | |
vim.cmd 'silent bdelete' | |
ink_fzf.files { cwd = dir } | |
end | |
end | |
vim.api.nvim_create_autocmd("VimEnter", { | |
pattern = '*', | |
callback = function() | |
if vim.fn.exists('#FileExplorer') == 1 then | |
vim.cmd [[exe 'au! FileExplorer *']] | |
end | |
if vim.fn.exists('#NERDTreeHijackNetrw') == 1 then | |
vim.cmd [[exe 'au! NERDTreeHijackNetrw *']] | |
end | |
local fname = vim.fn.expand('%:p') | |
if fname == '' then fname = nil end | |
if fname == nil or vim.fn.isdirectory(fname) == 1 then | |
do_files_instead(fname) | |
end | |
end, | |
}) | |
vim.api.nvim_create_autocmd("BufEnter", { | |
pattern = '*', | |
callback = function() | |
local fname = vim.fn.expand('%:p') | |
if vim.fn.isdirectory(fname) == 1 and vim.v.vim_did_enter == 1 then | |
if vim.fn.isdirectory(fname) == 1 then | |
do_files_instead(fname) | |
end | |
end | |
end, | |
}) | |
-- | |
-- LSP CONFIGURATION | |
-- | |
if ink.is_package_loaded 'nvim-lspconfig' then | |
local lspconfig = require('lspconfig') | |
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( | |
vim.lsp.handlers.hover, { | |
border = "single", | |
} | |
) | |
local function activate_lsp_keymap(bufnr) | |
ink.keymap { | |
bufnr = bufnr, | |
mode = 'n', | |
noremap = true, | |
silent = true, | |
keys = { | |
['t'] = '<cmd>lua vim.lsp.buf.hover()<CR>', | |
['gd'] = '<cmd>lua vim.lsp.buf.definition()<CR>', | |
['gD'] = '<cmd>lua vim.lsp.buf.declaration()<CR>', | |
['gi'] = '<cmd>lua vim.lsp.buf.implementation()<CR>', | |
['gt'] = '<cmd>lua vim.lsp.buf.type_definition()<CR>', | |
['gr'] = '<cmd>lua vim.lsp.buf.references()<CR>', | |
['md'] = '<cmd>lua vim.diagnostic.open_float()<CR>', | |
['<leader>k'] = '<cmd>lua vim.lsp.buf.signature_help()<CR>', | |
['<leader>rn'] = '<cmd>lua vim.lsp.buf.rename()<CR>', | |
['<leader>ca'] = '<cmd>lua vim.lsp.buf.code_action()<CR>', | |
['<leader>f'] = '<cmd>lua vim.lsp.buf.format { async=true }<CR>', | |
['<C-n>'] = | |
-- TODO: need to check if lsp_document_symbol is supported | |
function() ink_fzf.lsp_document_symbol() end, | |
} | |
} | |
end | |
local on_attach = function(client, bufnr) | |
local function bufopt(...) vim.api.nvim_buf_set_option(bufnr, ...) end | |
if client.name == 'tsserver' then | |
-- disable formatting as we format with prettier | |
client.server_capabilities.documentFormattingProvider = false | |
client.server_capabilities.documentRangeFormattingProvider = false | |
end | |
-- bufopt('omnifunc', 'v:lua.lsp_omnifunc_sync') | |
activate_lsp_keymap(bufnr) | |
end | |
local signs = { Error = "█ ", Warn = "█ ", Hint = "█ ", Info = "█ " } | |
for type, icon in pairs(signs) do | |
local hl = "DiagnosticSign" .. type | |
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) | |
end | |
local activate_lsp = function(lsp, config) | |
local config0 = lspconfig[lsp].document_config.default_config | |
lspconfig[lsp].setup { | |
root_dir = function(fname) | |
local cmd = lspconfig[lsp].cmd[1] | |
if vim.fn.executable(cmd) == 0 then return nil end | |
return config0.root_dir(fname) | |
end, | |
on_attach = on_attach, | |
flags = { | |
debounce_text_changes = 700, | |
}, | |
capabilities = config.capabilities, | |
} | |
end | |
local tsserver_capabilities = vim.lsp.protocol.make_client_capabilities() | |
tsserver_capabilities.textDocument.document_formatting = false | |
local servers = { | |
gopls = {}, | |
ocamllsp = {}, | |
tsserver = { | |
capabilities = tsserver_capabilities, | |
}, | |
clangd = {}, | |
terraformls = {}, | |
} | |
for lsp, lsp_config in pairs(servers) do | |
activate_lsp(lsp, lsp_config) | |
end | |
end | |
if ink.is_package_loaded 'vim-mucomplete' then | |
vim.g['mucomplete#buffer_relative_paths'] = 1 | |
vim.g['mucomplete#minimum_prefix_length'] = 0 | |
vim.g['mucomplete#cycle_all'] = 0 | |
-- inoremap <silent> <plug>(MUcompleteFwdKey) <right> | |
-- imap <right> <plug>(MUcompleteCycFwd) | |
-- inoremap <silent> <plug>(MUcompleteBwdKey) <left> | |
-- imap <left> <plug>(MUcompleteCycBwd) | |
vim.g['mucomplete#chains'] = { | |
default = {'omni', 'path', 'keyn', 'keyp', 'dict'}, | |
python = {'path', 'keyn', 'keyp', 'dict'}, | |
vim = {'path', 'cmd', 'keyn'}, | |
} | |
end | |
-- | |
-- GITGUTTER | |
-- | |
vim.g.gitgutter_sign_added = '┃' | |
vim.g.gitgutter_sign_modified = '┃' | |
vim.g.gitgutter_sign_removed = '_' | |
vim.g.gitgutter_sign_removed_first_line = '‾' | |
vim.g.gitgutter_sign_removed_above_and_below = '_' | |
vim.g.gitgutter_sign_modified_removed = '┃' | |
vim.g.gitgutter_terminal_reports_focus = 1 | |
-- | |
-- STATUSLINE | |
-- | |
vim.opt.statusline = '%<%f' | |
vim.opt.statusline:append('%w%h%m%r') | |
vim.opt.statusline:append(' %y') | |
vim.opt.statusline:append('%=%-14.(%l,%c,%o%) %p%% ') | |
vim.opt.statusline:append('%#StatusLineOk#%{v:lua.diagnostics_status()}') | |
vim.opt.statusline:append('%#StatusLineError#%{v:lua.diagnostics_errors()}') | |
vim.opt.statusline:append('%#StatusLineWarning#%{v:lua.diagnostics_warnings()}') | |
-- | |
-- CELLS | |
-- | |
local ink_cells = require 'ink_cells' | |
local ink_tmux = require 'ink_tmux' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment