Skip to content

Instantly share code, notes, and snippets.

@petdance
Created August 20, 2019 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petdance/a203b3ed2fac2575119f0eccc609ee75 to your computer and use it in GitHub Desktop.
Save petdance/a203b3ed2fac2575119f0eccc609ee75 to your computer and use it in GitHub Desktop.
My ~/.vim/vimrc
"============================================================================
" General settings
"----------------------------------------------------------------------------
set nocompatible " nocp: turn off vi compatibility
set undolevels=1000 " ul: lots and lots of undo
set history=50 " hi: size of :command history
set modelines=20
set modeline " ml: Turn on modelines
set backup " keep a backup file
set ruler " show the cursor position all the time
filetype on
syntax on
syntax sync fromstart " This is a kludge until we figure out why syntax highlighting breaks so easily in 8.0.
"============================================================================
" Colors
"----------------------------------------------------------------------------
set t_Co=256 " Enable 256 colors
set t_Sf=[3%dm " set foreground (?)
set t_Sb=[4%dm " set background (?)
colorscheme mine
"============================================================================
" Presentation
"----------------------------------------------------------------------------
set shortmess=aIoO " sm: really short messages, don't show intro
set showmode " smd: show the current input mode
set more " more: page on extended output
set errorbells " eb: ring bell on error messages
set novisualbell " novb: turn off visual bell
set noequalalways " noea: don't always keep windows at equal size
set splitbelow " sb: splitted window appears below current one
set report=1 " Show line count if >1 line is yanked.
"set diffopt=iwhite
" Line numbers in the left gutter
if v:version >= 703
set relativenumber " Show relative numbers down the left gutter
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
if v:version >= 704
set number " Show absolute number on the current line
highlight CursorLineNr term=bold cterm=NONE ctermfg=Yellow ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
endif
endif
" Highlight current line
"set cursorline
"highlight CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
"============================================================================
" Statusline, Ruler
"----------------------------------------------------------------------------
set laststatus=2 " ls: always put a status line
"============================================================================
" Filename Autocompletion
"----------------------------------------------------------------------------
set wildchar=<Tab> " wc: tab does autocompletion
"set wildmode=longest,list " wim: bash-style autocompletion
set wildmode=list:longest,list:full
" wig: when autocompleting, ignore certain files
set wildignore=*~,#*#,*.sw?,*.o,*.class,.viminfo,*.pdf,*.mp3,*.gz,*.tgz,*.gif,*.jpg,*.png
"============================================================================
" Search and Replace
"----------------------------------------------------------------------------
set incsearch " is: show partial matches as search is entered
set hlsearch " hls: highlight search patterns
set ignorecase " Ignore case distinction when searching
set smartcase " ... unless there are capitals in the search string.
"set nowrapscan " Don't wrap to top of buffer when searching
"============================================================================
" Tab standards
"----------------------------------------------------------------------------
set smarttab
set softtabstop=4
set shiftwidth=4
set shiftround " Shift to the next round tab stop
set expandtab
" Load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
set autoindent
set cindent
" Make p in Visual mode replace the selected text with the "" register.
vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>
" https://superuser.com/questions/196055/how-to-replace-vim-screen-buffer-with-previous-bash-activity-after-quitting
" https://stackoverflow.com/questions/29169716/keeping-view-of-edited-file-after-exiting-vim
behave xterm
"============================================================================
" Autocommands
"----------------------------------------------------------------------------
" For all text files set 'textwidth' to 78 characters.
au FileType text setlocal tw=78
au FileType perl set makeprg=perl\ -c\ %\ $*
au FileType perl set errorformat=%f:%l:%m
au FileType perl set autowrite
au FileType perl :noremap K :!perldoc <cword> <bar><bar> perldoc -f <cword><cr>
" http://vimdoc.sourceforge.net/htmldoc/vimfaq.html
" 5.5. How do I configure Vim to open a file at the last edited location?
" Vim stores the cursor position of the last edited location for each buffer
" in the '"' register. You can use the following autocmd in your .vimrc or
" .gvimrc file to open a file at the last edited location:
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
au FileType vim set iskeyword+=. iskeyword+=/ iskeyword+=~
au FileType perl set iskeyword+=^: " So we don't see :: separators as part of function names.
" Perl-specific settings
"let perl_fold=1
let perl_nofold_packages=0 " Turning this on makes things very slow until @hoelzro fixes things
let perl_include_pod=1
" syntax color complex things like @{${"foo"}}
let perl_extended_vars=1
" let perl_pod_formatting=1 " Doesn't handle F<>, L<> or C<> properly.
" https://github.com/vim-perl/vim-perl/issues/241
" PHP-specifics
"let php_sql_query = 0
"let php_htmlInStrings = 1
"let php_baselib = 1
let g:PHP_default_indenting = 0
let g:PHP_vintage_case_default_indent = 1
au BufNewFile * silent! 0r ~/.vim/templates/%:e.tpl
set showmatch " show matches on parens, bracketc, etc.
set matchpairs+=<:>
" Folding
set foldmethod=marker
set nofoldenable
set background=dark
" Set visible tabs and trailing spaces.
exec "set listchars=tab:\\|-,trail:\uB7"
set list
set tags=./tags,./Tags,tags,../tags,../../tags,Tags,./Tags,../../Tags
set backspace=indent,eol,start
set scrolloff=3 " Always show at least 3 lines above/below cursor.
set lazyredraw
" Stop the annoying behavior of leaving comments on far left
set fo+=r
" Don't do the auto-highlighting
" From :help matchparen
let loaded_matchparen=1
" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.ln
" Paths to check for loading files with "gf"
set path=.,..,~/tw/**
"============================================================================
" Abbreviations, insert mode only
"----------------------------------------------------------------------------
iab wdd {use Data::Dumper; local $Data::Dumper::Sortkeys=1; warn Dumper()}<left><left>
iab udd {use Data::Dumper; local $Data::Dumper::Sortkeys=1; print Dumper()}<left><left>
iab ddd {use Data::Dumper; local $Data::Dumper::Sortkeys=1; diag Dumper()}<left><left>
iab wds {use Data::Show; show();}<left><left><left>
iab tudd [% USE Dumper; Dumper.dump_html() %]<left><left><left><left>
iab ltbl local $Test::Builder::Level = $Test::Builder::Level + 1;
iab rsss return subtest subtest_name() => sub {
iab asc $agent->save_content('foo.html');
iab dasc die $agent->save_content('foo.html');
iab dpsc die $page->save_content('foo.html');
iab shfit shift
iab cac <commandname>ack</commandname>
iab farc <filename>.ackrc</filename>
set secure
"============================================================================
" Key remapping
"----------------------------------------------------------------------------
" Shift-H goes to beginning.
" Shift-L to the end
noremap <silent> H :call FirstCharOrFirstCol()<cr>
noremap L $
function! FirstCharOrFirstCol()
let current_col = virtcol('.')
normal! ^
let first_char = virtcol('.')
if current_col <= first_char
normal! 0
endif
endfunction
vmap ff :!fmt -w75<CR>
vmap fw :!fw 120<CR>
vmap cc :!comment-sentence<CR>
vmap qq :!qq<CR>
vmap nn :s/\%u200b//g<CR>
" Make tab in visual mode indent code.
vmap <tab> >gv
vmap <s-tab> <gv
" Make double-<Esc> clear search highlights
nnoremap <silent> <Esc><Esc> <Esc>:nohlsearch<CR><Esc>
" Rob's syntax debugger from https://gist.github.com/hoelzro/bfcd6bc08fb0941e85347579404a29dc
function! DumpSynStack()
for id in synstack(line("."), col("."))
echo synIDattr(id, "name")
endfor
endfunction
map <F5> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
map <F6> :call DumpSynStack()<CR>
" Call ack
nnoremap <leader>g :Grepper -tool ack<CR>
" ack for word under cursor
nnoremap <leader>* :Grepper -tool ack -cword<CR>
" Keep selected text selected when fixing indentation. From https://kinbiko.com/vim/my-shiniest-vim-gems/
vnoremap < <gv
vnoremap > >gv
" Let ctrl-direction work in insert mode.
inoremap <C-h> <C-o>h
inoremap <C-j> <C-o>j
inoremap <C-k> <C-o>k
inoremap <C-l> <C-o>l
"============================================================================
" vim-plug plugins
"============================================================================
" silent because some machines may not have Git installed.
silent! call plug#begin( '~/.vim/plugged' )
Plug 'chr4/nginx.vim'
Plug 'google/vim-searchindex'
Plug 'jlanzarotta/bufexplorer'
Plug 'kien/ctrlp.vim'
Plug 'pangloss/vim-javascript'
Plug 'tpope/vim-liquid'
Plug 'tpope/vim-unimpaired'
Plug 'junegunn/vim-easy-align'
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
Plug 'tpope/vim-fugitive'
Plug 'andymass/vim-matchup'
hi MatchParen ctermbg=red cterm=bold
Plug 'elzr/vim-json'
let g:vim_json_syntax_conceal = 0
Plug 'mileszs/ack.vim'
" Ack for word under the cursor
" nnoremap * :Ack '\b<c-r><c-w>\b'<cr>
Plug 'mhinz/vim-startify'
let g:startify_custom_header = []
let g:startify_change_to_dir = 0
let g:startify_update_oldfiles = 0
let g:startify_files_number = 50
let g:startify_lists = [
\ { 'type': 'files', 'header': [ 'MRU'] },
\ ]
Plug 'mhinz/vim-signify'
let g:signify_vcs_list = [ 'git', 'svn' ]
let g:signify_realtime = 0
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
let g:airline_theme='cobalt2'
call plug#end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment