Vim.

Slides:



Advertisements
Similar presentations
In the last Session… ls -l command seven fields nine permissions of a file ls -ld file ownership file permissions (three-tiered file protection system)
Advertisements

CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
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.,
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006.
Vi Editor TA for ITIS3100: Xu Fei
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.
Using Linux Text Editors. Use Non-Graphical Linux Text Editors Graphical Text Editor.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Chapter 3 Mastering Editors
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:
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.
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.
Chapter8 The vi Editor. Introduction to vi u Modes of Operation u The Work Buffer  During the editing session, vi make all changes in the buffer  Advantage.
UNIX Intro vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text.
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.
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:
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
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.
1 Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
Amir Afzal UNIX Unbounded, 5th Edition Copyright ©2008 Chapter 6: The vi Editor – Last Look 1 of 55 Copyright ©2008 by Pearson Education, Inc. Upper Saddle.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 14 – UNIX vi text editor.
Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
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
Vi editor Pronounced: `vee eye‘’.
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Nassau Community College
Vi Editor.
Unix Fundamentals - Part iii vi Editor
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
Linux System Administration Editors
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
The Linux Command Line Chapter 12
Chapter 2 Basic vi Editor.
Linux Operations and Administration
The Emacs Editor Read: Forouzan, Appendix C
Lab 7 Shell Script Reference:
CSCI The UNIX System Editing files
In the last class… The vi basics command, input and ex mode
Day 5 Emacs Editor David A. Gaitros Department of Computer Science
The Linux Command Line Chapter 12
Presentation transcript:

Vim

Introduction Learning vim is fun, intuitive. It is well worth it in the long run. Once you figure out how to use vim's built-in help effectively, you'll learn vim much more comfortably. Vim is mostly preinstalled in every major linux distribution. You can always “sudo apt-get install vim” through the terminal, with an internet connection

Attributes of vim The vim editor is: 01/18/12 Attributes of vim The vim editor is: very powerful and at the same time is cryptic Shifting from windows editors may be difficult but it is the best decision you would think you made once you get to see its power The best way to learn vim commands is to use them So Practice… The Vim help provides almost description of every command used in it

Starting vi Type vi <filename> at the shell prompt 01/18/12 Starting vi Type vi <filename> at the shell prompt After pressing enter the command prompt disappears and you see tilde(~) characters on all the lines These tilde characters indicate that the line is blank

Vi modes There are two modes in vi 01/18/12 Vi modes There are two modes in vi Command mode Input mode When you start vi by default it is in command mode You enter the input mode through various commands You exit the input mode by pressing the Esc key to get back to the command mode

How to exit from vi First go to command mode 01/18/12 How to exit from vi First go to command mode press Esc There is no harm in pressing Esc even if you are in command mode. Your terminal will just beep and/or or flash if you press Esc in command mode There are different ways to exit when you are in the command mode

How to exit from vi (comand mode) 01/18/12 How to exit from vi (comand mode) :q <enter> is to exit, if you have not made any changes to the file :q! <enter> is the forced quit, it will discard the changes and quit :wq <enter> is for save and Exit :x <enter> is same as above command ZZ is for save and Exit (Note this command is uppercase) The ! Character forces over writes, etc. :wq!

01/18/12 Moving Around You can move around only when you are in the command mode Arrow keys usually works(but may not) The standard keys for moving cursor are: h - for left l - for right j - for down k - for up

Moving Around w - to move one word forward b - to move one word backward $ - takes you to the end of line <enter> takes the cursor the the beginning of next line

Moving Around - - (minus) moves the cursor to the first character in the current line H - takes the cursor to the beginning of the current screen(Home position) L - moves to the Lower last line M - moves to the middle line on the current screen

Moving Around f - (find) is used to move cursor to a particular character on the current line For example, fa moves the cursor from the current position to next occurrence of ‘a’ F - finds in the reverse direction

Moving Around ) - moves cursor to the next sentence } - move the cursor to the beginning of next paragraph ( - moves the cursor backward to the beginning of the current sentence { - moves the cursor backward to the beginning of the current paragraph % - moves the cursor to the matching parentheses

Moving Around Control-d scrolls the screen down (half screen) Control-u scrolls the screen up (half screen) Control-f scrolls the screen forward (full screen) Control-b scrolls the screen backward (full screen).

Entering text To enter the text in vi you should first switch to input mode To switch to input mode there are several different commands a - Append mode places the insertion point after the current character i - Insert mode places the insertion point before the current character

01/18/12 Entering text I - places the insertion point at the beginning of current line o - is for open mode and places the insertion point after the current line O - places the insertion point before the current line R - starts the replace(overwrite) mode

Editing text x - deletes the current character 01/18/12 Editing text x - deletes the current character d - is the delete command but pressing only d will not delete anything you need to press a second key dw - deletes to end of word dd - deletes the current line d0 - deletes to beginning of line There are many more keys to be used with delete command

The change command 01/18/12 c - this command deletes the text specified and changes the vi to input mode. Once finished typing you should press <Esc> to go back to command mode cw - Change to end of word cc - Change the current line There are many more options

Structure of vi command 01/18/12 Structure of vi command The vi commands can be used followed by a number such as n<command key(s)> For example dd deletes a line 5dd will delete five lines. This applies to almost all vi commands This how you can accidentally insert a number of characters into your document

Undo and repeat command 01/18/12 u - undo the changes made by editing commands . (dot or period) repeats the last edit command

Copy, cut and paste in vi yy - (yank) copy current line to buffer 01/18/12 yy - (yank) copy current line to buffer nyy - Where n is number of lines p - Paste the yanked lines from buffer to the line below P - Paste the yanked lines from buffer to the line above (the paste commands will also work after the dd or ndd command)

Stupid vi Tricks Indent four lines: 4>> 01/18/12 Stupid vi Tricks Indent four lines: 4>> Will delete the character under the cursor, and put it afterwards. In other words, it swaps the location of two characters: xp Similar to xp, but swapping lines: ddp Remove all lines that start with # :g/^#/d Remove all empty lines, assumes no spaces or tabs: :g/^$/d

01/18/12 Some Practice Using a command line utility called wget let’s pull down a copy of the Gettysburg Address wget –U “ “ http://wildbill.org/rose/gettysburg.txt Now we will run a few commands against the text (note: I placed several blank lines and lines starting with the #)

Gettysburg.txt Run the following commands: vi gettysburg.txt :g/^#/d 01/18/12 Gettysburg.txt Run the following commands: vi gettysburg.txt :g/^#/d :g/^$/d

01/18/12 Gettysburg.txt Invoke vi’s edit mode by pressing the Esc key, then a colon ( : ), and enter: 1,$s/oldstring/newstring/g This will change oldstring into newstring wherever it occurs throughout the entire text. The  1  (the number one) in the above command means "start the search on the first line". The  $  means "end the search on the last line". The  g  at the end executes the change globally on each line. If you omit the  g , the search will stop after finding the first occurrence of oldstring.

Creating a shell script using vi 01/18/12 Create a directory call class Change into class vi myscript.sh inside the file enter following commands clear echo "===========" echo "Hello World" sleep 3 echo Host is $HOSTNAME echo User is $USER

Creating a shell script using vi 01/18/12 Creating a shell script using vi Save the file Change the permissions on myscript.sh chmod 700 myscript.sh <enter> Now execute myscript.sh myscript.sh <enter> Did the script run? Why not? Hint, think about absolute vs relative path Type echo $PATH to see your PATH variable Try this ./myscript.sh <enter> The ./ mean right here in this directory!

Vi – Emacs Holy Wars First salvo – Use vi? How hard could that be? 01/18/12 Vi – Emacs Holy Wars First salvo – Use vi? How hard could that be? Here are the steps for using vi. Procure fish, any kind, length > 12 inches Freeze it overnight Sit in front of PC, run vi Holding fish by the tail, smash it repeatedly against your forehead until you decide to give EMACS a try because the fish scales are flying around and your head is starting to ache.

Vi References The Vi Lovers Home Page The Editor War 01/18/12 Vi References The Vi Lovers Home Page http://thomer.com/vi/vi.html The Editor War http://en.wikipedia.org/wiki/Editor_war