Skip to content

Instantly share code, notes, and snippets.

@nathanshelly
Last active October 17, 2018 17:32
Show Gist options
  • Select an option

  • Save nathanshelly/69e56b0035a1b671299f0d5c705babfc to your computer and use it in GitHub Desktop.

Select an option

Save nathanshelly/69e56b0035a1b671299f0d5c705babfc to your computer and use it in GitHub Desktop.
A basic `.vimrc` with some subjective sensible defaults
" Example basic .vimrc
" these settings are subjective
" pick and choose any you like and ignore those you don't
" hopefully this serves as a jumping off point with more
" nicer defaults than vim comes with out of the box
" feel free to reach out if you have any questions!
" <<<<<<<< General Options >>>>>>>>
" disable beeping and screen flash on error
set visualbell
set t_vb=
" map leader -> space
" this is only useful if you use leader shortcuts
" see the explanation of `<leader>` under the
" remappings section further below
let mapleader=" "
" syntax coloring
syntax on
" line numbers
" turn on absolute line numbers
" (the kind of line numbers most editors display)
set number
" makes line numbers around the current line relative
" e.g., the line above and below are each shown as 1,
" the next line in each direction as 2 and so on
" especially useful when combined with motions. For example
" to jump 5 lines upward hit `5k`. Relative line numbers mean
" no need to do math (cause math is hard) to know what number
" needed to jump to a line above or below
" can be used without the `set number` line above
" in which case the current line is shown as `0`
set relativenumber
" scrolloff
"
set scrolloff=10
" normal backspace
" enables backspacing through indents, end of lines and characters
" previously inserted before entering insert mode this time (kinda
" confusing, see refs for more explanation)
" refs:
" https://vi.stackexchange.com/questions/2162/why-doesnt-the-backspace-key-work-in-insert-mode
" http://vim.wikia.com/wiki/Backspace_and_delete_problems
set backspace=indent,eol,start
" indentation
" I use spaces not tabs, this debate is as old as computers
" so use whatever makes you happy. Here's an explanation of my
" choices:
" tabstop - # of columns a tab counts for
" softtabstop - # of columns to use when hitting Tab in insert mode (see refs)
" shiftwidth - # of columns text is indented w/ `<<` & `>>`
" expandtab - insert spaces on Tab
" Vim has lots of configuration options for indentation
" refs:
" http://vim.wikia.com/wiki/Indenting_source_code
" https://tedlogan.com/techblog3.html
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
set autoindent
" wrap on linebreak (show as much as possible)
" ref - http://vim.wikia.com/wiki/Word_wrap_without_line_breaks
set wrap
" wrap only at linebreak characters - ` ^I!@*-+;:,./?`
set linebreak
" include as much of last line as possible instead of showing `@`
" https://stackoverflow.com/questions/4621798/how-do-you-prevent-vim-from-showing-an-at-symbol-when-a-line-doesnt-fit-on
set display+=lastline
" show ruler @ 80
" displays a line onscreen at the given number of columns
" so you know if you're going over line length
" (write up to line, not on top of it)
set colorcolumn=81
" << search >>
" show matches as you type
set incsearch
" highlight all matches
set hlsearch
" case sensitive if the search contains
" capitals (ignorecase needs to be set for this)
" to search for a whole word -> /\<word\>
" lowercase sensitive -> /word\C (`\C` can be anywhere)
set ignorecase
set smartcase
" <<<< File Specific >>>>
" these options apply only to the filetype specified by
" `au FileType` before the option (`au` is short for `autocmd`)
" << git >>
" commit message subject line wrap and color
" wrap at 72 characters
au FileType gitcommit set tw=72
" highlight characters past line length that Github (and other
" VCS systems) will display before truncating
au FileType gitcommit hi gitCommitSummary ctermfg=blue
" << makefile >>
" insert tabs, not 2 spaces
" make files need tabs to actually be tabs
au FileType make set noexpandtab
" <<<<<<<< Remappings >>>>>>>>
" Vim allows you to map any keystrokes to various actions
" below are a few examples of remappings
“ using vim requires frequent use of esc but the escape key is in
“ an awkward location. Many people set another key or combination
to send escape. I personally use `jk` in rapid succession, some other
“ common choices are `jj`, `;;`, `kj`, etc.
“ ref - http://vim.wikia.com/wiki/Avoid_the_escape_key
inoremap jk <esc>
" use Ctrl-j/k to scroll screen
noremap <c-j> <c-e>
noremap <c-k> <c-y>
" the concept of a `<leader>` allows for even
" more shortcuts, see the below link for an explanation
" https://stackoverflow.com/questions/1764263/what-is-the-leader-in-a-vimrc-file
" turn off search highlighting
nmap <silent> <leader>n :noh<CR>
" start/end of screen line movement
nmap <silent> <leader>$ g$
nmap <silent> <leader>0 g0
" <<<<<<<< Colors >>>>>>>>
" background
set background=dark
" enable 256 colors (as opposed to the 16 of the default ascii colors)
set t_Co=256
" << highlighting >>
" hi is short for highlight
" many commands you'll see in example .vimrc files
" will use these sorts of shortcuts to shorten lines
" search
hi Search cterm=None ctermfg=black ctermbg=cyan
hi IncSearch cterm=None ctermfg=black ctermbg=cyan
" matching
hi MatchParen cterm=None ctermfg=black ctermbg=cyan
" transparent background
hi Normal ctermbg=None
" << whitespace >>
" whitespace group coloring
" set color of trailing whitespace
hi ExtraWhitespace ctermbg=magenta
" keep through color scheme change
" (maintains trailing whitespace coloring if overall colorscheme changes)
au ColorScheme * hi ExtraWhitespace ctermbg=magenta
" highlight all trailing whitespace
au BufRead,InsertLeave * match ExtraWhitespace /\s\+$/
" avoid highlighting trailing whitespace on the current
" line when editing at the end of it
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment