Skip to content

Commit

Permalink
Move .vimrc to lua syntax and .config/nvim/lua/config
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-hanna committed Nov 26, 2021
1 parent 9048253 commit b809943
Show file tree
Hide file tree
Showing 8 changed files with 734 additions and 267 deletions.
6 changes: 6 additions & 0 deletions .config/nvim/ftplugin/elixir.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-- set comment_leader for elixir comments
vim.b.comment_leader = '#'

-- set the debug_cmd for elixir pry statements
vim.b.debug_cmd = 'require IEx; IEx.pry'

-- execute mix test on current file
vim.api.nvim_buf_set_keymap('0', 'n', '<leader>r', ':!time mix test % --color<CR>', { silent = true })

25 changes: 25 additions & 0 deletions .config/nvim/ftplugin/go.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

-- GoVet " vim-go compile go program

-- Linters
-- gosec - AST security
-- gofmt - formating
-- govet - compile bugs
-- godepth - depth complexity
-- staticcheck - simplification suggetsions

-- vim-go config
vim.g.go_def_mode = 'guru'
vim.g.go_code_completion_enabled = 0
vim.g.go_template_autocreate = 0

vim.g.go_alternate_mode = 'vsplit' -- TODO: set this to a hotkey

-- se. comment_leader for golang comments
vim.b.comment_leader = '// '

-- execute tests on current directory package,
-- ./ (dir) % (current filepath) p (path) . (reduce to relative) h (directory)
vim.api.nvim_set_keymap("n", "<leader>r", [[:!time go test -v ./%:p:.:h<CR>]])
-- autocmd BufWritePre *.go GoFmt " run vim-go GoFmt on save

3 changes: 3 additions & 0 deletions .config/nvim/ftplugin/lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ require'lspconfig'.sumneko_lua.setup {
},
},
}
require "lsp_signature".setup({
bind = true,
})


-- Give the test runner a keymap
Expand Down
7 changes: 2 additions & 5 deletions .config/nvim/ftplugin/scala.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
----------------------------------
-- LSP Setup ---------------------
----------------------------------
local metals_config = require("metals").bare_config
local metals_config = require("metals").bare_config()
metals_config.root_patterns = { "build.sbt" }

metals_config.settings = {
Expand All @@ -26,10 +26,7 @@ end

-- Start the LSP server
require("metals").initialize_or_attach(metals_config)
require("lspsaga").init_lsp_saga({
server_filetype_map = { metals = { "sbt", "scala" } },
code_action_prompt = { virtual_text = false },
})
require("lsp_signature").setup()

----------------------------------
-- Metals bindings ---------------
Expand Down
2 changes: 1 addition & 1 deletion .config/nvim/init.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let &packpath = &runtimepath
let g:python3_host_prog='~/.pyenv/versions/py3nvim/bin/python'

" it's nice having ~/.vimrc be fairly vanilla
source ~/.vimrc
" source ~/.vimrc

" Load the lua config
lua require('config')
176 changes: 171 additions & 5 deletions .config/nvim/lua/config.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
local Plug = vim.fn['plug#']

vim.call('plug#begin', '~/.vim/bundle')
-- --- Editing utility ---
Plug('godlygeek/tabular') -- align tables
Plug('tpope/vim-surround') -- git wrapper gblame
Plug('kana/vim-textobj-user') -- create custom vim text-objects
Plug('dense-analysis/ale') -- Asynchronous Lint Engine - runs prettier
Plug('hrsh7th/vim-vsnip') -- vscode like snippets
-- --- Prose and markdown ---
Plug('reedes/vim-pencil') -- text wrapping navigation
Plug('majutsushi/tagbar') -- ctag navigation split
Plug('lvht/tagbar-markdown') -- tagbar markdown support
Plug('junegunn/goyo.vim')
-- --- Git and File utility ---
-- Plug('/usr/local/opt/fzf') " import Homebrew fzf installation
-- Plug('junegunn/fzf.vim') " fzf function wrapper
Plug('tpope/vim-fugitive') -- git wrapper gblame
-- --- Visuals and syntax ---
Plug('ntpeters/vim-better-whitespace')
-- --- Ruby ---
-- --- Rust ---
Plug('simrat39/rust-tools.nvim')
Plug('saecki/crates.nvim', { branch = 'main' })
-- --- Python ---
-- --- Elixir ---
Plug('elixir-editors/vim-elixir') -- elixir syntax highlight
Plug('andyl/vim-textobj-elixir') -- make elixir blocks text-objects
-- --- GoLang ---
Plug('fatih/vim-go', { ['do'] = ':GoUpdateBinaries' }) -- GoLang editing improvments
-- --- React ---
Plug('maxmellon/vim-jsx-pretty') -- syntax highlighting for jsx
Plug('rstacruz/vim-closer') -- close '({[' for writing ES6
Plug('alvan/vim-closetag') -- close React component and HTML tags
-- --- Misc Formatting ---
-- Plug('hashivim/vim-terraform')
Plug('neovim/nvim-lspconfig')
Plug('nvim-treesitter/nvim-treesitter', {['do'] = ':TSUpdate'}) -- We recommend updating the parsers on update
Plug('mfussenegger/nvim-dap')
Plug('kevinhwang91/nvim-bqf', { branch = 'main' })
-- Plug('glepnir/lspsaga.nvim', { 'branch': 'main') }
Plug('ray-x/lsp_signature.nvim')
-- --- Scala ---
Plug('nvim-lua/plenary.nvim')
Plug('scalameta/nvim-metals', { branch = 'main' })
vim.call('plug#end')

local set = vim.opt
local cmd = vim.cmd
local g = vim.g
local function map(mode, lhs, rhs, opts)
Expand All @@ -12,6 +56,45 @@ local function map(mode, lhs, rhs, opts)
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end

g.mapleader = " "

----------------------------------
-- Vim settings ------------------
----------------------------------
cmd [[colorscheme apprentice]]
set.relativenumber = true
set.number = true

cmd [[highlight ColorColumn ctermbg=235]]
set.colorcolumn = '80'
set.hlsearch = false

set.expandtab = true
set.shiftwidth = 2
set.tabstop = 2
set.smartindent = true

set.swapfile = false
set.wildmenu = true
set.wildmode='longest:full,full'

local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")

-- leave insert mode quickly
-- https://stackoverflow.com/questions/13404602/how-to-prevent-esc-from-waiting-for-more-input-in-insert-mode/13485315#13485315
cmd [[
if ! has('gui_running')
set ttimeoutlen=10
augroup FastEscapeInsert
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
endif
]]

----------------------------------
-- Setup Plugins -----------------
----------------------------------
Expand All @@ -27,10 +110,93 @@ end
vim.opt_global.completeopt = { "menu", "noinsert", "noselect" }
vim.opt_global.shortmess:remove("F"):append("c")

-- LSP
----------------------------------
-- Normal bindings----------------
----------------------------------
map("n", "Q", [[<nop>]])

map("n", "<leader>e", [[:e <C-r>=expand("%:p:h") . '/'<CR>]], { silent = false })
-- Add visual comments based on the $comment_leader
-- - visual leader is mapped to \ by default
-- Comment out selected lines + format them
map("v", "<leader>fa", [[:s/^/\=b:comment_leader/g<CR>gv=]])
-- Uncomment selected lines (copied from StackOverflow = black magic) + format them
map("v", "<leader>fr", [[:s@\V<c-r>=escape(b:comment_leader,'\@')<cr>@@<cr>gv=]])

----------------------------------
-- Compiler and QFX --------------
----------------------------------
map("n", "~", [[:make<CR>]])
map("n", "]q", [[:lnext<CR>]])
map("n", "[q", [[:lprevious<CR>]])
map("n", "]Q", [[:cnext<CR>]])
map("n", "[Q", [[:cprev<CR>]])
map("n", "<leader>Q", [[:cclose<CR>]])
map("n", "]b", [[:bnext<CR>]])
map("n", "[b", [[:bprev<CR>]])

----------------------------------
-- LSP ---------------------------
----------------------------------
map("n", "K", [[<cmd>lua vim.lsp.buf.hover()<CR>]])
map("n", "gD", [[<cmd>lua vim.lsp.buf.definition()<CR>]])
map("n", "K", [[<cmd>lua require"lspsaga.hover".render_hover_doc()<CR>]])
map("n", "gi", [[<cmd>lua vim.lsp.buf.implementation()<CR>]])
map("n", "gr", [[<cmd>lua vim.lsp.buf.references()<CR>]])
map("n", "gds", [[<cmd>lua vim.lsp.buf.document_symbol()<CR>]])
map("n", "gws", [[<cmd>lua vim.lsp.buf.workspace_symbol()<CR>]])

-- load specific configurations based on filetype
-- - <r> running spec(s)
-- - comment leader
-- - <v> open rel spec file
-- TODO: move these to ftplugins
cmd [[
au BufRead,BufNewFile *.sbt,*.sc set filetype=scala
if !exists("autocommands_loaded")
let autocommands_loaded = 1
au Filetype ruby source ~/.vim/scripts/ruby.vim
au FileType sh,python let b:comment_leader = '# '
au FileType javascript,javascriptreact source ~/.vim/scripts/js.vim
au FileType typescript,typescriptreact source ~/.vim/scripts/js.vim
au FileType vim let b:comment_leader = '" '
au BufRead,BufNewFile *.tf* source ~/.vim/scripts/terraform.vim
au BufNewFile,BufRead *.bib set filetype=markdown " this sets syntax and ctag checking to markdown
endif
]]
-- au Filetype elixir source ~/.vim/scripts/elixir.vim
-- au Filetype go source ~/.vim/scripts/go.vim

----------------------------------
-- Ale ---------------------------
----------------------------------
g.ale_lint_on_text_changed = 'never' -- don't lint on a changed buffer
g.ale_lint_on_enter = 0 -- don't lint on file open
g.ale_linters_explicit = 1 -- only lint opt-in extensions
g.ale_fix_on_save = 1 -- run extension fixer on save only
g.ale_fixers = {
elixir = 'mix_format',
javascript = 'prettier',
javascriptreact = 'prettier',
typescript = 'prettier',
typescriptreact = 'prettier',
css = 'prettier',
}

----------------------------------
-- Vim-clostag vars --------------
----------------------------------
g.closetag_filetypes = 'html,xhtml,phtml,javascript,javascriptreact'
g.closetag_emptyTags_caseSensitive = 1

----------------------------------
-- Snippet mappings --------------
----------------------------------
cmd [[
imap <expr> <C-j> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-j>'
smap <expr> <C-j> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-j>'
imap <expr> <C-l> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<C-l>'
imap <expr> <C-k> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : "<C-k>"
smap <expr> <C-l> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<C-l>'
smap <expr> <C-k> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : "<C-k>"
]]
g.vsnip_snippet_dir = vim.fn.expand('~/.vim/snippets')
Loading

0 comments on commit b809943

Please sign in to comment.