Skip to content

Instantly share code, notes, and snippets.

@grahams
Created June 8, 2023 18:12
Show Gist options
  • Save grahams/13be4941dba2c2107e408d3007f59d23 to your computer and use it in GitHub Desktop.
Save grahams/13be4941dba2c2107e408d3007f59d23 to your computer and use it in GitHub Desktop.
" .vimrc
" Originally Jon Parise (jon@csh.rit.edu)
" Modified by Sean Graham (grahams@sean-graham.com)
" set encoding=utf-8
if file_readable(expand("~/.vimrc_local"))
source ~/.vimrc_local
endif
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
Plug 'sainnhe/edge'
Plug 'mattn/gist-vim'
Plug 'godlygeek/tabular'
Plug 'nelstrom/vim-docopen'
Plug 'takac/vim-hardtime'
Plug 'machakann/vim-highlightedyank'
Plug 'christoomey/vim-tmux-navigator'
Plug 'airblade/vim-gitgutter'
Plug 'sheerun/vim-polyglot'
Plug 'itchyny/lightline.vim'
Plug 'mileszs/ack.vim'
Plug 'maksimr/vim-jsbeautify'
Plug 'Lenovsky/nuake'
Plug 'pangloss/vim-javascript'
if (has("signs"))
Plug 'neomake/neomake'
endif
if has('nvim')
Plug 'github/copilot.vim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update
Plug 'neovim/nvim-lspconfig'
Plug 'glepnir/lspsaga.nvim', { 'branch': 'main'}
endif
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-characterize'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-markdown'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-speeddating'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
" Plug 'w0rp/ale'
" Plug 'Valloric/YouCompleteMe'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Add plugins to &runtimepath
call plug#end()
map  !par
" General configuration settings
"
set background=dark " dark background (as opposed to "light")
set backspace=2 " smarter backspace
set backupcopy=yes
set colorcolumn=80 " highlights the 80th column
set columns=80 " sets the number of columns displayed
set cpoptions=aABceF " vi compatibility options
set diffopt=filler,iwhite
set expandtab " expand tabs to spaces
set formatoptions=cqrt " options for "text format" ("gp")
set guioptions=aAce
set helpheight=0 " disable help
set joinspaces " insert two spaces after period when joining lines
set laststatus=2 " always show status line
set magic " use extended regexp in search patterns
set modeline " turn on the modeline
set modelines=1 " last line is the modeline
set noautoindent " turn autoindenting off
set nobackup " turn backups off
set nocompatible " turn off full vi compatibility
set noerrorbells " turn off error bells
set nohlsearch " turn off search result highlighting
set noignorecase " don't ignore case in search patterns
set noinsertmode " don't start vim in insertmode
set nolist " turn off extended character listing
set nonumber " don't number lines
set noruler " show cursor position
set noshowcmd " don't show incomplete commands
set nostartofline " don't jump to first char with page commands
set notitle " suppress title messages
set nowritebackup " don't write backups
set report=0 " show all changes
set shiftround " round indent to multiple of 'shiftwidth'
set shiftwidth=4 " number of spaces in each indent
set shortmess=atI " abbreviate all messages
set showmode " show the current mode
set softtabstop=4 " treat spaces as virtual tabs
set suffixes=.class " ignore filesnames with these suffixes
set t_vb= " turn off terminal's visual bell
set tabstop=4 " set the tab stop
set textwidth=76 " set the maximum text width
set visualbell " replace audible bells with visual bells
set wildchar=<TAB> " character used for command line expansion
set wrapmargin=5 " wrap from the right margin
if (has("termguicolors"))
let &t_8f = "[38;2;%lu;%lu;%lum"
let &t_8b = "[48;2;%lu;%lu;%lum"
set termguicolors
colorscheme edge
endif
" NeoVim-specific settings
if has('nvim')
set inccommand=split
tnoremap <Esc> <C-\><C-n>
"tnoremap <A-[> <Esc>
tnoremap <a-h> <c-\><c-n><c-w>h
tnoremap <a-j> <c-\><c-n><c-w>j
tnoremap <a-k> <c-\><c-n><c-w>k
tnoremap <a-l> <c-\><c-n><c-w>l
nnoremap <a-h> <c-w>h
nnoremap <a-j> <c-w>j
nnoremap <a-k> <c-w>k
nnoremap <a-l> <c-w>l
else
endif
if has("win32")
set guifont=Lucida_Console:h9
else
set guifont=Inconsolata:h16
endif
let mapleader=' '
" Shortcut to rapidly toggle "set list" and use Textmate symbols
nmap <leader>l : set list!<CR>
"set listchars=tab:▸\ ,eol:¬
nnoremap <leader>h <Esc>:call ToggleHardMode()<CR>
" Shortcuts to rapidly edit files in the directory containing the current
" open file. From: http://vimcasts.org/episodes/the-edit-command/
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%
" Nuake bindings
nnoremap <F4> :Nuake<CR>
inoremap <F4> <C-\><C-n>:Nuake<CR>
tnoremap <F4> <C-\><C-n>:Nuake<CR>
let g:nuake_position = 'top'
syntax on
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
map <C-L> :%!xmllint --format -<CR> :set filetype=xml<CR>
" Gist plugin settings
let g:gist_clip_command = 'pbcopy'
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
let g:gist_post_private = 1
" Neomake plugin settings
let g:neomake_javascript_enabled_makers = ['eslint']
" let g:neomake_python_enabled_makers = ['pyflakes']
" let g:neomake_open_list = 2
" let g:neomake_verbose=3
" let g:neomake_logfile='/tmp/error.log'
" Options to the Java Syntax file
let java_ignore_javadoc=1
let java_highlight_debug=1
" automatically rebalance windows on vim resize
autocmd VimResized * :wincmd =
" zoom a vim pane, <C-w>= to re-balance
nnoremap <leader>- :wincmd _<cr>:wincmd \|<cr>
nnoremap <leader>= :wincmd =<cr>
" Lightline
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [['mode', 'paste'],
\ ['gitbranch', 'filename', 'modified']],
\ 'right': [['lineinfo'],
\ ['fileformat', 'fileencoding', 'filetype'],
\ ['readonly', 'linter_warnings', 'linter_errors', 'linter_ok']]
\ },
\ 'component_expand': {
\ 'linter_warnings': 'LightlineLinterWarnings',
\ 'linter_errors': 'LightlineLinterErrors',
\ 'linter_ok': 'LightlineLinterOK'
\ },
\ 'component_type': {
\ 'readonly': 'error',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error'
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead'
\ },
\ }
function! LightlineLinterWarnings() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ◆', all_non_errors)
endfunction
function! LightlineLinterErrors() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ✗', all_errors)
endfunction
function! LightlineLinterOK() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '✓ ' : ''
endfunction
autocmd User ALELint call s:MaybeUpdateLightline()
" Update and show lightline but only if it's visible (e.g., not in Goyo)
function! s:MaybeUpdateLightline()
if exists('#lightline')
call lightline#update()
end
endfunction
" ack.vim/silver searcher integration
let g:ackprg = 'ag --vimgrep'
" formatprg bindings
if has("autocmd")
let pandoc_pipeline = "pandoc --from=html --to=markdown"
let pandoc_pipeline .= " | pandoc --from=markdown --to=html"
autocmd FileType html let &l:formatprg=pandoc_pipeline
let xml_pipeline = "xmllint --format -"
autocmd FileType xml let &l:formatprg=xml_pipeline
let json_pipeline = "python -m json.tool"
autocmd FileType json let &l:formatprg=json_pipeline
endif
if has("autocmd")
filetype on
filetype plugin on
autocmd FileType c,cpp,js,java,php,css,javascript set formatoptions=cqrto
\ cindent comments=sr:/*,mb:*,ex:*/,://
if has("neomake")
autocmd! BufWritePost,BufEnter * Neomake
endif
autocmd FileType js,javascript syntax on
" Treat .rss files as XML
autocmd BufNewFile,BufRead *.rss setfiletype xml
" Treat .ann files as XML
autocmd BufNewFile,BufRead *.ann setfiletype xml
" Treat .md files as Markdown (not Modula-2)
autocmd BufNewFile,BufReadPost *.md set filetype=markdown formatoptions=qro
" Enter hardmode by default
" autocmd VimEnter,BufNewFile,BufReadPost * silent! call HardMode()
" Syntax of these languages is fussy over tabs Vs spaces
autocmd FileType make setlocal ts=8 sts=8 sw=8 noexpandtab
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
" Customisations based on house-style (arbitrary)
" autocmd FileType html setlocal ts=2 sts=2 sw=2 expandtab
" autocmd FileType css setlocal ts=2 sts=2 sw=2 expandtab
" autocmd FileType javascript setlocal ts=4 sts=4 sw=4 noexpandtab
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment