"Note when ~/.vimrc present the following is done automatically "set nocompatible if v:lang =~ "utf8$" || v:lang =~ "UTF-8$" set fileencodings=utf-8,latin1 endif "allow backspacing over everything in insert mode set bs=2 set viminfo='20,\"50 " read/write a .viminfo file, don't store more " than 50 lines of registers set history=50 " keep 50 lines of command line history "Allow switching buffers without writing to disk set hidden "Always show cursor position set ruler "Set terminal title to filename set title if has("autocmd") " When editing a file, always jump to the last cursor position autocmd BufReadPost * \ if line("'\"") > 0 && line ("'\"") <= line("$") | \ exe "normal g'\"" | \ endif endif "This is necessary to allow pasting from outside vim. It turns off auto stuff. "You can tell you are in paste mode when the ruler is not visible set pastetoggle= "Usually annoys me set nowrap "Usually I don't care about case when searching set ignorecase "Only ignore case when we type lower case when searching set smartcase "I hate noise. The t_vb bit removes any delay also set visualbell t_vb= "Always provide a little context around the current line set scrolloff=4 "Show menu with possible tab completions set wildmenu "Ignore these files when completing names and in Explorer set wildignore=.svn,CVS,.git,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif "Search for tags in this dir and above set tags=./TAGS;/,./tags;/ " Alt-right/left to navigate forward/backward in the tags stack map map " Delete comment character when joining commented lines if v:version > 703 set formatoptions+=j endif """""""""""""""""""""""""""""""""""""""""""""""" " Indenting """""""""""""""""""""""""""""""""""""""""""""""" "Default to autoindenting of C like languages "This is overridden per filetype below set noautoindent smartindent "The rest deal with whitespace handling and "mainly make sure hardtabs are never entered "as their interpretation is too non standard in my experience set softtabstop=4 " Note if you don't set expandtab, vi will automatically merge " runs of more than tabstop spaces into hardtabs. Clever but " not what I usually want. set expandtab set shiftwidth=4 set shiftround set nojoinspaces " Set GNU style indentation, spaces instead of TABs function! GNUIndent() if match(getcwd(), "coreutils") > 0 || match(getcwd(), "gnulib") > 0 " The next 3 lines below set the GNU indentation setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1 setlocal shiftwidth=2 setlocal tabstop=8 " Coreutils specific, expand TABs with spaces setlocal expandtab endif endfunction autocmd BufEnter *.c,*.h call GNUIndent() """""""""""""""""""""""""""""""""""""""""""""""" " Dark background """""""""""""""""""""""""""""""""""""""""""""""" "I always work on dark terminals set background=dark "Make the completion menus readable highlight Pmenu ctermfg=0 ctermbg=3 highlight PmenuSel ctermfg=0 ctermbg=7 "The following should be done automatically for the default colour scheme "at least, but it is not in Vim 7.0.17. if &bg == "dark" highlight MatchParen ctermbg=darkblue guibg=blue endif """""""""""""""""""""""""""""""""""""""""""""""" " Syntax highlighting """""""""""""""""""""""""""""""""""""""""""""""" if v:version >= 700 "The following are a bit slow "for me to enable by default "set cursorline "highlight current line "set cursorcolumn "highlight current column endif if v:version >= 700 "Display a visual barrier for col 80 "This has the disadvantage of adding trailing whitespace "when copy and pasting from vim. "set colorcolumn=80 endif if &t_Co >= 256 && &bg == "dark" highlight ColorColumn ctermbg=233 elseif &t_Co >= 256 && &bg != "dark" highlight ColorColumn ctermbg=230 else highlight ColorColumn ctermbg=8 endif "Syntax highlighting if appropriate if &t_Co > 2 || has("gui_running") syntax on set hlsearch set incsearch "For fast terminals can highlight search string as you type endif if &diff "I'm only interested in diff colours syntax off endif "syntax highlight shell scripts as per POSIX, "not the original Bourne shell which very few use let g:is_posix = 1 "flag problematic whitespace (trailing and spaces before tabs) "Note you get the same by doing let c_space_errors=1 but "this rule really applys to everything. highlight RedundantSpaces term=standout ctermbg=red guibg=red match RedundantSpaces /\s\+$\| \+\ze\t/ "\ze sets end of match so only spaces highlighted "use :set list! to toggle visible whitespace on/off set listchars=tab:>-,trail:.,extends:> """""""""""""""""""""""""""""""""""""""""""""""" " Key bindings """""""""""""""""""""""""""""""""""""""""""""""" "Note is the user modifier key (like g is the vim modifier key) "One can change it from the default of \ using: let mapleader = "," "\n to turn off search highlighting nmap n :silent :nohlsearch "\l to toggle visible whitespace nmap l :set list! "\s to toggle spellcheck nmap s :setlocal spell! spelllang=en_gb "\u to toggle us spellcheck nmap u :setlocal spell! spelllang=en_us "Shift-tab to insert a hard tab imap " when opening file under cursor, use line number info if available nmap gf gF "allow deleting selection without updating the clipboard (yank buffer) vnoremap x "_x vnoremap X "_X "don't move the cursor after pasting "(by jumping to back start of previously changed text) noremap p p`[ noremap P P`[ "Reselect after indent so it can easily be repeated vnoremap < >gv " toggles between start of line and start of text imap nmap inoremap :call Home() nnoremap :call Home() function Home() let curcol = wincol() normal ^ let newcol = wincol() if newcol == curcol normal 0 endif endfunction " goes to end of screen before end of line imap nmap inoremap :call End() nnoremap :call End() function End() let curcol = wincol() normal g$ let newcol = wincol() if newcol == curcol normal $ endif "The following is to work around issue for insert mode only. "normal g$ doesn't go to pos after last char when appropriate. "More details and patch here: "http://www.pixelbeat.org/patches/vim-7.0023-eol.diff if virtcol(".") == virtcol("$") - 1 normal $ endif endfunction "Ctrl-{up,down} to scroll. "The following only works in gvim? "Also vim doesn't have default C-{home,end} bindings? if has("gui_running") nmap imap nmap imap endif """""""""""""""""""""""""""""""""""""""""""""""" " file type handling """""""""""""""""""""""""""""""""""""""""""""""" " To create new file securely do: vim new.file.txt.gpg " Your private key used to decrypt the text before viewing should " be protected by a passphrase. Alternatively one could use " a passphrase directly with symmetric encryption in the gpg commands below. au BufNewFile,BufReadPre *.gpg :set secure viminfo= noswapfile nobackup nowritebackup history=0 binary au BufReadPost *.gpg :%!gpg -d 2>/dev/null au BufWritePre *.gpg :%!gpg -e -r 'P@draigBrady.com' 2>/dev/null au BufWritePost *.gpg u filetype on filetype plugin on filetype indent on augroup html au! "Disable parenthesis matching as it's way too slow au BufRead *.html NoMatchParen "Disable autoindenting for HTML as it's a bit annoying au FileType html set nosmartindent noautoindent augroup END augroup sh au! "smart indent really only for C like languages au FileType sh set nosmartindent autoindent augroup END augroup Python "See $VIMRUNTIME/ftplugin/python.vim au! "smart indent really only for C like languages "See $VIMRUNTIME/indent/python.vim au FileType python set nosmartindent autoindent " Allow gf command to open files in $PYTHONPATH au FileType python let &path = &path . "," . substitute($PYTHONPATH, ';', ',', 'g') if v:version >= 700 "See $VIMRUNTIME/autoload/pythoncomplete.vim " to autocomplete au FileType python set omnifunc=pythoncomplete#Complete "Don't show docs in preview window au FileType python set completeopt-=preview endif augroup END augroup man au! "Ensure vim is not recursively invoked (man-db does this) "when doing ctrl-[ on a man page reference au FileType man let $MANPAGER="" augroup END