- Practical Vim by Drew Nell
- tmux by Brian P. Hogan
- Blogarticle by Mislav vim intro
- Who has the best handicap? Vim golf
Go with MacVim or vim-nox on ubuntu:
brew install vim
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
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 indent on
Add a plugin to ~/.vimrc
and run :PluginInstall
<esc>:PluginInstall
" 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'
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)
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
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-modeu
Undo insert operationO
Prepend line and enter insert-modeo
Append line and enter insert-modeA
Enter insert mode after end of current linea
Enter insert mode after current character
0
Go to Beginning of line^
Go to first printable character in line (whitespaces/tab do not count)$
Go to last character in lineh
1 character leftj
1 character downk
1 line up (same character position or last)l
1 line down (same character position or last)w
go one word aheadb
go one word backwards
dd
Delete lineC
Delete from current position to end of lineD
Delete from current position to end of line
y
Copies current line%y
Yank whole buffer (content of currently open possibly changed file)
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
1,3y
Yank lines 1 through 3
Registers are vim's clipboard.
y"
ory
yank into default buffer<ctrl>r+"
enter insert-mode and enter content of default buffer
ci
Change innerciw
Change inner word (removes current word and enters insert-mode)di"
"Hello!" delete content of quotes and enter insert mode
User ctrl+v
to enter visual mode.
I
Enters insert-mode on all visually selected lines; end with<esc>
h
,j
,k
andl
moves selection
u
Undo an atomar change made in insert-mode.
<ESC>
:set paste<cr>
<i>
<cmd>+v
<ESC>
:set nopaste<cr>
Use tmux visual mode.
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>]
.
Is a session and window manager for unix shells.
brew install tmux
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 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!"
-
<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
This is similar to vim control mode, enter commands or show help for commands.
<leader>:
Enter control mode / command mode
<leader><ESC>
Enter copy mode
Movement as in vim
?
Search backward/
Search forward<RETURN>
Copy selection to session-buffer<leader>p
Paste bufferv
Start selection
tmux save-buffer -|pbcopy
I believe the last line from
.vimrc
should be: