Vim Improvement Plan: Getting Started
See information about the Vim Improvement Plan here.
The Rules
- We'll start with an empty ~/.vimrc and ~/.vim; the system vimrc will be untouched from installation. By "empty" I mean I'm filling it in right now.
- All other rules have been deleted thus far...
Though I'm using Windows for this, you'll notice I use UN*X-y filenames and directory layouts; I try to keep my systems set up the same as much as possible. On Windows, my vimrc is ~/.vimrc, etc. This allows me to keep everything in sync via git without renaming files (yes, git hooks will do it, but this is simpler).
Open up and... gvim's default view on a 4K display is unreadable. Let's fix the font and re-source (`:so $MYVIMRC`), though I'll later move this into the plugins folder:
if has("gui_running")
if has("gui_gtk2")
set guifont=Inconsolata\ 12
elseif has("gui_macvim")
set guifont=Menlo\ Regular:h14
elseif has("gui_win32")
set guifont=Fira\ Code:h11
set renderoptions=type:directx
endif
else
set t_Co=256
endif
We'll make a few other changes I know I want and install Vundle as my plugin manager, which gives us the following .vimrc and .vim/ (yes, it's a lot for a "clean slate", but it's mostly just paint on the fence):
" [~/.vimrc]
set nocompatible
" From romainl - https://gist.github.com/romainl/4df4cde3498fada91032858d7af213c2
if !exists('g:env')
if has('win64') || has('win32') || has('win16')
let g:env = 'WINDOWS'
else
let g:env = toupper(substitute(system('uname'), '\n', '', ''))
endif
endif
" I use ~/.vim folder on all systems - including Windows.
if g:env =~ 'WINDOWS'
let &runtimepath="$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after"
endif
" Vundle configuration.
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" Plugins go here.
call vundle#end()
filetype plugin indent on
syntax on
" Convenient leader.
let mapleader=' '
" I default to UNIX line endings, even on Windows. Vim handles them just fine.
set fileformat=unix
set fileformats=unix,dos
set encoding=utf-8
set fileencoding=utf-8
set autoread
set backspace=indent,eol,start
set expandtab
set smarttab
set smartindent
set shiftwidth=4
set tabstop=4
set cpoptions+=n
set noswapfile
set undodir="~/.vim/undo"
set undofile
set undolevels=500
set history=1000
" Treat wrapped lines as unwrapped.
nnoremap j gj
nnoremap k gk
" Search settings
set ignorecase
set smartcase
set incsearch
" Set guide columns.
set cc=81,121
set laststatus=2
set scrolloff=5
set showmatch
set nu
" I want to see 82 characters, regardless of the size of the gutter; this gives
" me a 3-char margin on the right, which looks nice, and we won't wrap once the
" left gutter expands by one.
" From http://superuser.com/a/330352
au BufRead * let &numberwidth = float2nr(log10(line("$"))) + 4
\| let &columns = &numberwidth + 83
set nostartofline " Keep the cursor's column position.
" [.vim/myprefs/gui.vim]
if !has("gui_running")
set t_Co=256
finish
endif
if has("gui_gtk2")
set guifont=Inconsolata\ 12
elseif has("gui_macvim")
set guifont=Menlo\ Regular:h14
elseif has("gui_win32")
set guifont=Fira\ Code:h11
set renderoptions=type:directx
endif
" [.vim/myprefs/typos.vim]
" Fix common typos.
command! W :w
I have also added the lightline, previm, and vimwiki plugins:
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'itchyny/lightline.vim'
Plugin 'previm/previm'
Plugin 'vimwiki/vimwiki'
call vundle#end()