Program Development with Vim

Slides:



Advertisements
Similar presentations
Lesson 12 Getting Started with Excel Essentials
Advertisements

A Guide to Unix Using Linux Fourth Edition
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006.
Chapter 5 Editing Text Files
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
CS 497C – Introduction to UNIX Lecture 9: The vi/vim Editor Chin-Chih Chang
Starting Vi Opening an existing file vi filename Creating a new file vi filename In your workshop directory, create a new file called mysong vi mysong.
CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a.
CSCI 330 T HE UNIX S YSTEM Editing files. E DITOR C ONCEPTS Editing a file is to modify the content of a file Text editor: Enter and modify text in a.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Chapter 3 Mastering Editors
Basic Text Processing, Redirection and Pipes. 222 Lecture Overview  Basic text processing commands head, tail, wc  Redirection and pipes  Getting to.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
The UNIX development environment CS 400/600 – Data Structures.
T HE VI EDITOR. vi has 2 modes: command mode (initial or "default" mode) insert mode [Esc] is used to switch to command mode. In general, vi commands:
Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Productivity Programs Common Features and Commands.
4 Editing files and Emacs Editing files The Emacs editor.
Text editors Why should I use an editor ? It is very important to able to use at least one text mode editor a text mode editor is so useful on remote machines.
Unix Editors. u Editors in Unix come in two general flavours: –modal editors have "modes" v generally input mode and command mode –input mode allows entry.
Tony Kombol.  Why text edit?  Many programs and features require configuration ▪ Configuration is kept in files ▪ Usually in the /etc directory  Changes.
Unix Session IV.
Text Editing February 2 nd, 2004 Class Meeting 3.
1 of 47 Chapter 4: The vi Editor – First Look Copyright ©2008 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved.
Chapter Three Text Editing1 System Programming Text Editing.
Unix Environment Input Output 2  List Content (ls) ◦ ls (list current directory) ◦ ls –all (include hidden files/folders)  Make directory (mkdir) ◦
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
Introduction to Unix (CA263) File Editing By Tariq Ibn Aziz.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Chapter Three The UNIX Editors.
Linux Class #03. File Access Permissions Types of users in Linux: Local User (u) Group User (g) Other User (o) Each User can have 3 types of permissions:
THE vi EDITOR. Introduction There are three editors available in almost all versions of Unix: ed, ex and vi. The ed program is the original editor that.
Text editing and more basic commands CS 2204 Class meeting 3 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session.
Agenda Using vi Editor Starting vi Session Command / Input Modes
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 14 – UNIX vi text editor.
Purdue Linux Users Group Presents Linux 201: Session 1 Everything you ever wanted to do in VIM Thor Smith.
CS:414 introduction to Unix and Linux
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
Practical Office 2007 Chapter 2
SUSE Linux Enterprise Desktop Administration
Vim basics Vi IMproved.
What Every Vi User Should Know about Vim
Guide To UNIX Using Linux Third Edition
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vim.
Vi Introduction Tony Kombol.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Technical University of Kosice
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
You do want to create and edit programs?
Lesson 17 Getting Started with Excel Essentials
vim Basics Understanding And Using the vim Text Editor
Emacs CSC 135.
Key Applications Module Lesson 12 — Word Essentials
Productivity Programs Common Features and Commands
Linux Operations and Administration
The Emacs Editor Read: Forouzan, Appendix C
Key Applications Module Lesson 12 — Word Essentials
CSCI The UNIX System Editing files
Formatting and Editing Skills
In the last class… The vi basics command, input and ex mode
Presentation transcript:

Program Development with Vim

Brief History ed – original (line-oriented) editor of Unix ex – superset of ed commands (Joy) vi – visual (full screen) interface for ex (Joy) circa 1976 vim – Vi improved

Why Use vi/Vim? Part of the standard Unix distribution Always there Available on just about all other platforms Powerful Programmable/configurable Free

Why Use vi/Vim? It’s a programmer’s editor For programmers, by programmers Lets you think like a programmer

Some Philosophy Modal editor insert: typed text becomes part of document normal: typed chars are editing commands Occasionally called command mode (ugh) Allows user to edit without removing hands from the keyboard’s home row - feature? unintended consequence of ‘dumb terminal’ keyboard?

Some More Philosophy As a programmer’s editor, orthogonality plays a big role in the design Combining two features usually works… … and works the way you’d expect it to

A Suggestion Toss out the GUI Toss out the mouse Toss out the toolbar Toss out the menu bar

Before Anything Else… Help :help – enters the help system :help <topic> - positions the help system at the topic It’s not always that simple– read the beginning of the help pages The help system is a text document And can thus be somewhat navigated using vim

Before There was Hypertext … there was the vi help system (I think) Positioning the cursor over a highlighted topic and pressing <Ctl-]> takes you to the topic <Ctl-O> / <Ctl-T> takes you back

And Then There’s Vimtutor Go to the installation directory and run vimtutor.bat

Normal Mode Movement h, j, k, l – left, down, up, right 0, ^, $ - beginning, 1st nonblank, end of line w – forward one word b – backward one word <n>G – go to line n G – go to last line gg – go to first line <Ctl-F>, <Ctl-B> - forward back one page

Search within Line f<c> – forward (on)to character c F<c> – backward (on)to character c t<c> – forward (up) to character c T<c> – backward (up) to character c

Other Normal Mode Commands i, a – enter insert mode (insert/append) exit via <Esc> x – delete char r – replace char w – write file ZZ – write file and quit vi

Adding Count <n><command> - perform command n times 10x 5w 10j

Movement-Based Commands d – delete text of movement dw – delete word dt) – delete text until ) c – change text of movement (insert mode) cw – change word y – yank (copy) text of movement y$ – yank to end of line

The General Form <n><action><n><movement> 10dw c2w 2cw

Doubles and Caps Doubling action’s character often makes it operate on the entire line dd, yy Capitalizing action often goes to end of line (or some other ‘enhanced’ action) C, D R – replace multiple chars (enters insert mode) Y – delete to end of line

Repeating Commands . (period) - repeats the last command performed in normal mode. I use it for inserting HTML tags in my lecture notes i<code><Esc> Then I move to the next spot and press . … and so on

Marking Locations m<letter> - Marking a location '<letter> (single quote) - go to the beginning of the line of marked location `<letter> (backtick) - go to line and column of marked location Uppercase letter marks work between files

Searching /<pattern>/ Wraps around at end/beginning of file /main/ Will incrementally search as pattern is typed ?<pattern? - searches backwards //, ?? - repeats search Wraps around at end/beginning of file

Command (Line) Mode Commands requiring more user input than a couple of characters Commands operating on multiple lines Entered by typing : Subsequent entry occurs on bottom line General form: <line range><action>… Line range is of form <start>,<end>

Some Commands wq – write and quit (like ZZ) :<n> - go to line n :<range>d – delete range of lines :10,20d :<range>s/<patt>/<replacement>/gc :5,10s/hello/goodbye/ Can use ‘any’ character as delimiter wq – write and quit (like ZZ)

Line Specifications Line # Symbolic Expression Search Marks ., $, % .+1, $-2 Search /main/ Marks 'a

Not Everyone Can Be Perfect u – undo <Ctl>-R – redo

Repeating Commands Cursor keys work in command line mode There’s also a command line history you can search and edit For another day

Seeing is Believing – Visual Mode Highlights selected text From normal mode v – plain visual mode Highlights on a character basis <Shift-V> - linewise visual mode Highlights on a line basis <Ctl-V> - block visual mode Highlights on a column (rectangular) basic

Reg\(ular \)\?Ex\(pression\)\? /Search\(ing\|es\)/ Provides search pattern based on regular expressions Added bonus: you get to learn regex’s

Regular Expressions Patterns used for search (and replacement) Uses metacharacters for pattern specification Perl is the standard these days Vim’ is similar but not identical Filename wildcards on LSD

Basic categories . (period) – any character except newline \s – any whitespace character \d – digit \a, \l, \u – alpha, lowercase, uppercase Uppercase flips parity \S – non-whitespace \D – non-digit

Anchors ^, $ - beginning / end of line \<, \> - word boundaries

Character Ranges [aeiou] – matches any of the specified characters [0-9] – matches any character from 0 through 9 (in the underlying character set) Above two canbe combined [A-Za-z0-9_] [^A-Z] – matches any character except A through Z

Grouping \(, \) Used for any precedence issues But more importantly allow subsequent retrieval of matched text (during replacement) These are called backreferences

Alternation <pattern1> \| <pattern2> Matches pattern1 OR pattern2 \(int | double\)

Replacement Has its own set of meta-characters to allow retrieval &, \0 – all the text that matched the pattern \1, \2, … - the text of the n’th matched group

Buffers – Multiple Files :set hidden – allows you to move freely between buffers :e <file> - brings a new file into the editor Placed into its own buffer :buffers – displays info about the buffers :b<n> - edits buffer n

Multiple Windows :split – horizontal window split :vsplit – vertical window split <Ctl-W><action> performs window-related action h, j, k, l – moves to window in that direction There are resizing, and moving actions as well :q (ZZ) closes window

Programming Aids Vim can just about be transformed into a full IDE We’ll look at a few simple features Indentation Delimiter matching/navigating Running commands from within the editor Navigating compilation errors

Fixing Indentation <<, >> (normal mode) – shift one tab position to the left/right Don’t forget about . <, > does same in command mode :4,20> = – indent Works with motion =10 =/void/

Indenting as You Code :set cindent :set smartindent :set autoindent Follows C/C++/Java ‘standard’ rules :set smartindent Indents after {; unindents after ‘}’ :set autoindent Indents to same level as previous line

Autocompletion <Ctl-N>, <Ctl-P> - next/previous word matching the prefix under the cursor :set complete option controls where to search for words Dictionaries can be also be loaded and used for non-code files Commands are slightly different Spell checking is available as well

Running Commands :!<command> - runs command in a shell :sh – enters a shell exiting the shell (e.g. <Ctl-D> or <Ctl-Z>) returns you to the editor In particular: :!g++ *.cpp :!a.out

Navigating Compiler Errors Compile your code, redirecting errors to a file :!g++ *.cpp 2>errors Inform Vim of the existence of the error file :!cfile errors :set errorfile=errors sets the file as the default error file Then just have to write :!cfile

Navigating Compiler Errors (cont’d) Navigate through the errors with :cc - display current error :cc<n> - display error n :cn – next error :cp – previous error :clist – list all errors

Tips Don’t try to master it all at once Try to add one feature a week If you ‘discover’ a new feature, try to use it often Google, google, google

A Most Important Tip Learn to touch type!!! http://www.typing.com/tutor/courses/ In case you didn’t hear me—