Skip to content

Instantly share code, notes, and snippets.

@Kovrinic
Last active July 19, 2019 21:58
Show Gist options
  • Save Kovrinic/82d812e55312360c986f5a9ad4973e74 to your computer and use it in GitHub Desktop.
Save Kovrinic/82d812e55312360c986f5a9ad4973e74 to your computer and use it in GitHub Desktop.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Custom vim for Matthew, hey thats me
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" First Created: 02/05/2015
" Current Edit: 01/01/2017
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pathogen is an improved plugin manager for Vim
" http://www.bestofvim.com/plugin/pathogen/
"
" Change Pathogen runtime location.
" This get around problem with using symlinks across
" different OS's
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" syntax highlighting
syntax enable
" enable language-dependent indenting
filetype plugin indent on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Make backspace work again.
" When I removed NeoComplCache,
" backspace stopped working for some reason
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" http://vim.wikia.com/wiki/Backspace_and_delete_problems
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set backspace=indent,eol,start
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Indent automatically depending on filetype
filetype indent on
" Generic next-line match
set autoindent
" Setup colorscheme
set background=dark
"set background=light
colorscheme desert
"let g:solarized_termtrans = 1
"colorscheme solarized
" Turn on line numbering. Turn it off with "set nonu"
set nu
" Search as you type, highlight
set incsearch
set hlsearch
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Create <leader>gf binding,
" like gf but creating file if it doesn't exist.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" https://app.asana.com/0/2677909504410/8354666017829
" http://superuser.com/questions/277325/create-a-file-under-the-cursor-in-vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>gf :e <cfile><cr>
vmap <leader>gf "ay:e <C-r>a<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Indentation/Whitespace Visibility
" set list listchars=tab:»·,trail:·
set list listchars=tab:\ \ ,trail:·
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim command typos
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" http://blog.sanctum.geek.nz/vim-command-typos/
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("user_commands")
command! -bang -nargs=? -complete=file E e<bang> <args>
command! -bang -nargs=? -complete=file W w<bang> <args>
command! -bang -nargs=? -complete=file Wq wq<bang> <args>
command! -bang -nargs=? -complete=file WQ wq<bang> <args>
command! -bang Wa wa<bang>
command! -bang WA wa<bang>
command! -bang Q q<bang>
command! -bang QA qa<bang>
command! -bang Qa qa<bang>
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Allow saving of files as sudo when I forget to start vim using sudo.
" http://vim.wikia.com/wiki/Su-write
cmap w!! w !sudo tee % > /dev/null
" Matching parenthesis blink
set showmatch
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Whitespace Cleaning
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" http://www.bestofvim.com/tip/trailing-whitespace/
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Find Trailing Withespces and mark as an error
"
" function that automatically kills
" trailing whitespace when Vim writes
function! TrimWhiteSpace()
%s/\s\+$//e
endfunction
"
" <Leader>rtw will remove trailing whitespace.
" It can replace rtw with anything you want.
nnoremap <silent> <Leader>rts :call TrimWhiteSpace()<CR>
"
" On-Write triggers that call that function
autocmd FileWritePre * :call TrimWhiteSpace()
autocmd FileAppendPre * :call TrimWhiteSpace()
autocmd FilterWritePre * :call TrimWhiteSpace()
autocmd BufWritePre * :call TrimWhiteSpace()
"
" You can also enable that mapping
" on a per-filetype basis with:
" These are for example, uncomment and add own files
"autocmd FileType python,java autocmd FileWritePre * :call TrimWhiteSpace()
"autocmd FileType python,java autocmd FileAppendPre * :call TrimWhiteSpace()
"autocmd FileType python,java autocmd FilterWritePre * :call TrimWhiteSpace()
"autocmd FileType python,java autocmd BufWritePre * :call TrimWhiteSpace()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Auto reload vim
" http://www.bestofvim.com/tip/auto-reload-your-vimrc/
augroup reload_vimrc " {
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END " }
" Configure Vim to watch for changes in your .vimrc and automatically reload
" the config.
"augroup myvimrchooks
" au!
" autocmd bufwritepost .vimrc source ~/.vimrc
"augroup END
" Switch Off The Current Search
" http://www.bestofvim.com/tip/switch-off-current-search/
nnoremap <silent> <Leader>/ :nohlsearch<CR>
" Better Line Wraps
" http://www.bestofvim.com/tip/better-line-wraps/
set showbreak=↪
" Ctrl-P is a file-finder on overdrive.
" requires .vim lib in home directory
" http://www.bestofvim.com/plugin/ctrl-p/
" http://kien.github.io/ctrlp.vim/
set runtimepath^=~/.vim/bundle/ctrlp.vim
" Automatically inserts one extra level of indentation in some cases
" http://vim.wikia.com/wiki/Indenting_source_code
set smartindent
" Indentation purely with hard tabs
" http://vim.wikia.com/wiki/Indenting_source_code
set tabstop=2
set shiftwidth=2
" Insert space characters whenever the tab key is pressed
" http://vim.wikia.com/wiki/Converting_tabs_to_spaces
set expandtab
" Displaying status line always
" http://vim.wikia.com/wiki/Displaying_status_line_always
set laststatus=2
" Set the status line to the full file path name, change to "f" for file name only
set statusline+=%F
" Automatically change the current directory
" http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
set autochdir
" Using the mouse for Vim in an xterm
" http://vim.wikia.com/wiki/Using_the_mouse_for_Vim_in_an_xterm
" set mouse=a
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NERDTree plugin options
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" https://github.com/scrooloose/nerdtree/
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Open a NERDTree automatically when vim starts up
"autocmd vimenter * NERDTree
"
" Open a NERDTree automatically when vim
" starts up if no files were specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
"
" Shortcut to open NERDTree
map <C-n> :NERDTreeToggle<CR>
"
" Close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Syntax highlighting for samba files
au BufReadPost smb.conf.master set syntax=samba
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Diff On, Diff Off
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" http://www.bestofvim.com/tip/diff-diff/
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Set up a keymapping from <Leader>df to a function call.
" Note the function doesn't need to be defined beforehand.
" Run this mapping silently. That is, when I call this mapping,
" don't bother showing "call DiffToggle()" on the command line.
nnoremap <silent> <Leader>df :call DiffToggle()<CR>
"
" Define a function called DiffToggle.
" The ! overwrites any existing definition by this name.
function! DiffToggle()
if &diff
diffoff
else
diffthis
endif
:endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Better Commit Messages
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" http://www.bestofvim.com/tip/better-commit-messages/
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Git commits.
autocmd FileType gitcommit setlocal spell
"
" Subversion commits.
autocmd FileType svn setlocal spell
"
" Mercurial commits.
autocmd FileType asciidoc setlocal spell
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Gundo Plugin
" http://sjl.bitbucket.org/gundo.vim/#requirements
nnoremap <F5> :GundoToggle<CR>
" Markdown Support
" disable wrapping
let g:vim_markdown_folding_disabled=1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Latex-Suite
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" http://vim-latex.sourceforge.net/documentation/latex-suite/recommended-settings.html
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*
"
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
"
" TIP: if you write your \label's as \label{fig:something}, then if you
" type in \ref{fig: and press <C-n> you will automatically cycle through
" all the figure labels. Very useful!
set iskeyword+=:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Syntasic settins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" https://github.com/scrooloose/syntastic
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Note: Syntasic needs a syntax checker to be installed
" and in your path, i.e. flake8 or pylint. Also aliases
" do not work, the actual executalbe must be available in you $PATH
"
set statusline+=$warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
"
let g:syntastic_always_populate_loc_list=1
let g:syntastic_auto_loc_list=1
let g:syntastic_check_on_open=1
let g:syntastic_check_on_wq=0
let g:syntastic_mode_map={"mode": "passive"}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" python autocmd
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" http://stackoverflow.com/questions/18948491/running-python-code-in-vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType python nnoremap <buffer> <F9> :exec '!python' shellescape(@%, 1)<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment