• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rico's guide for setting up Vim

Deprecated: Thanks for checking my project! The guide below was made for older versions of Vim. Today, you can try nvim-starter or kickstart.nvim for Neovim.



Vim from scratch

Rico's guide to setting up Vim for
everyday development


This guide will walk you through setting up a practical config that will work on Vim, Neovim, Macvim, and any other Vim implementation out there.

Getting started

Customizations

Interoperability

Moving forward

Install Vim and Neovim

(Skip this step if you've already installed Vim.)

There are many ways to acquire Vim. I suggest using Neovim, a fork of Vim with extra features--but regular Vim would work just fine.

  • Vim on Linux
    Most distributions come with vim and neovim packages. Some distributions have different versions available. When in doubt, pick the vim-gnome or vim-gtk3 or gvim package.

    sudo pacman -S gvim         # Arch Linux
    sudo apt install vim-gnome  # Ubuntu
  • Neovim on Linux
    If your distro ships with python-neovim, add it in too.

    sudo pacman -S neovim python-neovim
  • Neovim on MacOS
    The neovim package is available in Homebrew.

    brew install neovim
    # (todo: add more notes on python integration etc)
  • Vim on MacOS
    I recommend using Macvim with installed via Homebrew with --override-system-vim. This gets you a more updated version of Vim than if you used the vim package. You'll also get a GUI app, which can be nice.

    brew install macvim --with-cscope --with-lua --override-system-vim --with-luajit --with-python3

Back up your existing Vim config

(Skip this step if you're setting up a fresh installation of Vim.)

Want to try out this guide, but you already have Vim set up? You can rename them for now, and restore it later on.

mv ~/.vimrc ~/.vimrc~
mv ~/.vim ~/.vim~
mv ~/.config/nvim ~/.config/nvim~

Create your ~/.vim

The first obvious step is to create your config folder. Vim expects this in ~/.vim, and Neovim expects it in ~/.config/nvim. Since our goal is to make a Vim config that'll work everywhere, I suggest keeping it in ~/.vim and symlinking it as needed.

mkdir -p ~/.vim
cd ~/.vim

# Version it using Git
git init
git commit -m "Initial commit" --allow-empty

Create your init.vim (aka .vimrc)

Vim looks for your config in ~/.vimrc, and Neovim looks for it in ~/.config/nvim/init.vim. Let's create the file as ~/.vim/init.vim, which we will symlink to the proper locations later.

cd ~/.vim
touch init.vim

Set up symlinks

My preferred method is to create a Makefile which will set up symlinks as necessary. In ~/.vim, create a file called Makefile and add this in:

# Makefile
pwd := $(shell pwd -LP)

link:
	@if [ ! . -ef ~/.vim ]; then ln -nfs "${pwd}" ~/.vim; fi
	@if [ ! . -ef ~/.config/nvim ]; then ln -nfs "${pwd}" ~/.config/nvim; fi
	@ln -nfs "${pwd}/init.vim" ~/.vimrc

After creating it, just run make link. This should finally make your config available in both ~/.config/nvim/init.vim and ~/.vimrc.

# Before doing this, make sure you don't have ~/.vimrc (careful!)
rm ~/.vimrc

# Set up symlinks
cd ~/.vim
make link

Install vim-plug

vim-plug is the plugin manager I can recommend the most. It's ridiculously fast, and supports a lot of great features. This command will download plug.vim into your Vim config path:

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
  https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Edit your config file by doing vim ~/.vim/init.vim. Add the following:

set nocompatible
let g:mapleader=" "

call plug#begin('~/.vim/vendor')

if !has('nvim') && !exists('g:gui_oni') | Plug 'tpope/vim-sensible' | endif
Plug 'rstacruz/vim-opinion'

call plug#end()

Save it, restart Vim, then call PlugInstall.

" Save the file and exit vim
:wq

" Start vim again, then install the plugins
:PlugInstall

See: vim-plug usage (github.com)

Install plugins

The config above will install 2 plugins. Both are optional, but I recommend them:

  • vim-sensible enables some good "sensible" defaults, such as turning on syntax highlighting. This is superfluous in some vim forks like Neovim so I suggest to conditionally load it only when needed.

    if !has('nvim') && !exists('g:gui_oni') | Plug 'tpope/vim-sensible' | endif
  • vim-opinion enables some good "opinionated" defaults that I prefer (I'm the author of this plugin!). This has some settings that I think will do well for most setups, such as incremental search and so on.

    Plug 'rstacruz/vim-opinion'

More plugins

Here are some more that I can recommend to almost every developer:

  • fzf is a very fast file picker. I recommend this over alternatives like ctrlp.vim.

    Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
    Plug 'junegunn/fzf.vim'
  • ale verifies your files for syntax errors.

    Plug 'w0rp/ale'
  • vim-sleuth auto-detects if files use space or tabs, and how many spaces each file should have.

    Plug 'tpope/vim-sleuth'
  • vim-polyglot adds automatic language support for every language that Vim can support through 3rd party plugins.

    Plug 'sheerun/vim-polyglot'

Set up additional options

Our config so far has vim-sensible and vim-opinion, which has some great defaults. You may want to add more settings. Instead of dumping them into ~/.vimrc, I suggest adding them to your after-directory instead. This will keep your config file as clean as possible.

mkdir -p ~/.vim/after/plugin
vim ~/.vim/after/plugin/options.vim

Here are some stuff you can add. All of these are optional.

" Enable 256-color by default in the terminal
if !has('gui_running') | set t_Co=256 | endif

" Hide line numbers by default
set nonumber

" Wildignore
set wig+=vendor,log,logs

See: Keep your vimrc clean (vim.wikia.com), ~/.vim/after _(learnvimscriptthehardway.stevelosh.com)_

Set up additional key bindings

I suggest keeping most (all?) of your key bindings in one file in your after-directory. I prefer to keep them in ~/.vim/after/plugin/key_bindings.vim. This way, you can

vim ~/.vim/after/plugin/key_bindings.vim
" ctrl-s to save
nnoremap <C-s> :w<CR>

" ctrl-p to open a file via fzf
if exists(':FZF')
  nnoremap <C-p> :FZF!<cr>
endif

" SPC-f-e-d to edit your config file
nnoremap <leader>fed :cd ~/.vim<CR>:e ~/.vim/init.vim<CR>
" SPC-f-e-k to edit your kepmap file
nnoremap <leader>fek :cd ~/.vim<CR>:e ~/.vim/after/plugin/key_bindings.vim<CR>
" SPC-f-e-o to edit your options file
nnoremap <leader>feo :cd ~/.vim<CR>:e ~/.vim/after/plugin/options.vim<CR>

The leader keymaps at the end can be triggered with the Spacebar as the leader key. For instance, the first one is SPACE f e d. These are inspired by Spacemacs.

Change your leader key

The default init.vim above has a g:mapleader setting of spacebar. This is a great default that a lot of people use! I personally prefer the , key as a Dvorak user, but this is totally up to you. Common leader keys are <space>, <cr>, <bs>, - and ,.

" In your ~/.vim/init.vim
let g:mapleader=","

See: Leaders (learnvimscriptthehardway.stevelosh.com)

Interoperability with GUI Vim apps

There are many Vim GUI apps available today. Some popular ones include Macvim, VimR, vim-gtk and more are probably coming out everyday.

There are some settings you might only want to use on GUI. You can use if has('gui_running') to conditionally only apply settings when running in a GUI.

Like most settings, I suggest placing them in the after-directory, eg, ~/.vim/after/plugin/theme.vim. Here's an example that sets fonts for GUIs:

" ~/.vim/after/plugin/theme.vim

if has('gui_running')
  " Settings for when running in a GUI
  set transparency=0
  set guifont=Iosevka\ Medium:h16 linespace=-1
  set guioptions+=gme " gray menu items, menu bar, gui tabs
  set antialias
  color ir_black+
else
  " Settings for when running in the console
  color base16
endif

Interoperability between Vim and Neovim

TODO: talk about has('nvim'), config paths, etc

Interoperability with Oni

TODO: talk about exists('g:gui_oni')

More to come!

This guide is a work in progress, more stuff soon! But at this point you should have a working Vim config. Commit it, and share it!

Here are some more resources to look at:

Icon from Thenounproject.com

More Repositories

1

nprogress

For slim progress bars like on YouTube, Medium, etc
JavaScript
25,552
star
2

cheatsheets

Cheatsheets for web development - devhints.io
SCSS
13,674
star
3

jquery.transit

Super-smooth CSS3 transformations and transitions for jQuery
JavaScript
7,328
star
4

rscss

Reasonable System for CSS Stylesheet Structure
3,894
star
5

flatdoc

Build sites fast from Markdown
CSS
2,679
star
6

webpack-tricks

Tips and tricks in using Webpack
2,359
star
7

sparkup

A parser for a condensed HTML format
Python
1,566
star
8

backbone-patterns

Common Backbone.js usage patterns.
760
star
9

remount

Mount React components to the DOM using custom elements
JavaScript
680
star
10

sinatra-assetpack

Package your assets transparently in Sinatra.
CSS
542
star
11

jsdom-global

Enable DOM in Node.js
JavaScript
472
star
12

hicat

Command-line syntax highlighter
JavaScript
405
star
13

kingraph

Plots family trees using JavaScript and Graphviz
JavaScript
390
star
14

vim-closer

Closes brackets
Vim Script
337
star
15

scour

Traverse objects and arrays with ease
JavaScript
308
star
16

mocha-jsdom

Simple jsdom integration with mocha
JavaScript
254
star
17

css-condense

[unsupported] A CSS compressor that shows no mercy
JavaScript
206
star
18

swipeshow

The unassuming touch-enabled JavaScript slideshow
JavaScript
191
star
19

rsjs

Reasonable System for JavaScript Structure
181
star
20

vim-coc-settings

My Vim settings for setting it up like an IDE
Vim Script
164
star
21

startup-name-generator

Let's name your silly startup
JavaScript
164
star
22

onmount

Safe, reliable, idempotent and testable behaviors for DOM nodes
JavaScript
156
star
23

psdinfo

Inspect PSD files from the command line
JavaScript
147
star
24

vim-hyperstyle

Write CSS faster
Python
144
star
25

js2coffee.py

JS to CoffeeScript compiler. [DEPRECATED]
Python
127
star
26

firefox-stealthfox

Firefox customization for stealth toolbars
CSS
122
star
27

mocha-clean

Clean up mocha stack traces
JavaScript
107
star
28

jquery-stuff

A collection of small jQuery trinkets
JavaScript
96
star
29

npm-pipeline-rails

Use npm as part of your Rails asset pipeline
Ruby
95
star
30

navstack

Manages multiple screens with mobile-friendly transitions
JavaScript
94
star
31

bootstrap-practices

List of practices when using Bootstrap in projects
90
star
32

details-polyfill

Polyfill for the HTML5 <details> element, no dependencies
JavaScript
89
star
33

dom101

DOM manipulation utilities
JavaScript
82
star
34

unorphan

Removes text orphans
JavaScript
81
star
35

expug

Pug templates for Elixir
Elixir
80
star
36

stylelint-rscss

Validate CSS with RSCSS conventions
JavaScript
74
star
37

feh-blur-wallpaper

Blur your desktop wallpaper when windows are open
Shell
73
star
38

pomo.js

Command-line timer, great for Pomodoros
JavaScript
73
star
39

sinatra-backbone

Neat Backbone.js integration with Sinatra.
Ruby
72
star
40

flowloop

A Pomodoro-like timer for hyper-productivity
JavaScript
71
star
41

vimfiles

My VIM config files.
Lua
63
star
42

bookmarks

My bookmarks
63
star
43

my_qmk_keymaps

Keymaps for keyboards
C
59
star
44

typish

Typewriter simulator
JavaScript
58
star
45

iconfonts

Fine-tuned icon fonts integration for Sass, Less and Stylus
CSS
54
star
46

pre.js

Efficient, resilient resource preloader for JS/CSS
JavaScript
54
star
47

tape-watch

Rerun tape tests when files change
JavaScript
53
star
48

tinkerbin

Tinkerbin.com
JavaScript
52
star
49

vim-fastunite

Search for files fast
Vim Script
48
star
50

collaborative-etiquette

A manifesto for happy Open Source projects
46
star
51

decca

Render interfaces using pure functions and virtual DOM
JavaScript
45
star
52

vim-opinion

My opinionated vim defaults
Vim Script
44
star
53

modern-development

Using agile methods to build quality web applications
CSS
43
star
54

til-2013

Old version of http://ricostacruz.com/til (2015-2018)
CSS
42
star
55

ion

[deprecated] Ruby/Redis search engine.
Ruby
41
star
56

timetip

Deliciously-minimal time tracker for the command-line
JavaScript
40
star
57

vim-xtract

Extract the selection into a new file
Vim Script
39
star
58

bump-cli

Command-line version incrementer
JavaScript
39
star
59

halla

Native Slack wrapper app without the bloat
JavaScript
38
star
60

newsreader-sample-layout

CSS
36
star
61

ento

Simple, stateful, observable objects in JavaScript
JavaScript
36
star
62

cron-scheduler

Runs jobs in periodic intervals
JavaScript
35
star
63

promise-conditional

Use if-then-else in promise chains
JavaScript
34
star
64

ractive-touch

Touch events for Ractive
JavaScript
33
star
65

jquery.unorphan

[deprecated] Obliterate text orphans.
JavaScript
33
star
66

git-update-ghpages

Simple tool to update GitHub pages
Shell
33
star
67

greader

[UNSUPPORTED] Google Reader API client for Ruby
Ruby
32
star
68

penpad

Design and document web UI components
TypeScript
32
star
69

typecat

TypeScript
31
star
70

react-meta-elements

Sets document title and meta tags using React elements or hooks
TypeScript
31
star
71

vim-ultisnips-css

[deprecated] Write CSS in VIM faster.
Ruby
31
star
72

tape-plus

Nested tape tests with before/after, async, and promise support
JavaScript
30
star
73

taskpaper.js

Taskpaper parser in JavaScript
JavaScript
28
star
74

frontend-starter-kit

Rico's opinionated Metalsmith frontend kit
JavaScript
28
star
75

homebrew-backup

Back up your Homebrew profile
Shell
28
star
76

fishfiles

my fish-shell config files
Shell
28
star
77

passwordgen.js

Password generator for the command line
JavaScript
28
star
78

reacco

Generate documentation from README files.
Ruby
26
star
79

ghub

Open this project in github
Shell
26
star
80

sass_icon_fonts

Sass 3.2 integration with modern icon fonts.
CSS
26
star
81

lidoc

[Deprecated] Literate-programming style documentation tool.
CoffeeScript
24
star
82

rspec-repeat

Repeats an RSpec example until it succeeds.
Ruby
24
star
83

lofi

VHS music machine from the 80's
JavaScript
24
star
84

sinatra-template

Ruby
24
star
85

fish-asdf

Fish shell integrations for asdf version manager
Shell
24
star
86

wiki

Stuff
23
star
87

arch-installer

Install UI for Arch Linux
Shell
22
star
88

slack-emoji-magic

Magic: the Gathering emojis
Makefile
21
star
89

node-hledger

Node.js API for hledger
JavaScript
21
star
90

ractive-promise-alt

Adaptor for Ractive.js to support promises
JavaScript
21
star
91

webpack-starter-kit

Baseline configuration for Webpack
JavaScript
21
star
92

vimbower

Use bower, git and pathogen to manage your vim setup
21
star
93

til-2020

Today I learned blog of @rstacruz
TypeScript
21
star
94

phoenix_expug

Expug integration for Phoenix
JavaScript
20
star
95

cssutils

Collection of Sass utility mixins and other goodies.
CSS
20
star
96

cdnjs-command

Command line helper for cdnjs.com
Ruby
20
star
97

responsive-modular-scale.css

Responsive typography using CSS variables
20
star
98

curlformat

CLI utility to clean up your "Copy as cURL" strings
JavaScript
19
star
99

ractive-loader

ractive template loader for webpack
JavaScript
19
star
100

ajaxapi

Minimal AJAX library for APIs. Supports promises
JavaScript
18
star