Linux Working with files Saleh Khazaei

Slides:



Advertisements
Similar presentations
CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
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.
A Practical Guide to Fedora and Red Hat Enterprise Linux Chapter 5: The vim Editor By Fred R. McClurg Linux Operating System © Copyright 2014, All Rights.
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.
Vi Editor TA for ITIS3100: Xu Fei
Linux+ Guide to Linux Certification, Second Edition
Chapter 5 Editing Text Files
CS 497C – Introduction to UNIX Lecture 10: The vi/vim Editor Chin-Chih Chang
Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl Linux editors and commands (e.g.
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
UNIX Filters.
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:
1 Unix Text Editors Creating files on the Unix system.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
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.
Linux+ Guide to Linux Certification, Third Edition
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:
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 7 Editing.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
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.
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.
Introduction to Unix – CS 21 Lecture 7. Lecture Overview Regular expressions revisited emacs versus vi Basic emacs and vi usage.
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.
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.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
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
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
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
Program Development with Vim
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
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:

Linux Working with files Saleh Khazaei

Commands Cat – prints context of a file more / less head / tail ( e.g. -n10 ) file grep ( -i, -n, -c ) wc ( -c, -m, -l, -w ) nano gedit geany Qt

VIM

What is VIM Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems

The Programmers’ Editor ! Vim is often called a "programmer's editor," and so useful for programming that many consider it an entire IDE. It's not just for programmers, though. Vim is perfect for all kinds of text editing, from composing to editing configuration files.

It could be distributed freely! Vim is under the license of GPL which means it could be distributed freely.

Vim & Vi The Differences -Vim has been ported to a much wider range of OS's than vi. -Vim includes support (syntax highlighting, code folding, etc) for several popular programming languages (C/C++, Python, Perl, shell, etc). -Vim integrates with cscope. -Vim can be used to edit files using network protocols like SSH and HTTP. -Vim includes multilevel undo/redo. -Vim allows the screen to be split for editing multiple files. -Vim can edit files inside a compressed archive (gzip, zip, tar, etc).

Vim & Vi The Differences -Vim includes a built in diff for comparing files (vimdiff). -Vim includes support for plugins, and finer control over config and startup files. -Vim can be scripted with vimscript, or with an external scripting language (e.g. python, perl, shell).

Let’s Start!

Modes

Movement ( Only Command Mode ) h – move left l – move right k – move up j – move down Or you can also use the cursor keys in all three modes.

Movement ( Only Command Mode ) w – start of the next word. e – end of the word. b – beginning of the word. H – moves to the top of the page. M – moves to the middle of the page. L – moves to the end of the page. Ctrl-f – scroll forward one screen, Ctrl-b – scroll backward one screen

Important Commands ! 0first column of the line ^ first non-blank character of the line w jump to next word W jump to next word, ignore punctuation e jump to word-end E jump to word-end, ignore punctuation b jump to word-beginning B jump to word-beginning, ignore punctuation ge jump to previous word-ending gE jump to previous word-ending, ignore punctuation g_ jump to last non-blank character of the line $ jump to the last character of the line

There are a lot of movement commands !

Text inserting is pretty simple ! Just type “i” and start typing !

Vim offers these commands ! d delete the characters from the cursor position up the position given by the next command (for example d$ deletes all character from the current cursor position up to the last column of the line). c change the character from the cursor position up to the position indicated by the next command. x delete the character under the cursor. X delete the character before the cursor (Backspace). y copy the characters from the current cursor position up to the position indicated by the next command. p paste previous deleted or yanked (copied) text after the current cursor position. P paste previous deleted or yanked (copied) text before the current cursor position. r replace the current character with the newly typed one. s substitute the text from the current cursor position up to the position given by the next command with the newly typed one.. repeat the last insertion or editing command (x,d,p…).

Copy … Paste “ayy” copies the current line into register “a”. Pasting the contents of register “a” is done by “ap”. “:registers” shows contents of the registers.

Visual Block ! 1- Select a rectangle using Ctrl-V 2- Insert text by I or A 3- Type! It’s pretty cool, isn’t it?! To substitute the whole block with a new text select a block and type s ! To append some text at the end of some lines, use Ctrl-v$ and select the lines.

MOST IMPORTANT COMMAND S Don’t be afraid to try the various commands, you can undo almost anything using “u” in the command mode Even undo is undoable !!! :D Using Ctrl-r UNDO AND REDO

Search? / - Search in forward direction ? – Search in backward direction n – repeat search in forward direction N – repeat search in backward direction f – next occurrence of a character F – previous occurrence of a character ( e.g. fo finds next o ) * - next occurrence of the word under cursor # - previous occurrence of the word under cursor

Replace :range s[ubstitute]/pattern/string/cgiI cConfirm each substitution g Replace all occurrences in the line (without g - only first). iIgnore case for the pattern. IDon't ignore case for the pattern.

Replace :range s[ubstitute]/pattern/string/cgiI Specifiers SpecifierDescription numberan absolute line number.the current line $the last line in the file % the whole file. The same as 1,$ 't'tposition of mark "t" /pattern[/] the next line where text "pattern" matches. ?pattern[?] the previous line where text "pattern" matches \/ the next line where the previously used search pattern matches \? the previous line where the previously used search pattern matches \& the next line where the previously used substitute pattern matches

Regular Exp. ^ - beginning of the line $ - end of the line \ […] – class of characters Anchors "Escaped" characters or Metacharacters #Matching#. any character except new line \swhitespace character\S non-whitespace character \ddigit\Dnon-digit \xhex digit\Xnon-hex digit \ooctal digit\Onon-octal digit \h head of word character (a,b,c...z,A,B,C...Z and _) \H non-head of word character \pprintable character\P like \p, but excluding digits \wword character\Wnon-word character \aalphabetic character\A non-alphabetic character \llowercase character\L non-lowercase character \uuppercase character\U non-uppercase character

Regular Exp. QuantifierDescription * matches 0 or more of the preceding characters, ranges or metacharacters.* matches everything including empty line \+ matches 1 or more of the preceding characters... \= matches 0 or 1 more of the preceding characters... \{n,m} matches from n to m of the preceding characters... \{n} matches exactly n times of the preceding characters... \{,m} matches at most m (from 0 to m) of the preceding characters... \{n,} matches at least n of of the preceding characters... where n and m are positive integers (>0) Quantifiers, Greedy and Non-Greedy

Regular Exp. Character ranges [a-zA-z] [^A-Z] [ ] [-0-9] ^ have it’s special meaning only if it’s the first character in the range

Regular Exp. Grouping and Backreferences \( … \) e.g. : :s/\(\w\+\)\(\s\+\)\(\w\+\)/hello :s/(w+)(s+)(w+)/hello

Regular Exp. Replacement Part of :substitute #Meaning# &the whole matched pattern\L the following characters are made lowercase \0the whole matched pattern\U the following characters are made uppercase \1 the matched pattern in the first pair of \(\) \Eend of \U and \L \2 the matched pattern in the second pair of \(\) \eend of \U and \L... \rsplit line in two at this point \9 the matched pattern in the ninth pair of \(\) \lnext character made lowercase ~the previous substitute string\unext character made uppercase

Regular Exp. Alternations Using "\|" you can combine several expressions into one which matches any of its components. The first one matched will be used. \(Date:\|Subject:\|From:\)\(\s.*\)

A Lovely Feature Using Ctrl-p Vim searches the currently typed text backwards for a word starting with the same characters as already typed. Ctrl-x Ctrl-l completes the whole line. Completion

Commands you shouldn’t forget! :w ( save ) :q ( quit ) :q! ( quit without saving ) ZZ – exiting VIM immediately ! u – Undo Ctrl-r – Redo

If any problem …

First :help

Second man vim

Third Google is your best friend

References [1] A. Nateghi, M. Behbooei, “An Introduction to VIM”, [2] M. Jakl, “Vim Introduction and Tutorial”, 2007 [Online], Available ial.html [Accessed: 3 Feb. 2015]Vim Introduction and Tutorial ial.html [3] “Vim Regular Expression”, 2002 [Online], Available [Accessed: 3 Feb. 2015]

Thanks for your attention! If you have any questions, you could ask now