- 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).
:wSave file:qQuit vim:e file.rbOpen file or touch file for editing
Pressing i let's you enter insert-mode. This is the mode most changes / editing is made in.
iEnter insert-mode<esc>Exit insert-modeuUndo insert operationOPrepend line and enter insert-modeoAppend line and enter insert-modeAEnter insert mode after end of current lineaEnter insert mode after current character
0Go to Beginning of line^Go to first printable character in line (whitespaces/tab do not count)$Go to last character in lineh1 character leftj1 character downk1 line up (same character position or last)l1 line down (same character position or last)wgo one word aheadbgo one word backwards
ddDelete lineCDelete from current position to end of lineDDelete from current position to end of line
yCopies current line%yYank whole buffer (content of currently open possibly changed file)
All window operations are cascadable and relate to the currently active panel/window.
<ctrl>w+vsplit window vertically in two panes<ctrl>w+ssplit window horizontally in two panes<ctrl>w+wtoggle through panes
1,3yYank lines 1 through 3
Registers are vim's clipboard.
y"oryyank into default buffer<ctrl>r+"enter insert-mode and enter content of default buffer
ciChange innerciwChange 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.
IEnters insert-mode on all visually selected lines; end with<esc>h,j,kandlmoves selection
uUndo 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>ais the leader (if set, default is<CTRL>b) -
<leader>,Rename window -
<leader>cNew window -
<leader>1-9Open window -
<leader>wOpen window list -
<leader>vVertical split (if set with bind) -
<leader>sHorizontal split (if set with bind) -
<leader><SHIFT>jkMove hori. splitter down/up -
<leader><SHIFT>hlMove 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>pPaste buffervStart selection
tmux save-buffer -|pbcopy
I believe the last line from
.vimrcshould be: