Marginally Useful VIM Tricks - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Marginally Useful VIM Tricks

Description:

The text editor is a program we use so frequently that it is worthwhile to ... Without any customizations, I find VI and VIM to be nearly unbearable. Customizing VIM ... – PowerPoint PPT presentation

Number of Views:294
Avg rating:3.0/5.0
Slides: 19
Provided by: jok4
Category:

less

Transcript and Presenter's Notes

Title: Marginally Useful VIM Tricks


1
Marginally Useful VIM Tricks
  • COS Club Enrichment Series
  • Jason OKane
  • October 31, 2000

2
Premise and Purpose
  • The premise
  • The text editor is a program we use so frequently
    that it is worthwhile to invest effort in getting
    the environment just right.
  • The purpose
  • To provide an introduction to what VIM can to do
    and to stimulate further exploration.

3
A Confession
Without any customizations, I find VI and VIM to
be nearly unbearable.
4
Customizing VIM
  • Create a file in your home directory called
    .vimrc
  • Put commands in it.

5
From jokanes .vimrc
version 4.0 set bs2 set ruler set incsearch set
showmatch set ai set laststatus2 set
shiftwidth2 set tabstop2 set visualbell set
ignorecase cab W w cab Q q cab E e cab Sp sp cab
SP sp cab Wq wq iab i include iab d define
6
Cool Settings
  • syntax on
  • activates syntax highlighting
  • incsearch
  • shows next match so far
  • showmatch
  • matches parens, brackets, etc. (vital for LISP)
  • ignorecase
  • case-insensitive searches

7
More Cool Settings
  • visualbell
  • switches from annoying bell to soothing flash
  • bs2
  • allows liberal use of backspace
  • Use help option-summary for a complete list of
    settings

8
Abbreviations
  • Command Abbreviations
  • cab W w
  • cab Q q
  • Insert Mode Abbreviations
  • iab d define
  • iab i include

9
Mappings
  • Shift Key? Humbug!
  • map
  • map w wltC-Mgt
  • map q qltC-Mgt

10
.viminfo
  • VIM can store commands, buffer contents, search
    patterns, etc. between editing sessions.
  • set viminfo'1,f0,50,/50,n/vim/viminfo

11
Working with Multiple Files
  • sp ltfilenamegt
  • opens another file
  • sp
  • opens another window with the current file
  • CTRL-W ltdirectiongt
  • switches to another open file
  • Q
  • closes the current file

12
Exceptionally Nerdy Scripts
  • Spelling Checker
  • 2-keystroke Make
  • File Skeleton System

13
Spelling Checker
  • /vim/spell.vim lists all English words
  • command line spell used to create list of words
    to show in red

fu! Spell() w!spell0.tmp !spell lt spell0.tmp
gt spell1.tmp !sed -e"s//syntax keyword
ErrorMsg /" lt spell1.tmp gt spell2.tmp !echo
syntax clear gt spell3.tmp !cat spell2.tmp gtgt
spell3.tmp syntax on so spell3.tmp so
/vim/spell.vim !rm spell0.tmp spell1.tmp
spell2.tmp spell3.tmp endf
14
2-Keystroke Make
  • Executes a make the current directory.
  • Shows the results (read error messages) in a
    split window

15
2-Keystroke Make
fu! Make() pe mrn "make-results" "
Create a buffer to hold the make results, if
needed. " Assume that if there's a
make-results buffer, it's the current one "
This is reasonable since the mapping below moves
up 99 windows before " calling this make
function. pe if(maincurbuf-gtName() ne mrn)
VIMDoCommand("new") VIMDoCommand("e
mrn") pe if(maincurbuf-gtName() ne mrn)
VIMDoCommand("e mrn") " Empty out the
buffer pe maincurbuf-gtDelete(1,
maincurbuf-gtCount) " Execute make "
The zero is needed in order to read into an empty
buffer. 0r!make " Allow users to close the
window without saving the results set
nomodified endf map m ltC-Wgt99kcall
Make()ltC-MgtltC-MgtltC-Wgtj
16
File Skeleton System
  • Reads in a skeleton when a new file is created.
  • New file types can be added simply by creating
    new files in the skeleton directory.

17
File Skeleton System
pe HOME "/home/users9/jokane" pe SKEL
"HOME/vim/skel" fu! ReadSkel() pe fname
maincurbuf-gtName() pe (ext) (fname
/\.(a-z)/) pe VIMMsg("yo SKEL/ext")
pe if(-e "SKEL/ext") VIMDoCommand("r
SKEL/ext") pe maincurbuf-gtDelete(1) end
f au! au BufNewFile call ReadSkel()
18
What was that again?
  • If you remembered all of that, seek professional
    help.
  • If not, find these slides and code at

http//www.css.tayloru.edu/jokane/vim
Write a Comment
User Comments (0)
About PowerShow.com