small pixel drawing of a pufferfish dotfiles

init.vim -> init.lua
Jes Olson j3s@c3f.net
Sun, 19 Feb 2023 16:50:15 -0800
commit

7d0b920bc9c866f696072137981afae2f2988e67

parent

4c9dd17079e846e08c5ba41a478e65d078067f80

2 files changed, 66 insertions(+), 122 deletions(-)

jump to
A .config/nvim/init.lua

@@ -0,0 +1,66 @@

+local use = require('packer').use +require('packer').startup(function() + use 'wbthomason/packer.nvim' -- Package manager + use 'neovim/nvim-lspconfig' -- Configurations for Nvim LSP + use 'sainnhe/everforest' -- Colorscheme + + -- Very powerful search + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.1', + requires = { {'nvim-lua/plenary.nvim', 'BurntSushi/ripgrep'} } + } +end) + +vim.cmd('colorscheme everforest') -- solarized, but green +vim.cmd('set termguicolors') -- needed for truecolor support +vim.cmd('set mmp=2000') -- resolves https://github.com/vim/vim/issues/2049 + +-- Mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap=true, silent=true } +vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) +vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts) +vim.keymap.set('n', '<space>m', "Go<esc>:put =strftime('%Y-%m-%d')<cr>o============<cr>", opts) + +-- auto-format on save +vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.formatting_sync()]] + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + -- Enable completion triggered by <c-x><c-o> + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', '<space>wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts) +end + +---- golang +require('lspconfig')['gopls'].setup{ + on_attach = on_attach, +} +-- organize golang imports on save +vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.go', + callback = function() + vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true }) + end +})
D .config/nvim/init.vim

@@ -1,122 +0,0 @@

-call plug#begin() -Plug 'junegunn/vim-easy-align' -Plug 'neovim/nvim-lspconfig' -Plug 'nvim-lua/plenary.nvim' " lua funcs i guess -Plug 'hrsh7th/nvim-compe' -Plug 'ctrlpvim/ctrlp.vim' -Plug 'cormacrelf/vim-colors-github' -Plug 'dewyze/vim-tada' -Plug 'tidalcycles/vim-tidal' -call plug#end() - -colorscheme github -set termguicolors " required for truecolor support - -" idk, this resolved the following weirdness: -" https://github.com/vim/vim/issues/2049 -set mmp=2000 - -lua << EOF -require'lspconfig'.gopls.setup{} -require'lspconfig'.terraformls.setup{} -EOF - -" set keybinds for go LSP - warning: disgusting -lua << EOF -local nvim_lsp = require('lspconfig') - --- Use an on_attach function to only map the following keys --- after the language server attaches to the current buffer -local on_attach = function(client, 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') - - -- Mappings. - local opts = { noremap=true, silent=true } - - -- See `:help vim.lsp.*` for documentation on any of the below functions - 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', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) - buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) - buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) - buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) - buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) - buf_set_keymap('n', '<space>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', '<space>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', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) - buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) -end - --- Use a loop to conveniently call 'setup' on multiple servers and --- map buffer local keybindings when the language server attaches -local servers = { "gopls", "terraformls" } -for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup { on_attach = on_attach } -end -EOF - -" golang imports setup (ugh, sorry) -lua <<EOF - -- … - - function go_org_imports(wait_ms) - local params = vim.lsp.util.make_range_params() - params.context = {only = {"source.organizeImports"}} - local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, wait_ms) - for cid, res in pairs(result or {}) do - for _, r in pairs(res.result or {}) do - if r.edit then - local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16" - vim.lsp.util.apply_workspace_edit(r.edit, enc) - end - end - end - end -EOF - -autocmd BufWritePre *.go lua go_org_imports() - -" tabstops for my langs -autocmd FileType sh setlocal et ts=4 sw=4 -autocmd FileType python setlocal et ts=4 sw=4 -autocmd FileType go setlocal noet ts=4 sw=4 -autocmd FileType ruby setlocal et ts=2 sw=2 -autocmd FileType terraform setlocal et ts=2 sw=2 -autocmd FileType text setlocal tw=80 -autocmd FileType html setlocal et ts=2 sw=2 -autocmd FileType yaml setlocal et ts=2 sw=2 -autocmd FileType mail setlocal noautoindent -augroup filetypedetect - autocmd BufRead,BufNewFile *mutt-* setfiletype mail -augroup filetypedetect -autocmd FileType json setlocal et ts=2 sw=2 -" markdown auto-wrapping per -" https://vi.stackexchange.com/questions/9421/how-to-make-formatoptions-a-useful -autocmd FileType markdown set fo+=aw -autocmd FileType markdown setlocal tw=80 et ts=2 sw=2 - -" terraform ft detection -" vint: -ProhibitAutocmdWithNoGroup -" By default, Vim associates .tf files with TinyFugue - tell it not to. -silent! autocmd! filetypedetect BufRead,BufNewFile *.tf -autocmd BufRead,BufNewFile *.hcl set filetype=hcl -autocmd BufRead,BufNewFile .terraformrc,terraform.rc set filetype=hcl -autocmd BufRead,BufNewFile *.tf,*.tfvars set filetype=terraform -autocmd BufRead,BufNewFile *.tfstate,*.tfstate.backup set filetype=json - -" bindings -let mapleader = "," -nmap <leader>m Go<esc>:put =strftime(\"%Y-%m-%d\")<cr>o----------------<cr><esc> - -" use neovim's own terminal instead of tmux: -let g:tidal_target = "terminal"