Skip to content

Instantly share code, notes, and snippets.

@przbadu
Forked from fredv/vimux.md
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save przbadu/85305e2ead51d24bef17 to your computer and use it in GitHub Desktop.
Save przbadu/85305e2ead51d24bef17 to your computer and use it in GitHub Desktop.

Vim/Tmux Setup

Reads

Vim

Install

Go with MacVim or vim-nox on ubuntu:

brew install vim

~/.vimrc

Config settings and key mappings for vim. Bundle management via vundle is helpful. Start empty, grow slow. Do not copy whole .vimrc.

" Syntax highlighting
syntax on
" Sets line number, nonu disables line numbers
set nu
" Shows non-printable characters
set list
" Sets tab size
set tabstop=2
" Sets shift character shift
set shiftwidth=2
" Use 2 whitespaces for \\t tab
set expandtab
" Highlights next search matches
set incsearch

" relative line numbers
" set relativenumber

~/.vim/ Plugins

Vundle for vim plugins

git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Add to ~/.vimrc

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" Add other plugins.
" Keep Plugin commands between vundle#begin/end.
" e.g. for fugitive:
" Plugin 'tpope/vim-fugitive'

call vundle#end()

filetype plugin indenx on

Add a plugin to ~/.vimrc and run :PluginInstall

<esc>:PluginInstall

Plugins to start with

" Syntax checking for many languages
Plugin 'scrooloose/syntastic'
" Expandable search
Plugin 'kien/ctrlp.vim'
" Boilerplate/Snippets for vim
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
" Tmux support
Plugin 'benmills/vimux'
" Git integration
Plugin 'tpope/vim-fugitive'
" In-place reformatting to CamelCase or dasher_rize
Plugin 'tpope/vim-abolish'
" Ack or Ag support:
Plugin 'rking/ag'

Specific for Go-lang: Plugin 'kien/vim-go.vim'

Mappings

Add map statements to ~/.vimrc. There are special notations for example the <leader>-key which can be custom set.

map ,t :CtrlP

This maps keys <,> to command CtrlP (which is the advanced Command-T command known from browsing files in TextMate/Sublime)

Usage

Modes

Control-mode

Enter Control-mode by pressing <ESC>, you then see a :-colon on the bottom of the screen and can insert commands followed by a <cr> carriage-return (Return key/Enter).

  • :w Save file
  • :q Quit vim
  • :e file.rb Open file or touch file for editing

Insert-mode

Pressing i let's you enter insert-mode. This is the mode most changes / editing is made in.

  • i Enter insert-mode
  • <esc> Exit insert-mode
  • u Undo insert operation
  • O Prepend line and enter insert-mode
  • o Append line and enter insert-mode
  • A Enter insert mode after end of current line
  • a Enter insert mode after current character
Movement in insert mode
  • 0 Go to Beginning of line
  • ^ Go to first printable character in line (whitespaces/tab do not count)
  • $ Go to last character in line
  • h 1 character left
  • j 1 character down
  • k 1 line up (same character position or last)
  • l 1 line down (same character position or last)
  • w go one word ahead
  • b go one word backwards
Deletion
  • dd Delete line
  • C Delete from current position to end of line
  • D Delete from current position to end of line
Copy / Yank
  • y Copies current line
  • %y Yank whole buffer (content of currently open possibly changed file)
Window control

All window operations are cascadable and relate to the currently active panel/window.

  • <ctrl>w+v split window vertically in two panes
  • <ctrl>w+s split window horizontally in two panes
  • <ctrl>w+w toggle through panes
Ranges
  • 1,3y Yank lines 1 through 3
Register control

Registers are vim's clipboard.

  • y" or y yank into default buffer
  • <ctrl>r+" enter insert-mode and enter content of default buffer

Combined commands

  • ci Change inner
  • ciw Change inner word (removes current word and enters insert-mode)
  • di" "Hello!" delete content of quotes and enter insert mode

Visual-mode

User ctrl+v to enter visual mode.

  • I Enters insert-mode on all visually selected lines; end with <esc>
  • h, j, k and l moves selection

Undo

  • u Undo an atomar change made in insert-mode.

Pasting text from clipboard

<ESC>
:set paste<cr>
<i>
<cmd>+v
<ESC>
:set nopaste<cr>

Yanking/Copying to clipboard

Use tmux visual mode.

Advanced

ctags

ctags allow systematic syntax linking in many languages. E.g. "new Photo" links to /app/models/photo.rb class definition.

Install ctags

brew install ctags

Add majutsushi/tagbar plugin to ~/.vimrc " Runs ctags automatically and adds :TagBar to inspect ctags Plugin 'majutsushi/tagbar'

Jump to definition <leader>].

Tmux

Is a session and window manager for unix shells.

Reading

Install

brew install tmux

Usage

Start a new session:

tmux

or

tmux new -s phrase

Attach to a running session

tmux attach -t phrase

Find out running sessions

tmux list-sessions

Config

Config is under ~/.tmux.conf:

# set-option -g default-command "reattach-to-user-namespace -l zsh"
set-option -g prefix C-a
set-option -g status-keys vi
setw -g mode-keys vi

set-option -g default-shell /bin/zsh
set-option -g history-limit 10000
set -g repeat-time 1000
set -g default-terminal "xterm-256color"

set -s escape-time 1
set -g base-index 1
set -g pane-base-index 1

# mouse stuff
setw -g mode-mouse off
set -g mouse-select-pane off
set -g mouse-resize-pane off
set -g mouse-select-window off


# VIM setting
# splitting
bind | split-window -h
bind v split-window -h
bind - split-window -v
bind s split-window -v

# resizing
bind -r h select-pane -L
bind -r j select-pane -D
bind -r k select-pane -U
bind -r l select-pane -R

bind -r H resize-pane -L 1
bind -r J resize-pane -D 1
bind -r K resize-pane -U 1
bind -r L resize-pane -R 1

# copy mode
bind p paste-buffer
bind Escape copy-mode

bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'V' begin-selection
bind-key -t vi-copy 'y' copy-selection

# status
set -g status-left-length 40set -g status-right-length 40set -g status-left '#(current_project)|#S|#h'
#set -g status-right '#(date +"%H:%M") #(~/scripts/icinga_status)'

set -g status-justify centre
set -g status-interval 10
unbind %
bind r source-file ~/.tmux.conf \; display "Reloaded!"

Window management

  • <CTRL>a is the leader (if set, default is <CTRL>b)

  • <leader>, Rename window

  • <leader>c New window

  • <leader>1-9 Open window

  • <leader>w Open window list

  • <leader>v Vertical split (if set with bind)

  • <leader>s Horizontal split (if set with bind)

  • <leader><SHIFT>jk Move hori. splitter down/up

  • <leader><SHIFT>hl Move vert. splitter left/right

Control mode

This is similar to vim control mode, enter commands or show help for commands.

  • <leader>: Enter control mode / command mode

Copy mode

  • <leader><ESC> Enter copy mode

Movement as in vim

in copy mode

  • ? Search backward
  • / Search forward
  • <RETURN> Copy selection to session-buffer
  • <leader>p Paste buffer
  • v Start selection

Tips & Tricks

Copy to Clipboard

tmux save-buffer -|pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment