" Tom Ryder (tejr)'s vimrc: " Requires Vim 7.0 or newer with +eval. " Undo anything the operating system's vimrc may have broken runtime system.vim " Set an environment variable for the user runtime directory if !exists('$MYVIM') if has('win32') || has('win64') let $MYVIM = expand('~/vimfiles') else let $MYVIM = expand('~/.vim') endif endif " The all-important default indent settings; filetypes to tweak set autoindent " Use indent of previous line on new lines set expandtab " Use spaces instead of tabs set shiftwidth=4 " Indent with four spaces " The number of spaces the Tab key should insert should follow 'shiftwidth'; " if Vim is new enough (v7.3.693), use a negative value to automate this, " otherwise just use its present value if v:version > 703 \ || v:version == 703 && has('patch693') set softtabstop=-1 else let &softtabstop = &shiftwidth endif " Try to keep backups in one system-appropriate directory, including full " encoded path in filename (trailing double slash) if supported (v8.1.251) set backup if has('patch-8.1.251') set backupdir^=$MYVIM/cache/backup// else set backupdir^=$MYVIM/cache/backup endif " Add some *nix paths not to back up if has('unix') set backupskip^=/dev/shm/* " Shared memory RAM disk set backupskip^=/usr/tmp/* " Hard-coded path for `sudo -e` 1/2 set backupskip^=/var/tmp/* " Hard-coded path for `sudo -e` 2/2 endif " Indent wrapped lines if supported (v7.4.338) if exists('+breakindent') set breakindent endif " Clear default 'comments' and 'commentstring', filetype to handle set comments= set commentstring= " Add completion options set completeopt+=longest " Insert longest common substring set completeopt+=menuone " Show the menu even if only one match " Give me a prompt instead of just rejecting risky :write, :saveas set confirm " Sentence objects are separated by two spaces set cpoptions+=J " Try to keep swap files in one system-appropriate directory, including full " encoded path in filename (trailing double slash) set directory^=$MYVIM/cache/swap// " Use UTF-8 if we can and $LANG doesn't tell us not to if has('multi_byte') \ && !exists('$LANG') \ && &encoding ==# 'latin1' set encoding=utf-8 endif " Don't wait for a key after Escape in insert mode " Not in NeoVim if exists('+esckeys') set noesckeys endif " Fold based on indent, but only when I ask set foldlevelstart=99 set foldmethod=indent " Delete comment leaders when joining lines, if supported (v7.3.541) if v:version > 703 \ || v:version == 703 && has('patch541') set formatoptions+=j endif " Don't break a single space after a period, if supported (v8.1.728) if has('patch-8.1.728') set formatoptions+=p endif " Don't load GUI menus; set here before GUI starts or any filetype or syntax " logic is performed if has('gui_running') set guioptions+=M endif " Allow buffers to have changes without being displayed set hidden " Keep much more command and search history set history=2000 " Highlight completed searches; clear on reload set hlsearch nohlsearch " Don't assume I'm editing C; let the filetype set this set include= " Show search matches as I type my pattern set incsearch " Don't show a status line if there's only one window " This is Vim's default, but not NeoVim's if &laststatus != 1 set laststatus=1 endif " Don't redraw the screen during batch execution set lazyredraw " Break lines at word boundaries set linebreak " Define extra 'list' display characters set listchars+=extends:> " Unwrapped text to screen right set listchars+=nbsp:+ " Non-breaking spaces set listchars+=precedes:< " Unwrapped text to screen left set listchars+=tab:>- " Tab characters, preserve width set listchars+=trail:_ " Trailing spaces " Don't allow setting options via buffer content set nomodeline " Treat numbers with a leading zero as decimal, not octal set nrformats-=octal " Don't search /usr/include by default set path-=/usr/include " Disable command line display of file position " This is Vim's default, but not NeoVim's if &ruler set noruler endif " Make sessions usable set sessionoptions-=localoptions " No buffer options or mappings set sessionoptions-=options " No global options or mappings " Don't show startup splash screen (I donated) set shortmess+=I " Prefix wrapped rows with three dots set showbreak=... " New window positioning set splitbelow " Below the current window, not above set splitright " Right of the current window, not left " Don't try to syntax highlight run-on lines set synmaxcol=500 " PuTTY is a fast terminal if &term =~# '^putty' set ttyfast endif " No terminal mouse, even if we could; the manual says to set 't_RV', but " doing that doesn't seem to prevent 'ttyfast' from being set " Not in NeoVim if exists('+ttymouse') && &ttymouse !=# '' set ttymouse= endif " Try to keep persistent undo files in one system-appropriate directory " (v7.2.438), including full encoded path in filename (trailing double slash) if has('persistent_undo') set undofile set undodir^=$MYVIM/cache/undo// endif " Let me move beyond buffer text in visual block mode set virtualedit+=block " Never beep at me set visualbell t_vb= " Tab completion settings set wildignore=*~,#*# \,*.7z \,*.a,*.adf,*.asc,*.au,*.aup,*.avi \,*.bin,*.bmp,*.bz2 \,*.class \,*.db,*.dbm,*.djvu,*.docx \,*.exe \,*.filepart,*.flac \,*.gd2,*.gif,*.gifv,*.gmo,*.gpg,*.gz \,*.hdf \,*.ico,*.iso \,*.jar,*.jpeg,*.jpg \,*.m4a,*.mid,*.mp3,*.mp4 \,*.o,*.odp,*.ods,*.odt,*.ogg,*.ogv,*.opus \,*.pbm,*.pdf,*.png,*.ppt,*.psd,*.pyc \,*.rar,*.rm \,*.s3m,*.sdbm,*.sqlite,*.swf,*.swp \,*.tar,*.tga,*.ttf \,*.wav,*.webm \,*.xbm,*.xcf,*.xls,*.xlsx,*.xpm,*.xz \,*.zip \,.DS_Store,.git,.hg,.svn if exists('+wildignorecase') set wildignorecase " Case insensitive, if supported (v7.3.072) endif set wildmode=list:longest " Tab press completes and lists " Load filetype settings, plugins, and maps let maplocalleader = ',' filetype plugin indent on " Use syntax highlighting if !exists('syntax_on') syntax enable endif " Try to use sahara color scheme with 'cursorline' set; otherwise, use the " default color scheme with a dark background try colorscheme sahara set cursorline catch set background=dark endtry " Remap normal space to scroll down a page nnoremap " Do a :next after hitting the last line if &loadplugins " Don't change the mapping if we won't be loading the plugin nmap (ScrollNext) endif " Remap insert Ctrl-C to undo the escaped insert operation if &loadplugins " Don't break the key if we won't be loading the plugin imap (InsertCancel) endif " Map double Ctrl-K in insert mode to search digraph names imap (DigraphSearch) " Stack normal/visual/select Ctrl-L to clear search highlight nnoremap :nohlsearch vnoremap :nohlsearchgv " Make Ctrl-L work in insert mode too; good for choppy terminals inoremap :redraw " Remap normal/visual & and g& to preserve substitution flags nnoremap & :&& xnoremap & :&& nnoremap g& :%&& " Map g: as a 'colon operator' nmap g: (ColonOperator) " Cycle through argument list nnoremap [a :previous nnoremap ]a :next " Cycle through buffers nnoremap [b :bprevious nnoremap ]b :bnext " Cycle through quickfix list items nnoremap [c :cprevious nnoremap ]c :cnext " Cycle through location list items nnoremap [l :lprevious nnoremap ]l :lnext " Insert blank lines around current line nmap [ (PutBlankLinesAbove) nmap ] (PutBlankLinesBelow) " \a toggles 'formatoptions' 'a' flag using a plugin nnoremap a :ToggleFlagLocal formatoptions a " \b toggles settings friendly to copying and pasting nmap b (CopyLinebreakToggle) " \c toggles 'cursorline'; no visual mode map as it doesn't work nnoremap c :setlocal cursorline! cursorline? " \C toggles 'cursorcolumn'; works in visual mode nnoremap C :setlocal cursorcolumn! cursorcolumn? xnoremap C :setlocal cursorcolumn! cursorcolumn?gv " \d inserts the local date (POSIX date) nnoremap d :read !date " \D inserts the UTC date (POSIX date) nnoremap D :read !date -u " \e forces a buffer to be editable nnoremap e :setlocal modifiable noreadonly " \f shows the current 'formatoptions' at a glance nnoremap f :setlocal formatoptions? " \F reloads filetype plugins nnoremap F :doautocmd filetypedetect BufRead " \g changes directory to the current file's location nnoremap g :cd %:hpwd " \h toggles highlighting search results nnoremap h :set hlsearch! hlsearch? " \H shows command history nnoremap H :history : " \i toggles showing matches as I enter my pattern nnoremap i :set incsearch! incsearch? " \j jumps to buffers ("jetpack") nnoremap j :buffers:buffer " \k shows my marks nnoremap k :marks " \l toggles showing tab, end-of-line, and trailing white space nnoremap l :setlocal list! list? xnoremap l :setlocal list! list?gv " \L toggles 'colorcolumn' showing 'textwidth' nnoremap L :ToggleFlagLocal colorcolumn +1 xnoremap L :ToggleFlagLocal colorcolumn +1gv " \m shows normal maps nnoremap m :map " \M shows buffer-local normal maps nnoremap M :map " \n toggles line number display nnoremap n :setlocal number! number? xnoremap n :setlocal number! number?gv " \N toggles position display in bottom right nnoremap N :set ruler! ruler? xnoremap N :set ruler! ruler?gv " \o opens a line below in paste mode nmap o (PasteOpenBelow) " \O opens a line above in paste mode nmap O (PasteOpenAbove) " \p toggles paste mode nnoremap p :set paste! paste? " \P creates the path to the current file nnoremap P :call mkdir(expand('%:h'), 'p') " \q formats the current paragraph nnoremap q gqap " \r acts as a replacement operator nmap r (ReplaceOperator) xmap r (ReplaceOperator) " \R reloads ~/.vimrc nnoremap R :source $MYVIMRC " \s toggles spell checking nnoremap s :setlocal spell! spell? " \S shows loaded scripts nnoremap S :scriptnames " \t shows current filetype nnoremap t :setlocal filetype? " \T clears filetype nnoremap T :setlocal filetype= " \u sets US English spelling (compare \z) nnoremap u :setlocal spelllang=en_us " \v shows all global variables nnoremap v :let g: v: " \V shows all local variables nnoremap V :let b: t: w: " \w toggles wrapping nnoremap w :setlocal wrap! wrap? xnoremap w :setlocal wrap! wrap?gv " \x strips trailing whitespace via a custom plugin nmap x :StripTrailingWhitespace xmap x :StripTrailingWhitespace " \X squeezes repeated blank lines via a custom plugin nmap X :SqueezeRepeatBlanks xmap X :SqueezeRepeatBlanks " \y shows all registers nnoremap y :registers " \z sets NZ English spelling (compare \u) nnoremap z :setlocal spelllang=en_nz " \= runs the whole buffer through =, preserving position nnoremap = :call vimrc#Anchor('1G=G') " \+ runs the whole buffer through gq, preserving position nnoremap + :call vimrc#Anchor('1GgqG') " \. runs the configured make program into the location list nnoremap . :lmake! " \< and \> adjust indent of last edit; good for pasting nnoremap :'[,'] nnoremap > :'[,']> " \_ uses last changed or yanked text as an object onoremap _ :normal! `[v`] " \% uses entire buffer as an object onoremap % :normal! 1GVG " \{ and \} move to lines with non-space chars before current column nmap { (VerticalRegionUp) nmap } (VerticalRegionDown) omap { (VerticalRegionUp) omap } (VerticalRegionDown) xmap { (VerticalRegionUp) xmap } (VerticalRegionDown) " \/ types :vimgrep for me ready to enter a search pattern nnoremap / :vimgrep /\c/j ** " \? types :lhelpgrep for me ready to enter a search pattern nnoremap ? :lhelpgrep \c " \\ escapes regex metacharacters nmap \ (RegexEscape) xmap \ (RegexEscape) " \DEL deletes the current buffer nnoremap :bdelete " \INS edits a new buffer nnoremap :enew " \TAB toggles 'autoindent' nnoremap :setlocal autoindent! autoindent? " Execution mappings; each of these clobbers register z " \@ executes line in normal mode nnoremap @ ^"zyg_@z " \: executes line in command mode nnoremap : ^"zyg_:z " \! executes line with 'shell' nnoremap ! ^"zyg_:!z " Things I almsot always type wrnog inoreabbrev almsot almost inoreabbrev wrnog wrong inoreabbrev Fielding Feilding " Source any .vim files from ~/.vim/config runtime! config/*.vim