Skip to content

Instantly share code, notes, and snippets.

@jamezpolley
Created May 4, 2011 01:56
Show Gist options
  • Save jamezpolley/954615 to your computer and use it in GitHub Desktop.
Save jamezpolley/954615 to your computer and use it in GitHub Desktop.
my .vimrc
" Things that need no explanation
set nocompatible
syntax on
set background=dark
" Tweaks to help mousiness work in normal vim inside an xterm.
set mouse=a
set ttymouse=xterm2
" Attempt to get sane indenting:
set autoindent
set shiftwidth=2
set tabstop=2
set expandtab " Make sure that ^T, <<, >>, and the like use spaces.
set cinoptions=l1,g0.5s,h0.5s,i2s,+2s,(0,W2s
" Don't mess with my terminal unless I tell you to!
set notitle
set norestorescreen
" Nice helper stuff:
set showmode
set showmatch
set ruler
set showcmd
set incsearch
set hlsearch " Highlight previous search results
set backspace=2
" Make it so that tabs and trailing spaces are always visible:
" (Relys on syntax highlighting to turn them yellow.)
set list
set listchars=tab:..,trail:\ ,extends:»,precedes:«
" So we can see tabs and trailing spaces.
hi SpecialKey ctermbg=Yellow guibg=Yellow
filetype plugin indent on
" Highlight lines > 80 chars
function! HighlightTooLongLines()
highlight def link RightMargin Error
if &textwidth != 0
exec 'match RightMargin /\%<' . (&textwidth + 4) . 'v.\%>' . (&textwidth + 2) . 'v/'
endif
endfunction
augroup filetypedetect
au BufNewFile,BufRead * call HighlightTooLongLines()
augroup END
" Clever tab - if at start of line insert spaces; else complete word.
function! CleverTab()
if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
return "\<Tab>"
else
return "\<C-X>\<C-N>"
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>
" Tab-complete filenames to longest unambiguous match and present menu:
set wildmenu wildmode=longest:full
:au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif
autocmd BufWrite mytips :helptags ~/.vim/doc/
autocmd BufRead mytips set filetype=help
autocmd BufRead mytips set noreadonly
autocmd BufRead mytips set modifiable
nmap <leader>h :tabnew ~/.vim/doc/mytips<CR>
set secure " Don't allow FS modifications in CWD .vimrc/.exrc.
" Turn on word-wrapping.
map gw :se tw=75<CR>
" Get rid of trailing whitespace.
map gc :%s/[ <Tab>]\+$//<CR>
" Fix paragraph movement ('{' and '}') to ignore whitespace.
" (This mostly works correctly, except when used in selection ('V') mode,
" where the last search is changed.)
nmap { ?\S?;?^\s*$<CR>:call histdel("search", -1)<CR>:let @/ = histget("search", -1)<CR>:nohlsearch<CR>:<CR>
omap { ?\S?;?^\s*$<CR>:call histdel("search", -1)<CR>:let @/ = histget("search", -1)<CR>:nohlsearch<CR>:<CR>
vmap { ?\S?;?^\s*$<CR>
nmap } /\S/;/^\s*$<CR>:call histdel("search", -1)<CR>:let @/ = histget("search", -1)<CR>:nohlsearch<CR>:<CR>
omap } /\S/;/^\s*$<CR>:call histdel("search", -1)<CR>:let @/ = histget("search", -1)<CR>:nohlsearch<CR>:<CR>
vmap } /\S/;/^\s*$<CR>
" rst heading helper
let @h = "yypVr"
" select xml text to format and hit ,x
vmap ,x :!tidy -q -i -xml<CR>
" select html text to format and hit ,h
vmap ,h :!tidy -q -i<CR>
"" Don't put comments on the left-margin
inoremap # #
" Inspired by https://gist.github.com/954432
" pay attention to modelines, so i can deal with different tab conventions
" more easily.
set modeline
set modelines=5
"I hold shift down too long when i hit :w...
command W :w
command Wq :wq
command WQ :wq
command Q :q
"---------------------------------------------------------------------
" Based on http://code.google.com/p/vim-python-ide/source/browse/.vimrc
" Modifications from https://dev.launchpad.net/UltimateVimPythonSetup
" vimrc file for following the coding standards specified in PEP 8
" This should be saved as ~/.vim/ftplugin/python.vim
"---------------------------------------------------------------------
" Number of spaces to use for an indent.
" This will affect Ctrl-T and 'autoindent'.
" Python: 4 spaces, PEP-8 compatible
au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
" Number of spaces that a pre-existing tab is equal to.
" For the amount of space used for a new tab use shiftwidth.
" Python: 4
au BufRead,BufNewFile *py,*pyw,*.c,*.h set tabstop=4
" Replace tabs with the equivalent number of spaces.
" Also have an autocmd for Makefiles since they require hard tabs.
" Python: yes
au BufRead,BufNewFile *.py,*.pyw set expandtab
" Use the below highlight group when displaying bad whitespace is desired
highlight BadWhitespace ctermbg=red guisp=red gui=undercurl guifg=NONE guibg=NONE
" Display tabs at the beginning of a line in Python mode as bad.
au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/
" Make trailing whitespace be flagged as bad.
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h set textwidth=78
" Use UNIX (\n) line endings.
" Only used for new files so as to not force existing files to change their
" line endings.
" Python: yes
au BufNewFile *.py,*.pyw set fileformat=unix
" The following section contains suggested settings. While in no way required
" to meet coding standards, they are helpful.
" Set the default file encoding to UTF-8:
set encoding=utf-8
"---------------------------------------------------------------------
" Python IDE relatd staff
"---------------------------------------------------------------------
" highlight variable under cursor (not smart)
" Python: yes
au BufRead,BufNewFile *.py,*.pyw autocmd CursorMoved * silent! exe printf('match IncSearch /\<%s\>/', expand('<cword>'))
" Folding based on indentation:
" set foldmethod=indent
" Show full tags when doing search completion
set showfulltag
" Speed up macros
set lazyredraw
" Try to show at least three lines and two columns of context when
" scrolling
set scrolloff=3
set sidescrolloff=2
" Allow edit buffers to be hidden
set hidden
" 1 height windows
set winminheight=1
" Wrap on these
au BufRead,BufNewFile *.py,*.pyw set whichwrap+=<,>,[,]
" Use the cool tab complete menu
set wildmenu
set wildignore=*.o,*~
" If possible, try to use a narrow number column.
setlocal numberwidth=4
"---------------------------------------------------------------------
" Vim 7.3 configs
"---------------------------------------------------------------------
" Persistent undo
set undodir=/tmp/
set undofile
set colorcolumn=80
"---------------------------------------------------------------------
" completion
"---------------------------------------------------------------------
"by tags
set dictionary=/usr/share/dict/words
let g:showfuncctagsbin = "/usr/bin/ctags"
" by pydict
let g:pydiction_location = '~/.vim/after/ftplugin/pydiction/complete-dict'
@jamezpolley
Copy link
Author

I've now created a full repo at https://github.com/jamezpolley/dotfiles with these and lots more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment