+ - 0:00:00
Notes for current slide
Notes for next slide

Customizing Vim

An Introduction To Your .vimrc

Kyle Rich

1 / 25

Overview

  • Motivation
  • Vim concepts
  • Defaults
  • Keyboard shortcuts
  • Plugins
2 / 25

Overview

- What this is not

This talk is not ...

  • A history of Vim. It's old, but still going strong. Enough said.
  • An Emacs roast. I actually don't know enough about Emacs to even attempt it.
  • For experienced users. Seriously, you probably know more than me.
3 / 25

Overview

- What this is not

- What this is

This talk is ...

  • An introduction to what's in your configuration file
  • For people who want to become more proficient with Vim
  • Show and tell
  • Partially based on opinion
    • I don't think anything involving Vim isn't...
4 / 25

Show and tell is scary. I'm trying to show you the things that were the keys to my understanding, but that reveals to you how I learn, and that's scary.

Overview

- What this is not

- What this is

- My goal

My goal for this talk is for you to feel equipped to look at someone else's .vimrc file, and learn something from it.
5 / 25

Motivation

- What I love

  • Almost universally available
  • Portable configuration
  • Syntax highlighting for almost everything
  • Customizable / Extensible
  • Repeat command / macros
6 / 25

Motivation

- What I love

  • Almost universally available
  • Portable configuration
  • Syntax highlighting for almost everything
  • Customizable / Extensible
  • Repeat command / macros

But mostly...

My hands stay on home row!

6 / 25

Motivation

- What I love

- Keyboard shortcuts

You will find yourself using h, j, k, and l for navigation in the craziest places.

  • GMail
  • Feedly
  • more / less
  • man
  • This very presentation
7 / 25

Vim Concepts

- Editor modes

Two basic modes

  • Normal (which never seems normal to new users)
  • Insert

Press i to go from Normal to Insert

Press <esc> to go from Insert to Normal

8 / 25

Vim Concepts

- Editor modes

- Advanced editor modes

At least three more modes:

  • Visual mode for selecting text
    • Press v to enter normal visual mode
    • Press <Shift-v> to enter visual line mode
    • Press <Ctrl-v> to enter visual column mode
  • Command mode for entering commands to Vim
    • Press : to enter
  • Replace mode for writing over existing words
    • Press <Shift-R> to enter
9 / 25

Vim Concepts

- Editor modes

- Advanced editor modes

- Commands

  • :w for write to save
  • :q to quit
  • :e for edit
  • :h for help

Just remember to be in normal mode first!

10 / 25

Vim Concepts

- Editor modes

- Advanced editor modes

- Commands

- vimrc

  • Default location is the root of your user folder, ~/.vimrc
  • Since Vim 7.4, will also look for ~/.vim/vimrc
  • See Tom Vincent's blog for help making Vim conform to the XDG spec
11 / 25

Defaults

- General

" Turn off vi compatibility, use advanced vim-only features
set nocompatible
" Turn on syntax highlighting
syntax enable
" Set colors to use 256 color palette
set t_Co=256
" Use the system clipboard as the default copy register
set clipboard=unnamed
" Copy indentation level when creating a new line
set autoindent
" Try to put the indent level at the right place
set smartindent
" Keep vim files in the ~/.vim folder
set viminfo='100,h,n~/.vim/viminfo
12 / 25

Defaults

- General

- Searching

" Case insensitive search
set ignorecase
" Unless there is mixed case, then make it case sensitive
set smartcase
" Highlight search terms instead of just moving the cursor
set hlsearch
" Highlight search terms as you type them
set incsearch
13 / 25

Keyboard Shortcuts

- Map

  • map is used to map shortcuts to actions
  • Usage is map [sequence of keys] [sequence of keys]
  • When you press the sequence of keys on the left, Vim types the sequence on the right
  • You can use key modifiers like Alt, by putting it in angle brackets <Alt-h>
  • nnoremap <A-h> :bp<cr> maps <Alt+h> to type :bp followed by the enter key (carriage return)
14 / 25

Keyboard Shortcuts

- Map

- Non-recursive mode

  • Vim already has a ton of keyboard shortcuts, and plugins all introduce their own
  • We need a way to keep from stepping on the toes of other shortcuts
  • Non-recursive maps solve this problem
  • Prepend nore to a keyboard mapping to make it non-recursive

noremap <leader>' <esc>:qa!<cr>

15 / 25

Keyboard Shortcuts

- Map

- Non-recursive mode

- Mode filtering

  • Maps can optionally apply only to specific modes
  • Prepend the character code for the mode to the map
  • i - Input mode
  • n - Normal mode
  • c - Command mode
  • v - Visual mode

Type :help map-modes for more information

16 / 25

Keyboard Shortcuts

- Map

- Non-recursive mode

- Mode filtering

- Leader

  • The "leader" key is just an alias to some other key, but you can change the alias
  • <leader> shows up all the time, particularly in shortcuts specific to plugins

Set the leader:

let mapleader=","

Use leader in a shortcut:

noremap <leader>sn :set number!<cr>

17 / 25

Keyboard Shortcuts

- Map

- Non-recursive mode

- Mode filtering

- Leader

- Common shortcuts

" Set the leader to comma, it'll grow on you
let mapleader=","
" Set the sequence 'jk' to hit escape
" This will make leaving input mode easier
inoremap jk <esc>
" This will save you when you discover you
" don't have permission to save a file
cnoremap w!! w !sudo tee % >/dev/null
" These make moving around easier with wrapped lines
nnoremap j gj
nnoremap k gk
" These allow you enter command mode without the shift key
nnoremap ; :
vnoremap ; :
18 / 25

Plugins

- Who reads these anyways?

You will be hard pressed to find an editor or IDE with more plugins than Vim.

  • I count 190 plugins for Notepad++
19 / 25

Plugins

- Who reads these anyways?

You will be hard pressed to find an editor or IDE with more plugins than Vim.

  • I count 190 plugins for Notepad++
  • Atom has 4,539 packages
19 / 25

Plugins

- Who reads these anyways?

You will be hard pressed to find an editor or IDE with more plugins than Vim.

  • I count 190 plugins for Notepad++
  • Atom has 4,539 packages
  • VimAwesome contains 12,975 Vim plugins at the time of this writing
19 / 25

Plugins

- Who reads these anyways?

- Plugin manager

A plugin manager will make it simple to manage and load your Vim plugins.

A few common managers include:

  • Pathogen
  • Vundle
  • Plug
  • VAM
20 / 25

Plugins

- Who reads these anyways?

- Plugin manager

- Manager bootstrapping

" Vim Plug automatic installation
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fsLo ~/.vim/autoload/plug.vim \
--create-dirs https://raw.githubusercontent.com\
/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
21 / 25

Plugins

- Who reads these anyways?

- Plugin manager

- Manager bootstrapping

- Management

" Plugins
call plug#begin('~/.vim/plugged')
" Color schemes
Plug 'vim-scripts/wombat256.vim'
" Core plugins
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdtree'
Plug 'sjl/gundo.vim'
Plug 'easymotion/vim-easymotion'
Plug 'ConradIrwin/vim-bracketed-paste'
" Git
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
" Language specific
Plug 'jmcantrell/vim-virtualenv', {'for': 'python'}
Plug 'plasticboy/vim-markdown', {'for': 'markdown'}
call plug#end()
22 / 25

Plugins

- Who reads these anyways?

- Plugin manager

- Manager bootstrapping

- Management

- Portability demo

And now a quick demonstration...

23 / 25

Questions?

24 / 25

Resources

Please leave feedback!

https://joind.in/talk/09b88

25 / 25

Overview

  • Motivation
  • Vim concepts
  • Defaults
  • Keyboard shortcuts
  • Plugins
2 / 25
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow