Created
June 10, 2022 19:02
-
-
Save andynu/cfd641ab396efc0fb13560dc4fd538b6 to your computer and use it in GitHub Desktop.
A neo-vim config.
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
" .config/nvim/init.vim | |
" Plugins | |
call plug#begin(stdpath('config') . '/plugins') | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'stevearc/aerial.nvim' | |
Plug 'tpope/vim-rails' | |
Plug 'tpope/vim-fugitive' | |
Plug 'tpope/vim-surround' | |
Plug 'tpope/vim-commentary' | |
Plug 'tpope/vim-sensible' | |
Plug 'tpope/vim-endwise' | |
Plug 'tpope/vim-eunuch' | |
Plug 'tpope/vim-sleuth' | |
Plug 'tpope/vim-vinegar' | |
Plug 'junegunn/goyo.vim' | |
Plug 'shumphrey/fugitive-gitlab.vim' | |
"Plug 'numkil/ag.nvim' " Ag command provided by fzf | |
Plug 'mileszs/ack.vim' " Ag command provided by fzf | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
Plug 'junegunn/fzf.vim' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'NLKNguyen/papercolor-theme' | |
Plug 'morhetz/gruvbox' | |
Plug 'nathanaelkane/vim-indent-guides' | |
Plug 'joeytwiddle/git_shade.vim' | |
Plug 'mbbill/undotree' | |
Plug 'vim-scripts/Align' | |
Plug 'vim-scripts/TVO--The-Vim-Outliner' | |
Plug 'w0rp/ale' | |
Plug 'junkblocker/git-time-lapse' | |
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update | |
Plug 'jpalardy/vim-slime' | |
Plug 'kchmck/vim-coffee-script' | |
Plug 'vim-ruby/vim-ruby' | |
Plug 'vim-utils/vim-ruby-fold' | |
Plug 'hrsh7th/cmp-nvim-lsp' | |
Plug 'hrsh7th/cmp-buffer' | |
Plug 'hrsh7th/cmp-look' | |
Plug 'hrsh7th/nvim-cmp' | |
" Tag listing | |
Plug 'preservim/tagbar' | |
call plug#end() | |
" Open new split panes to right and bottom, which feels more natural | |
set splitbelow | |
set splitright | |
set modeline | |
set termguicolors | |
" [buffer number] followed by filename: | |
set statusline=[%n]\ %t | |
" for Syntastic messages: | |
set statusline+=%#warningmsg# | |
"set statusline+=%{SyntasticStatuslineFlag()} | |
set statusline+=%* | |
" show line#:column# on the right hand side | |
set statusline+=%=%l:%c | |
" nmap <F8> :TagbarToggle<CR> | |
nmap ,t :TagbarToggle<CR> | |
" buffer switching/paging | |
map \e <Esc>:e#<CR> | |
map \E <Esc>:w<CR>:e#<CR> | |
nmap <C-n> <Esc>:next<CR> | |
nmap <C-p> <Esc>:prev<CR> | |
" quicklist paging (vimgrep, grep) | |
map qh <Esc>:cp<CR> | |
map ql <Esc>:cn<CR> | |
" move cursor up/down one char regardless of wordwrap | |
" WARNING: nvim is too quick and/or has a bug, because these can cause | |
" interleaving that result in lines being joined. | |
" map j gj | |
" map k gk | |
" Duplicate a visual selection | |
vmap D y'>p | |
" tags | |
map tf :tfirst<CR> | |
map th :tprevious<CR> | |
map tl :tnext<CR> | |
map ts :tselect<CR> | |
" tabs | |
map tt :tabnew<CR> | |
map tc :tabclose<CR> | |
map tn :tabnext<CR> | |
map tp :tabprevious<CR> | |
map \h <Esc>:set hlsearch!<CR> | |
"nmap \k :!perl -c %<CR> | |
nmap \r :!ruby %<CR> | |
nmap \R :!./%<CR> | |
"nmap \g :GoRun %<CR> | |
" show line numbers | |
map \l <Esc>:set number!<CR>:set number?<CR> | |
map \L <Esc>:set relativenumber!<CR>:set relativenumber?<CR> | |
nmap \s :vertical resize 30<CR> | |
nmap \S :vertical resize 60<CR> | |
map \v <Esc>:vertical resize 80<CR> | |
map \V <Esc>:vertical resize 100<CR> | |
map \o <Esc>:set paste!<CR>:set paste?<CR> | |
map \w <Esc>:set wrap!<CR>:set wrap?<CR> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" commands " | |
"""""""""""" | |
" quick timestamp-as-comment command | |
command! DS r!echo -n "\# " ; date | |
command! TS r!date +'\%Y-\%m-\%d \%H:\%M \%a' | |
command! Trim :%s#\s*\r\?$## | |
command! Chomp %!sed 's/[ \t]*$//' | |
command! StripHTML %s/<[^>]*>//g | |
command! SingleQuote s/"/'/g | |
command! StripFontTags %s/<\/*font[^>]*>//g | |
command! StripColor %s/\x1b\[[0-9;]*m//g | |
"command! StripTables %s/<\/*table[^>]*>//gi<CR><ESC>%s/<\/*tr[^>]*>//gi<CR><ESC>%s/<\/*td[^>]*>//gi<CR><ESC> | |
command! StripComments %!sed -e :a -e 's/[ \t]*\#.*$//mg' | |
command! StripBlankLines %s/^[\ \t]*\n//g | |
command! Doublespace :g/^/put_ | |
command! Ctags :!ctags -R | |
command! Focus :Goyo | |
command! PLight :colo PaperColor|set background=light | |
command! PDark :colo PaperColor|set background=dark | |
command! GDark :colo gruvbox|set background=dark | |
command! GLight :colo gruvbox|set background=light | |
command! Light :colo PaperColor|set background=light | |
command! Dark :colo gruvbox|set background=dark | |
command! -nargs=1 -complete=file S wa|mksession! ~/.vs/<args>.vim | |
command! -nargs=1 -complete=file SQ wa|mksession! ~/.vs/<args>.vim|qa | |
command! -nargs=1 L source ~/.vs/<args>.vim | |
" Eh... not quite. Does not work. | |
" command! -nargs=1 AnsibleRole !mkdir -p roles/<args>/tasks<CR>e roles/<args>/tasks/main.yml | |
command! -nargs=0 Vimrc source ~/.vimrc | |
command! Vt set textwidth=80|e ' $(ruby -rdate -e 'puts Date.today') |DS|a | |
command! Rfluff cexpr system('rfluff -qf ' . shellescape(expand('%:r')))|:cw | |
function! OpenLeft(other_proj) | |
let current_path=@% | |
let other_path=join(["../",a:other_proj,"/",current_path],'') | |
execute "vsplit " . other_path | |
endfunction | |
function! DiffLeft(other_proj) | |
let current_path=@% | |
let other_path=join(["../",a:other_proj,"/",current_path],'') | |
execute "vsplit " . other_path | |
execute "windo diffthis" | |
endfunction | |
command! -nargs=1 OL call OpenLeft(<q-args>) | |
command! -nargs=1 DL call DiffLeft(<q-args>) | |
command! -nargs=0 OT call OpenLeft("rails_template") | |
command! -nargs=0 DT call DiffLeft("rails_template") | |
"command! -nargs=0 ORT call OpenLeft("rails_template") | |
map <C-s> <Esc>:FZF<CR> | |
" I always, ALWAYS hit ":W" instead of ":w" | |
command! Q q | |
command! W w | |
command! Wq wq | |
command! Wqa wqa | |
nmap ; :Buffers<CR> | |
nmap <Leader>t :Tags<CR> | |
nmap \f :Files<CR> | |
if executable('ag') | |
let g:ackprg = 'ag --vimgrep --smart-case' | |
endif | |
" cnoreabbrev ag Ack | |
" cnoreabbrev aG Ack | |
" cnoreabbrev Ag Ack | |
" cnoreabbrev AG Ack | |
noremap <leader>a :Ack <cword><cr> | |
" Ale warning navigation. | |
" This uses the loclist by default: :Errors :lnext :lne / :lprevious :lpr | |
nmap <silent> <C-k> <Plug>(ale_previous_wrap) | |
nmap <silent> <C-j> <Plug>(ale_next_wrap) | |
nnoremap ]r :ALENextWrap<CR> | |
nnoremap [r :ALEPreviousWrap<CR> | |
nnoremap ,f :ALEFix<CR> | |
let mapleader = '\' | |
let maplocalleader = ',' | |
set foldlevel=0 | |
"-------------------------------------------------------------------------------- | |
" nvim-cmp Plugin Settings | |
set completeopt=menu,menuone,noselect | |
" Plugin config: shumphrey/fugitive-gitlab | |
let g:fugitive_gitlab_domains = ['https://git.wi.mit.edu'] | |
" Basic color scheme | |
colo pablo | |
" Plugin config: morhetz/gruvbox | |
colo gruvbox | |
"set bg=light | |
set bg=dark | |
" Plugin config; nathanaelkane/vim-indent-guides | |
"let g:indent_guides_enable_on_vim_startup = 1 | |
map \i :IndentGuidesToggle<CR> | |
" Plugin Ale Config {{{ | |
let g:ale_sign_error = '! ' | |
let g:ale_sign_warning = 'w ' | |
let g:ale_emit_conflict_warnings=0 | |
let g:ale_ruby_rubocop_options = '--config ~/.rubocop.yml' | |
let g:ale_use_global_executables=1 | |
let g:ale_fixers = { 'ruby': [ 'prettier', 'rubocop' ] } | |
let g:ale_fix_on_save = 0 | |
let g:ale_javascript_prettier_options = '--single-quote --trailing-comma es5' | |
let g:ale_python_mypy_options = '--python-version 3.7' | |
" set to never if linting only on save. | |
let g:ale_lint_on_text_changed = 'never' | |
" You can disable this option too | |
" " if you don't want linters to run on opening a file | |
" let g:ale_lint_on_enter = 0 | |
let g:ale_echo_msg_error_str = 'E' | |
let g:ale_echo_msg_warning_str = 'W' | |
let g:ale_echo_msg_format = '[%linter%] %s [%severity%] (%code%)' | |
" }}} | |
let g:slime_target = "tmux" | |
let g:slime_default_config = {"socket_name": "default", "target_pane": "{last}"} | |
"================================================================================ | |
" LUA CONFIG | |
"-------------------------------------------------------------------------------- | |
lua << EOF | |
local nvim_lsp = require('lspconfig') | |
local aerial = require'aerial' | |
-- Setup nvim-cmp. | |
local cmp = require'cmp' | |
cmp.setup({ | |
snippet = { | |
expand = function(args) | |
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. | |
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. | |
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. | |
-- require'snippy'.expand_snippet(args.body) -- For `snippy` users. | |
end, | |
}, | |
mapping = { | |
['<C-d>'] = cmp.mapping.scroll_docs(-4), | |
['<C-f>'] = cmp.mapping.scroll_docs(4), | |
['<C-Space>'] = cmp.mapping.complete(), | |
['<C-e>'] = cmp.mapping.close(), | |
['<CR>'] = cmp.mapping.confirm({ select = true }), | |
}, | |
sources = cmp.config.sources({ | |
{ name = 'nvim_lsp' }, | |
}, { | |
{ name = 'buffer' }, | |
}) | |
}) | |
-- Setup lspconfig. | |
local cmp_capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) | |
-- Use an on_attach function to only map the following keys | |
-- after the language server attaches to the current buffer | |
local custom_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) | |
-- beginAerial additions | |
aerial.on_attach(client) | |
-- Aerial does not set any mappings by default, so you'll want to set some up | |
-- Toggle the aerial window with <leader>a | |
vim.api.nvim_buf_set_keymap(0, 'n', ',a', '<cmd>AerialToggle!<CR>', {}) | |
-- Jump forwards/backwards with '{' and '}' | |
vim.api.nvim_buf_set_keymap(0, 'n', '{', '<cmd>AerialPrev<CR>', {}) | |
vim.api.nvim_buf_set_keymap(0, 'n', '}', '<cmd>AerialNext<CR>', {}) | |
-- Jump up the tree with '[[' or ']]' | |
vim.api.nvim_buf_set_keymap(0, 'n', '[[', '<cmd>AerialPrevUp<CR>', {}) | |
vim.api.nvim_buf_set_keymap(0, 'n', ']]', '<cmd>AerialNextUp<CR>', {}) | |
-- end Aerial additions | |
end | |
-- Use a loop to conveniently call 'setup' on multiple servers and | |
-- map buffer local keybindings when the language server attaches | |
-- local servers = { "pyright", "rust_analyzer", "tsserver" } | |
local servers = { "solargraph" } | |
for _, lsp in ipairs(servers) do | |
nvim_lsp[lsp].setup { | |
on_attach = custom_on_attach, | |
capabilities = cmp_capabilities, | |
flags = { | |
debounce_text_changes = 150, | |
} | |
} | |
end | |
-- treesitter config | |
require'nvim-treesitter.configs'.setup { | |
highlight = { | |
enable = true | |
}, | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment