Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linux Working with files Saleh Khazaei

Similar presentations


Presentation on theme: "Linux Working with files Saleh Khazaei"— Presentation transcript:

1 Linux Working with files Saleh Khazaei http://ceit.aut.ac.ir/~Khazaei/linux.pptx

2 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

3 VIM

4 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

5 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 email to editing configuration files.

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

7 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).

8 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).

9 Let’s Start!

10 Modes

11 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.

12 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

13 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

14 There are a lot of movement commands !

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

16 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…).

17 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.

18 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.

19 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

20 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

21 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.

22 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

23 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

24 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

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

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

27 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

28 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.*\)

29 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

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

31 If any problem …

32 First :help

33 Second man vim

34 Third Google is your best friend

35 References [1] A. Nateghi, M. Behbooei, “An Introduction to VIM”, 2014. [2] M. Jakl, “Vim Introduction and Tutorial”, 2007 [Online], Available HTTPS://blog.interlinked.org/tutorials/vim_tutor ial.html [Accessed: 3 Feb. 2015]Vim Introduction and Tutorial HTTPS://blog.interlinked.org/tutorials/vim_tutor ial.html [3] “Vim Regular Expression”, 2002 [Online], Available HTTP://vimregex.com/ [Accessed: 3 Feb. 2015]

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


Download ppt "Linux Working with files Saleh Khazaei"

Similar presentations


Ads by Google