Vim basics Vi IMproved.

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
Introduction to the gedit editor. gedit: the Gnome editor Gnome: Gnome is a freely available (i.e., no cost) desktop environment for the UNIX system The.
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
CS 497C – Introduction to UNIX Lecture 10: The vi/vim Editor Chin-Chih Chang
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.
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.
Copyrights© 2008 BVU Amplify DITM Basics of OS,UNIX/LINUX and Shell programming Page:1 Lesson 3: Vi- editor By Simi By Simi.
Visual Studio Tips and Tricks. Credits Zain Naboulsi Microsoft Developer Evangelist isbn:
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 Three The UNIX Editors. 2 Lesson A The vi Editor.
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:
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.
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.
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.
Chapter 9 Using Text Editors. vi Editor visual Editor, ASCII text editor, no formatting capabilities almost as powerful as MS Word, has 26 clipboards.
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:
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.
BIF703 FTP (File Transfer Protocol) Utility vi editor Utility.
Pasewark & Pasewark 1 Word Lesson 2 Basic Editing Microsoft Office 2007: Introductory.
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
Microsoft Word 2016 Lesson 1.
Using Vi(m) This presentation on using the Vi(m) editor will cover:
Guide To UNIX Using Linux Third Edition
Vi Editor.
Vim.
Vi Introduction Tony Kombol.
Linux 104 Training Module File Editing.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
Technical University of Kosice
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
The Linux Command Line Chapter 12
vim Basics Understanding And Using the vim Text Editor
Emacs CSC 135.
Benchmark Series Microsoft Word 2016 Level 1
Chapter 2 Basic vi Editor.
Lesson 1 – PowerPoint Essentials
Linux Operations and Administration
The Emacs Editor Read: Forouzan, Appendix C
CSCI The UNIX System Editing files
In the last class… The vi basics command, input and ex mode
The Linux Command Line Chapter 12
Presentation transcript:

vim basics Vi IMproved

What is vim? Text editor. Very efficient. Open source. Based off older editor; vi. Very efficient. Open source. Available for UNIX based distros, MAC, Windows, and others.

Starting vim In a terminal session, enter: vim [options] [file …] [options] is a list of zero or more options to start your windows with. [file …] is a list of zero or more files to edit. vim will open windows using [options] with the [file …]. Talk about the relation between files, buffers, and windows.

What will the following commands do? Note that ‘-o’ and ‘-O’ are options that open the file list vertically (think a stack of pancakes), or horizontally (think a line of dominoes). vim textline.cpp vim –o textline.cpp textline.h vim –O textline.cpp textline.h vim CTRL-w CTRL-w is a shortcut for switching to the next window.

vim textline.cpp

vim –o textline.cpp textline.h

vim –O textline.cpp textline.h

vim

Take note vim is case sensitive! CTRL-<key> means holds down CTRL and press <key>. <sometext> means replace <sometext> with some text. 2d<exampletext> => 2dfoo, 2dbar, 2d$$, etc. [text] means the addition of text is optional. 2d[<exampletext>] => 2d, 2dbanana, etc. 2d[exampletext] => 2d, 2dexampletext

Navigation While not in Insert mode, each of the following commands moves the cursor one character in a direction. h – Left. j – Down. k – Up. l – Right (an L). To move by a word. b – Backward. w – Forward. gg goes to the first line of file, G the last.

Image source: https://coderwall

How do you use vim? vim is operated in several modes. normal (command) insert visual etc. We will only focus on normal, insert, and visual mode. To switch between modes, press ESC to go to normal mode, and then enter the command that starts the mode you wish to be in.

Normal (command) mode Normal mode is where we enter commands. Commands can do a variety of things. Enter another mode. Copy, paste, and delete text. Search for text. Set options. And much more.

Insert mode Lets us insert new text into a file. While in Normal mode, press i, a, o, I, A, or O to enter Insert mode. The only difference in the options is where we begin inserting text. i – Before cursor. a – After cursor. I – Before beginning of line. A – After end of line. o – Below line on newly created line. O – Above line on newly created line.

Insert mode cont. Once you are in insert mode, any key you press will be put into the file at the cursor’s position. The exceptions are any CTRL-<key> and ALT-<key>.

Visual mode Lets us highlight text and perform commands on the highlighted text. There are three different highlighting methods. plain (as in vanilla) : v block : CTRL-v linewise : SHIFT-v

Operators, counts, and motions Many commands are just a mixture of an operator and a motion. Operator: Specifies what type of command we want to perform. d for delete, p for ‘paste’, … Motion: How the operator will be used. w – until start of next word, excluding its first character. e – to end of current word, including the last character. $ - until end of line, including the last character. <ARROW KEYS> – try it out. Many more. Count: How many times to repeat a command. [<count>]<command>; i.e. 2dw – delete 2 words

Common commands Yank (copy): y<motion> Put (paste): p Delete: d<motion> Delete cursor character: x Undo: u Replace: r<x>, where <x> is the new character. Search: /<sp>, where <sp> is what you are searching for. i.e. /potato would find the next occurrence of the text: potato <sp> is a regular expression.

Search and replace Suppose we have the file aside and we want to change the function to add two doubles and return a double. How could we efficiently change the code?

Method 1 Use search command / and search for int on current line: /int The cursor is brought to the first character of the matched text. Use 3x to delete 3 characters starting from the cursor position. Repeat until all instances of int are replaced. Drawbacks? Commands related to search. n – Next match forward starting from cursor position. N – Next match backward starting from cursor position. / - Just entering / is the same as n.

Method 2 Same process to find each instance of int we want to change. Use dw instead of 3x, as dw is more portable. Still just as slow and inefficient as Method 1. Any better ideas? Think about features you might have used in Microsoft Word or Visual Studio.

Substitute command Works similarly to Find and Replace in Microsoft products. Supports regular expressions. The command is :s/<old>/<new>[/<extra>] <old> - The expression to search for. <new> - The expression to replace <old> with.

Substitute command cont. Some more features you may find useful. :s/<old>/<new>/g Replace all instances on the current line. :%s/<old>/<new>/g Replace all instances in the entire file. :%s/<old>/<new>/gc Same as previous, but prompt user to change at each instance. Open ex.cpp in terminal and complete the problem.

Set command The set command turns options on or off. :set [no]<option> Put no before the option if you want to turn it off. More than just binary options.

Set command cont. Useful options to have enabled. number – Turn line numbering on (as seen in previous pictures) ruler – Shows cursor position in bottom right as well as % of file past. tabstop=<num> - Number of characters a tab should take up. backspace=indent,eol,start – Gets backspace to work in Insert mode.

Set command cont. These options only persist until you close the file. To make them persistent, put them in your ~/.vimrc file.

Saving :w [filename] Saves the currently open buffer to the file associated with it. If [filename] is supplied, saves a copy to [filename]. Think of Microsoft Save and Save As.

Quitting :q Close the current buffer. If multiple files are open, :qa closes them all. You can’t close a file if there are changes that have not been saved!

Saving and quitting :wq [filename] :x Save (As) and quit. :x Save and quit. Note: Append a to each command to apply it to all open buffers. :wa, :qa, :xa, etc.

Forcing a save or quit Append ! to each command to FORCE it to happen. :w! [filename] – write to [filename] now! :q! – Quit now, I don’t care about any unsaved changes!

Syntax coloring Turn on syntax coloring with :syntax on. Then choose a color scheme with :color <scheme>. You can cycle thru the default schemes with TAB.

Basic review Run vimtutor on a machine where vim is installed. Check out Lynda.com’s intro to vim. vim’s manpage. vim’s :help command.