vim, vimshell, mintty ( cool stuffs!)

Vim Tricks

Let's see some of vim's advanced features:
1. vim in multiple windows;
2. use vim's tabs function (vim 7.1+) ;
3. vim spelling;
4. vimshell (having a shell inside vim!)
5. more advanced vim commands.


(click the image for large view)



#1.split screens and editing multiple files:
vim -o file1 file2 to start vim in split-mode editing two files
if already inside vim working with one file, use :sp command to split/open new file
:sp filename #opens a new file and split screen in vim
:n new_file #opens a new file and replace current file
:b new_file #opens a new file and replace current file
:args #to see which files are open with

#CTRL W + j,k key to switch/toggle between windows/files
#CTRL W + s or v to split current window horizontally or veritically
#CTRL W + c to close current window
#CTRL W + x to swap window positions

#2. use vim's tabs to edit multiple files- far superior to buffer ( for vim 7.1+)
:tabe filename #opens a file in a new tab (a new thread of vim)
:tabn or gt #go to next file in tab
:tabp or gT #go to previous file in tab
:ls #to see a list of current tabs/buffers
:1b #to switch to the 1st tab/buffer same as gt/tabn cmds
:2b #to switch to the 2nd tab/buffer same as gt/tabn cmds
:help tabe #to see tab's help


#3. vim spelling
To switch on: :setlocal spell spelllang=en_us
To switch off::set nospell
:help spell to see details.

navigation:
]s - next misspelled word
[s - prev "

interaction:
zg - add misspelled word to system dictionary
zG - add misspelled word to buffer-local set of "good" words
zw - add word to 'bad' list
zW - add word to buffer-local 'bad' list
z= - view a numbered list of suggested spellings from which to choose for auto-replacement

#4. Need a shell inside vim window? Isn't just hitting Ctrl_W e/E to drop a shell window in your VIM session cool?!
With this feature, I virtually can do administration tasks without leaving vim. Perfect for coding while doing admin tasks.

To setup is simple, just patch vim with vimshell and define ctrl_w e/E in your .vimrc file with these mappings:

" VIM-Shell
" Ctrl_W e opens up a vimshell in a horizontally split window
" Ctrl_W E opens up a vimshell in a vertically split window
" The shell window will be auto closed after termination
nmap <C-W>e :new \| vimshell bash<CR>
nmap <C-W>E :vnew \| vimshell bash<CR>


Now, let's see something very cool! - run vim inside mintty in transparent mode...



Or, run mintty in glass mode...



#5. some useful vim commands
#load VIM without .vimrc and plugins (clean VIM)
gvim -u NONE -U NONE -N
" execute multiple command on a single file
vim -c "%s/ABC/DEF/ge | update" file1.c
" execute multiple command on a group of files
vim -c "argdo %s/ABC/DEF/ge | update" *.c
gvim.exe -c "/main" joe.c : Open joe.c & jump to "main"
gvim -d file1 file2 : vimdiff (compare differences)
dp : "put" difference under cursor to other file
do : "get" difference under cursor from other file
--------------------------------------------------------------------------
:reg : display contents of all registers
:reg a : display content of register a
:let @y='yy@"' : pre-loading registers (put in .vimrc)
qqq : empty register "q"
qaq : empty register "a"
:h quickref : VIM Quick Reference Sheet (ultra)
:h tips : Vim's own Tips Help
--------------------------------------------------------------------------
" where was an option set
:scriptnames : list all plugins, _vimrcs loaded (super)
:verbose set history? : reveals value of history and where set
:function : list functions
:func SearchCompl : List particular function
--------------------------------------------------------------------------
:'a,'bg/^/m'b : Reverse a section a to b
:g/^/t. : duplicate every line
:g/fred/t$ : copy(transfer) lines matching fred to EOF
:g/gladiolli/# : display with line numbers
--------------------------------------------------------------------------
:%s#<[^>]\+>##g : delete html tags, leave text (non-greedy)
:%s#<\_.\{-1,}>##g : delete html tags possibly multi-line (non-greedy)



Resources:
1. vi Complete Key Binding List.
2. Hardcore vim tips.
3. Daily vim tip page.
4. vim's color scheme.
5. vim official site for python syntax and all other scripts.
6. A very good vimrc file. (For more, visit vim's home page.)

Warning: vim is fun but can also be addictive, please allocate your time wisely.
I started my day programming Python, but found my self playing vim until mid-night... all I had was a fun day!


sample .bashrc
# To pick up the latest recommended .bashrc content,
# look in /etc/defaults/etc/skel/.bashrc

# Modifying /etc/skel/.bashrc directly will prevent
# setup from updating it.

# The copy in your home directory (~/.bashrc) is yours, please
# feel free to customise it to create a shell
# environment to your liking. If you feel a change
# would be benificial to all, please feel free to send
# a patch to the cygwin mailing list.

# User dependent .bashrc file


# Shell Options
# #############

# See man bash for more options...

# Don't wait for job termination notification
# set -o notify

# Don't use ^D to exit
# set -o ignoreeof

# Use case-insensitive filename globbing
# shopt -s nocaseglob

# Make bash append rather than overwrite the history on disk
# shopt -s histappend

# When changing directory small typos can be ignored by bash
# for example, cd /vr/lgo/apaache would find /var/log/apache
# shopt -s cdspell


# Completion options
# ##################

# These completion tuning parameters change the default behavior of bash_completion:

# Define to access remotely checked-out files over passwordless ssh for CVS
# COMP_CVS_REMOTE=1

# Define to avoid stripping description in --option=description of './configure --help'
# COMP_CONFIGURE_HINTS=1

# Define to avoid flattening internal contents of tar files
# COMP_TAR_INTERNAL_PATHS=1

# If this shell is interactive, turn on programmable completion enhancements.
# Any completions you add in ~/.bash_completion are sourced last.
# case $- in
# *i*) [[ -f /etc/bash_completion ]] && . /etc/bash_completion ;;
# esac


# History Options
# ###############

# Don't put duplicate lines in the history.
# export HISTCONTROL="ignoredups"

# Ignore some controlling instructions
# export HISTIGNORE="[ ]*:&:bg:fg:exit"

# Whenever displaying the prompt, write the previous line to disk
# export PROMPT_COMMAND="history -a"


# Aliases
# #######

# Some example alias instructions
# If these are enabled they will be used instead of any instructions
# they may mask. For example, alias rm='rm -i' will mask the rm
# application. To override the alias instruction use a \ before, ie
# \rm will call the real rm not the alias.

# Interactive operation...
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

# Default to human readable figures
# alias df='df -h'
# alias du='du -h'

# Misc :)
# alias less='less -r' # raw control characters
# alias whence='type -a' # where, of a sort
alias grep='grep --color' # show differences in colour

# Some shortcuts for different directory listings
alias ls='ls -hF --color=tty' # classify files in colour
# alias dir='ls --color=auto --format=vertical'
# alias vdir='ls --color=auto --format=long'
# alias ll='ls -l' # long list
# alias la='ls -A' # all but . and ..
# alias l='ls -CF' #


# Functions
# #########

# Some example functions
# function settitle() { echo -ne "\e]2;$@\a\e]1;$@\a"; }