Skip to content

Instantly share code, notes, and snippets.

@DoggettCK
Created Jun 27, 2018
Embed
What would you like to do?
New .vimrc until I get it in the main project
set nocompatible
syntax on
filetype plugin indent on
" Open splits to the bottom/right
set splitright
set splitbelow
" Package management
packadd minpac
call minpac#init()
" Update package manager itself
call minpac#add('k-takata/minpac', {'type': 'opt'})
" General
call minpac#add('tpope/vim-unimpaired') " Buffer/option toggling
call minpac#add('tpope/vim-obsession') " Session management
call minpac#add('mhinz/vim-grepper') " File search with ripgrep, ag, grep
call minpac#add('Raimondi/delimitMate') " Auto-close quotes/parens/brackets
call minpac#add('adelarsq/vim-matchit') " Better matching with '%'
call minpac#add('mattn/emmet-vim') " Expand CSS selector to HTML with <C-y>,
call minpac#add('scrooloose/nerdcommenter') " Easy commenting
call minpac#add('pbrisbin/vim-mkdir') " Ensure directory created before file save
call minpac#add('tpope/vim-abolish') " snake_case (crs) to MixedCase (crm) conversion
call minpac#add('tpope/vim-dispatch') " Async jobs
call minpac#add('radenling/vim-dispatch-neovim') " NVIM-specific async jobs
call minpac#add('tpope/vim-eunuch') " Unix command wrapper (:Delete, :SudoWrite, :Move)
call minpac#add('tpope/vim-repeat') " Repeat macros/complex plugin commands
call minpac#add('tpope/vim-surround') " Surround objects with chars using motions (e.g. ysiw')
call minpac#add('msanders/snipmate.vim') " Snippets
call minpac#add('tpope/vim-endwise') " Intelligently add 'end' to blocks
call minpac#add('kana/vim-textobj-user') " Custom text objects
" Git
call minpac#add('tpope/vim-fugitive') " Git commands
call minpac#add('tpope/vim-rhubarb') " Github commands
call minpac#add('airblade/vim-gitgutter') " Git status in left gutter
" UI
call minpac#add('vim-airline/vim-airline') " Better status line
call minpac#add('scrooloose/nerdtree') " File/directory tree
" Elixir
" TODO: Check out language server
call minpac#add('slashmili/alchemist.vim') " Elixir project helpers
call minpac#add('elixir-lang/vim-elixir') " Elixir support
call minpac#add('carlosgaldino/elixir-snippets') " Elixir snippets
call minpac#add('andyl/vim-textobj-elixir') " Elixir block motion support
" Ruby
call minpac#add('vim-ruby/vim-ruby') " Ruby support
call minpac#add('tpope/vim-rails') " Rails support
call minpac#add('kchmck/vim-coffee-script') " CoffeeScript support
call minpac#add('ngmy/vim-rubocop') " Rubocop support
call minpac#add('tpope/vim-rake') " Rake support
call minpac#add('nelstrom/vim-textobj-rubyblock') " Ruby block motion support
command! UpdatePackage call minpac#update()
command! CleanPackage call minpac#clean()
" Store undo files under $VIMDATA/undo, unless it's regular Vim
set undofile
if !has('nvim')
set undodir=~/.vim/undo
endif
augroup vimrc
autocmd!
" No undo files for /tmp directory, to prevent password manager caching
autocmd BufWritePre /tmp/* setlocal noundofile
" Reload .vimrc on write
autocmd BufWritePost .vimrc source %
" Remove trailing whitespace on save for Ruby/Elixir
autocmd BufWritePre *.rb,*.ex,*.exs :%s/\s\+$//e
" Wrap the quickfix window
autocmd FileType qf setlocal wrap linebreak
augroup END
" Generic settings
set nowrap
set hidden " Allow multiple buffers at the same time
set nobackup
set noswapfile
set number
set fixeol
set scrolloff=10
set sidescrolloff=20
set shiftwidth=2
set tabstop=2
set softtabstop=2
set nowrap
set autoindent
set copyindent
set smartindent
set shiftround
set ignorecase
set smartcase
set smarttab
set expandtab
set hlsearch
set incsearch
set numberwidth=5
set laststatus=2
set history=1000
set undolevels=1000
set novisualbell
set noerrorbells
set clipboard=unnamed
set lazyredraw
set showmatch
set enc=utf-8
set cursorline
set backspace=indent,eol,start
set whichwrap+=<,>,h,l,[,]
set t_Co=256
set updatetime=100
" Mappings
let mapleader=","
let maplocalleader="\\"
let g:grepper = {}
let g:grepper.tools = ['rg', 'ag', 'grep']
" Tab-switching
nmap <silent> <leader><Tab> ]b
nmap <silent> <leader><S-Tab> [b
" Save file
nnoremap <silent> <leader>s :w<CR>
" Close file
nnoremap <silent> <leader>w :bd!<CR>
" Unhighlight search
nnoremap <silent> <leader>h :nohlsearch<CR>
" Easy escape to normal mode
inoremap jf <Esc><Esc>
" Don't outdent hashes
inoremap # #
" Search for files with FZF
nnoremap <C-p> :<C-u>FZF<CR>
" Search for current word
nnoremap <Leader>f :Grepper<CR>
nnoremap <Leader>F :Grepper -cword -noprompt<CR>
" Search by motion (gf$, gfiw, gfa{, etc...)
nmap gf <plug>(GrepperOperator)
xmap gf <plug>(GrepperOperator)
" Alt + direction swaps windows
nnoremap <M-h> <C-w>h
nnoremap <M-j> <C-w>j
nnoremap <M-k> <C-w>k
nnoremap <M-l> <C-w>l
" Terminal-mode (NVIM) settings
if has('nvim')
" Different color for terminal mode cursor
highlight! TermCursorNC guibg=red guifg=white ctermbg=1 ctermfg=15
tnoremap <Esc> <C-\><C-n>
tnoremap jf <C-\><C-n>
tnoremap <C-v><Esc> <Esc>
" Alt + direction swaps windows
tnoremap <M-h> <C-\><C-n><C-w>h
tnoremap <M-j> <C-\><C-n><C-w>j
tnoremap <M-k> <C-\><C-n><C-w>k
tnoremap <M-l> <C-\><C-n><C-w>l
" Open a terminal with leader, then '|' or '-'
map <leader><bar> :vsplit \| terminal<CR>
map <leader>- :split \| terminal<CR>
augroup terminal_mode
autocmd!
" Don't set line numbers in terminal mode
autocmd TermOpen * setlocal nonumber
augroup END
endif
" Miscellaneous mappings
" Insert alphabet
nnoremap <leader>az aABCDEFGHIJKLMNOPQRSTUVWXYZ<ESC>
" Redact current word
nnoremap <leader>* Viwr*
" Make life easier by remapping ; to : for commands
nnoremap ; :
vnoremap ; :
" NERDCommenter settings
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" GitGutter settings
set signcolumn=yes
let g:gitgutter_highlight_lines=1
" Airline settings
let g:airline#extensions#tabline#enabled=1
" NERDTree settings
let NERDTreeIgnore=['vendor$', 'deps$', '.git$', '_build$']
nmap <silent> <leader>` :call g:WorkaroundNERDTreeToggle()<CR>
function! g:WorkaroundNERDTreeToggle()
try
NERDTreeToggle
catch
silent! NERDTree
endtry
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment