SlideShare uma empresa Scribd logo
1 de 18
Using vi editor

                        Minsuk Lee
               Hansung University, Seoul, Korea
                   minsuk@hansung.ac.kr



NEAOSS MC2.0       CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Why vi ?
    • vi: Terminal based text editor
         – vi doesn’t need mouse, Function/Arrow keys
               • Just regular keyboards
               • High speed editing
         – vi works with other source code tools
               • ctag, …


    • The original code for vi was written by Bill Joy in
      1976, as the visual mode for a line editor called
      ex that Joy had written with Chuck Haley.
      [wikipedia ‘vi’].
NEAOSS MC2.0               CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Vi as a modal editor
    • Modes of vi
         – Command Mode
               • Cursor movement, delete, …
                    – For cursor movement, You can also use arrow, [HOME],[END],[PgUp],[PgDn] keys
         – Input Mode
               • Edit (typing the document)
         – Ex Mode
               • Line command (write, cancel, quit, help, and ‘ex’ command)


                                                         $ vi file

                              ‘i’, ‘a’                                  ‘:’
               Input                            Command                                ex
               Mode                               Mode                                Mode
                             [ESC]                                     [ESC]
                                                                     [ENTER]


NEAOSS MC2.0                 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
vi
                                                                    Menu for
                                                                 Gnome-Terminal
                                                                    not for vi




                                                                     vi screen




NEAOSS MC2.0   CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Survival guide of vi
    1. $ vi filename
    2. You are in [Command Mode]
    3. EDITTING YOUR TEXT
         –     Type ‘i’ to change into [Input Mode]
         –     EDIT [Type whatever you want]
         –     Type ESC to return [Command Mode]
         –     Move cursors using arrow keys or ‘h’, ‘k’, ‘k’, ‘l’, ‘w’, ‘b’
         –     Delete a character using ‘x’
    4. If done, ‘ZZ’ or ‘:wq’ to save and quit,
       or ‘:q!’ to just quit
    5. $ cat filename


NEAOSS MC2.0               CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
If you see this screen
    • It’s the result of unwanted stop. (e.g., killed)




NEAOSS MC2.0      CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Recover message
 Found a swap file by the name ".myfile.swp"
     owned by: myuser dated: Sun Aug 28 11:12:41 2011
     modified: no
 While opening file "myfile“ dated: Sun Aug 28 11:46:35 2011
      NEWER than swap file!
 (1) Another program may be editing the same file. …
    Quit, or continue with caution.
 (2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vi -r myfile“ to recover.
    If you did this already, delete the swap file ".myfile.swp"
    to avoid this message.
NEAOSS MC2.0        CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
vi commands (1)
    • Command mode to Input Mode
         –     ‘i’ : from the cursor position
         –     ‘a’ : after the current character
         –     ‘I’ : from the starting column
         –     ‘A’ : after the last character of the line
    • Cursor movement
         –     ‘gg’ : move to 1st line of the file
         –     ‘G’ : move to the last line of the file
         –     ‘H’ : move to top right corner of the screen
         –     ‘nnG’ or ‘:nn [ENTER]’ : move to nnth line
         –     ‘h’, ’j’, ’k’, ’l’ : move left, down, up, right by one character (nn)
         –     ‘w’, ‘b’ : move to next, previous word (nn)


NEAOSS MC2.0                CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
vi commands (2)
    • Delete, modify
         –     ‘x’, [DEL] : delete character under cursor (nn)
         –     ‘X’ [BS] : delete the previous character (nn)
         –     ‘dw’ : delete word (nn)
                                                                               UNDO ?
         –     ‘dd’ : delete a line (nn)                                       Try ‘u’
         –     ‘cw’ : modify to the end of current word (nn)
         –     ‘cc’ : modify whole line (nn)
         –     ‘C’ : modify to the end of current line
         –     ‘r’ : replace one character under cursor (nn)                   REPEAT ?
         –     ‘R’ : replace characters
    • Copy and paste
                                                                               Try ‘.’
         –     ‘yw’ : copy word (nn)
         –     ‘yy’ : copy current line (nn)
         –     ‘p’ : paste copied or deleted item, next (nn)
         –     ‘P’ : paste before (nn)
NEAOSS MC2.0                 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
vi commands (3)
    • Search
         –     ‘/word ’ : search ‘word ’ forward
         –     ‘n’ find next (nn)
         –     ‘?’ change search direction backword
         –     ‘/’ change search direction forward


    • Replace
         –     ‘:s/source/destination’ : replace source to destination
         –     ‘:%s/source/destination’ : replace the FIRST occurrence of all lines
         –     ‘:%s/source/destination/g’ : replace the ALL occurrence of all lines
         –     ‘:aa,bbs/source/destination/g’ : replace from line aa to bb




NEAOSS MC2.0               CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
vi commands (4)
    • File Commands
       – ‘:w’ : save
       – ‘:w filename’ : save as filename
       – ‘:wq’ or ‘ZZ’ : save and quit
       – ‘:q’ : quit without save, if modified, ‘:q!’
       – ‘:e filename’ : read and edit filename
       – ‘:r filename’ : read and insert filename
       – ‘:!<command> : run shell command
       – ‘:n’ : next file without save, ‘:n!’ if modified
       – ‘:wn’ : write and next




NEAOSS MC2.0         CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Configuration of vi
    • ‘:set <command>’ or in configuration file ~/.exrc
         –     set autoindent : auto indentation
         –     set cindent : auto indentation for C language
         –     set autowrite : automatic write when modify
         –     set smartindent : smarter indentation
         –     set textwidth=nn : wrap after nn th column
         –     set wrap : auto wrap
                                                                Unset ?
         –     set backup : do not make backup
                                                          :set no<command>
         –     set tabstop=nn : set tab with nn
         –     set shiftwidth=n : set indentation with n
         –     set ignorecase : ignore case when search
         –     set showmode : show current mode in bottom line
         –     set number : show line number
NEAOSS MC2.0             CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
And more
    • Vi has millions of functions
         – http://vimdoc.sourceforge.net/htmldoc/help.html#help.txt

         – http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.h
           tml
         – http://wiki.kldp.org/KoreanDoc/html/Vim_Guide-
           KLDP/Vim_Guide-KLDP.html (KOREAN)
         – http://weezzle.net/1575 (KOREAN)


    • Look for ‘vi cheat sheet’ !!!
         – Single page command lists



NEAOSS MC2.0           CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Vi cheat sheets




                                                                 <www.viemu.com>



                                       <IBM>


NEAOSS MC2.0   CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
gedit
    • Gnome editor




NEAOSS MC2.0   CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Small tips for source code editing
    •   Syntax Highlighting (use vim, rather than vi)
    •   Keeps Indentation ! (editor can help)
    •   Do not use tab, but use 4 Spaces (editor can do this)
    •   See man pages for ALL functions you use (some IDE can help)




NEAOSS MC2.0          CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Let’s Practice !
    • Write a C program vi, compile & run

         Open a terminal
         $ vi hello.c                            // show line #
         $ gcc –ohello hello.c                   // error ? Edit it !!
         $ ./hello
         $ ./hello Minsuk
         $ ./hello Minsuk Lee
         $ ./hello Minsuk Lee

NEAOSS MC2.0       CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
hello.c : Type as is !!!




NEAOSS MC2.0   CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA

Mais conteúdo relacionado

Destaque

岸角客家文化
岸角客家文化岸角客家文化
岸角客家文化Minghua Lin
 
2011 National Space Symposium
2011 National Space Symposium 2011 National Space Symposium
2011 National Space Symposium SpaceFoundation
 
05.linux basic-operations-1
05.linux basic-operations-105.linux basic-operations-1
05.linux basic-operations-1Minsuk Lee
 
Portfolio Presentation 2
Portfolio Presentation 2Portfolio Presentation 2
Portfolio Presentation 2rutheast
 
08.file system
08.file system08.file system
08.file systemMinsuk Lee
 
Future of sharing beyond
Future of sharing   beyondFuture of sharing   beyond
Future of sharing beyondNick Rappolt
 
PSPD Newletter Spring 2011
PSPD Newletter Spring 2011PSPD Newletter Spring 2011
PSPD Newletter Spring 2011Pratt CMFM
 
これからの司法書士に求められるIT力強化セミナー
これからの司法書士に求められるIT力強化セミナーこれからの司法書士に求められるIT力強化セミナー
これからの司法書士に求められるIT力強化セミナーYukidama
 
Portfolio Presentation 2
Portfolio Presentation 2Portfolio Presentation 2
Portfolio Presentation 2rutheast
 
IT企業専門パソコン肩こり出張マッサージ「ほぐ神」4月末までの渋谷キャンペーン
IT企業専門パソコン肩こり出張マッサージ「ほぐ神」4月末までの渋谷キャンペーンIT企業専門パソコン肩こり出張マッサージ「ほぐ神」4月末までの渋谷キャンペーン
IT企業専門パソコン肩こり出張マッサージ「ほぐ神」4月末までの渋谷キャンペーンYukidama
 
The Complete Roadmap Workbook Final Use
The Complete Roadmap Workbook Final UseThe Complete Roadmap Workbook Final Use
The Complete Roadmap Workbook Final Usepaulageorge
 
Small business and enterprenure
Small business and enterprenureSmall business and enterprenure
Small business and enterprenurerounaq
 
it's software!
it's software!it's software!
it's software!Minsuk Lee
 
Module 1 presentation
Module 1 presentationModule 1 presentation
Module 1 presentationsnorthrop
 
Intelligent System for Alzheimer's Disease
Intelligent System for Alzheimer's DiseaseIntelligent System for Alzheimer's Disease
Intelligent System for Alzheimer's DiseaseBrain Dynamics
 
Open Source Software Day Talk
Open Source Software Day TalkOpen Source Software Day Talk
Open Source Software Day TalkMinsuk Lee
 

Destaque (20)

岸角客家文化
岸角客家文化岸角客家文化
岸角客家文化
 
2011 National Space Symposium
2011 National Space Symposium 2011 National Space Symposium
2011 National Space Symposium
 
05.linux basic-operations-1
05.linux basic-operations-105.linux basic-operations-1
05.linux basic-operations-1
 
Portfolio Presentation 2
Portfolio Presentation 2Portfolio Presentation 2
Portfolio Presentation 2
 
08.file system
08.file system08.file system
08.file system
 
Future of sharing beyond
Future of sharing   beyondFuture of sharing   beyond
Future of sharing beyond
 
Pp R L S 2011
Pp  R L S  2011Pp  R L S  2011
Pp R L S 2011
 
Eshopping1
Eshopping1Eshopping1
Eshopping1
 
PSPD Newletter Spring 2011
PSPD Newletter Spring 2011PSPD Newletter Spring 2011
PSPD Newletter Spring 2011
 
これからの司法書士に求められるIT力強化セミナー
これからの司法書士に求められるIT力強化セミナーこれからの司法書士に求められるIT力強化セミナー
これからの司法書士に求められるIT力強化セミナー
 
Portfolio Presentation 2
Portfolio Presentation 2Portfolio Presentation 2
Portfolio Presentation 2
 
IT企業専門パソコン肩こり出張マッサージ「ほぐ神」4月末までの渋谷キャンペーン
IT企業専門パソコン肩こり出張マッサージ「ほぐ神」4月末までの渋谷キャンペーンIT企業専門パソコン肩こり出張マッサージ「ほぐ神」4月末までの渋谷キャンペーン
IT企業専門パソコン肩こり出張マッサージ「ほぐ神」4月末までの渋谷キャンペーン
 
The Complete Roadmap Workbook Final Use
The Complete Roadmap Workbook Final UseThe Complete Roadmap Workbook Final Use
The Complete Roadmap Workbook Final Use
 
Small business and enterprenure
Small business and enterprenureSmall business and enterprenure
Small business and enterprenure
 
A 12
A 12A 12
A 12
 
Binary search
Binary searchBinary search
Binary search
 
it's software!
it's software!it's software!
it's software!
 
Module 1 presentation
Module 1 presentationModule 1 presentation
Module 1 presentation
 
Intelligent System for Alzheimer's Disease
Intelligent System for Alzheimer's DiseaseIntelligent System for Alzheimer's Disease
Intelligent System for Alzheimer's Disease
 
Open Source Software Day Talk
Open Source Software Day TalkOpen Source Software Day Talk
Open Source Software Day Talk
 

Semelhante a 07.using vi

Coding with Vim
Coding with VimCoding with Vim
Coding with VimEnzo Wang
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billynimbleltd
 
Vim Hacks (OSSF)
Vim Hacks (OSSF)Vim Hacks (OSSF)
Vim Hacks (OSSF)Lin Yo-An
 
07 vi text_editor
07 vi text_editor07 vi text_editor
07 vi text_editorShay Cohen
 
Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to VimBrandon Liu
 
Евгений Обрезков "Behind the terminal"
Евгений Обрезков "Behind the terminal"Евгений Обрезков "Behind the terminal"
Евгений Обрезков "Behind the terminal"Fwdays
 
Augusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim IntroductionAugusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim IntroductionKeith Pickett
 
Vim - How to Develop Like a Ninja
Vim - How to Develop Like a NinjaVim - How to Develop Like a Ninja
Vim - How to Develop Like a NinjaAlexLewin7
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2dVinsol
 
Subversion: A Getting Started Presentation
Subversion: A Getting Started PresentationSubversion: A Getting Started Presentation
Subversion: A Getting Started PresentationNap Ramirez
 
Intro_OpenCV.ppt
Intro_OpenCV.pptIntro_OpenCV.ppt
Intro_OpenCV.pptRithikRaj25
 
Puppet at DemonWare - Ruaidhri Power - Puppetcamp Dublin '12
Puppet at DemonWare - Ruaidhri Power - Puppetcamp Dublin '12Puppet at DemonWare - Ruaidhri Power - Puppetcamp Dublin '12
Puppet at DemonWare - Ruaidhri Power - Puppetcamp Dublin '12Puppet
 
Project ACRN Yocto Project meta-acrn layer introduction
Project ACRN Yocto Project meta-acrn layer introductionProject ACRN Yocto Project meta-acrn layer introduction
Project ACRN Yocto Project meta-acrn layer introductionProject ACRN
 
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architectureOpenStack Korea Community
 

Semelhante a 07.using vi (20)

Coding with Vim
Coding with VimCoding with Vim
Coding with Vim
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billy
 
Vi Editor
Vi EditorVi Editor
Vi Editor
 
swl--3 (1).docx
swl--3 (1).docxswl--3 (1).docx
swl--3 (1).docx
 
Vim Hacks (OSSF)
Vim Hacks (OSSF)Vim Hacks (OSSF)
Vim Hacks (OSSF)
 
07 vi text_editor
07 vi text_editor07 vi text_editor
07 vi text_editor
 
Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to Vim
 
Евгений Обрезков "Behind the terminal"
Евгений Обрезков "Behind the terminal"Евгений Обрезков "Behind the terminal"
Евгений Обрезков "Behind the terminal"
 
Augusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim IntroductionAugusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim Introduction
 
Vim - How to Develop Like a Ninja
Vim - How to Develop Like a NinjaVim - How to Develop Like a Ninja
Vim - How to Develop Like a Ninja
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2d
 
Subversion: A Getting Started Presentation
Subversion: A Getting Started PresentationSubversion: A Getting Started Presentation
Subversion: A Getting Started Presentation
 
Intro_OpenCV.ppt
Intro_OpenCV.pptIntro_OpenCV.ppt
Intro_OpenCV.ppt
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
 
Xen Debugging
Xen DebuggingXen Debugging
Xen Debugging
 
Puppet at DemonWare - Ruaidhri Power - Puppetcamp Dublin '12
Puppet at DemonWare - Ruaidhri Power - Puppetcamp Dublin '12Puppet at DemonWare - Ruaidhri Power - Puppetcamp Dublin '12
Puppet at DemonWare - Ruaidhri Power - Puppetcamp Dublin '12
 
Vi editor
Vi editorVi editor
Vi editor
 
Project ACRN Yocto Project meta-acrn layer introduction
Project ACRN Yocto Project meta-acrn layer introductionProject ACRN Yocto Project meta-acrn layer introduction
Project ACRN Yocto Project meta-acrn layer introduction
 
Linex
LinexLinex
Linex
 
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
[OpenInfra Days Korea 2018] Day 2 - E4 - 딥다이브: immutable Kubernetes architecture
 

Mais de Minsuk Lee

CES 처음 가는 분을 위한 가이드
CES 처음 가는 분을 위한 가이드CES 처음 가는 분을 위한 가이드
CES 처음 가는 분을 위한 가이드Minsuk Lee
 
NIA-PaaS-TA Pub 키노트
NIA-PaaS-TA Pub 키노트NIA-PaaS-TA Pub 키노트
NIA-PaaS-TA Pub 키노트Minsuk Lee
 
모두콘, 어떻게 배울 것인가 발제.
모두콘,  어떻게 배울 것인가 발제.모두콘,  어떻게 배울 것인가 발제.
모두콘, 어떻게 배울 것인가 발제.Minsuk Lee
 
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자Minsuk Lee
 
개발자, 회사.. 왜 오픈소스를 해야할까?
개발자, 회사.. 왜 오픈소스를 해야할까?개발자, 회사.. 왜 오픈소스를 해야할까?
개발자, 회사.. 왜 오픈소스를 해야할까?Minsuk Lee
 
진정한 소프트웨어 융합교육에 대하여
진정한 소프트웨어 융합교육에 대하여 진정한 소프트웨어 융합교육에 대하여
진정한 소프트웨어 융합교육에 대하여 Minsuk Lee
 
FOSS CON Korea 2018
FOSS CON Korea 2018FOSS CON Korea 2018
FOSS CON Korea 2018Minsuk Lee
 
소프트웨어 공부하는법
소프트웨어 공부하는법소프트웨어 공부하는법
소프트웨어 공부하는법Minsuk Lee
 
자기소개서, 이력서 쓰는 법
자기소개서, 이력서 쓰는 법자기소개서, 이력서 쓰는 법
자기소개서, 이력서 쓰는 법Minsuk Lee
 
왜 우리는 개발자에 집중하지 않는가?
왜 우리는 개발자에 집중하지 않는가?왜 우리는 개발자에 집중하지 않는가?
왜 우리는 개발자에 집중하지 않는가?Minsuk Lee
 
Somul 2017-이민석
Somul 2017-이민석Somul 2017-이민석
Somul 2017-이민석Minsuk Lee
 
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌Minsuk Lee
 
왜 소프트웨어를 배워야할까?
왜 소프트웨어를 배워야할까?왜 소프트웨어를 배워야할까?
왜 소프트웨어를 배워야할까?Minsuk Lee
 
소프트웨어, 정말 되는 건가?
소프트웨어, 정말 되는 건가?소프트웨어, 정말 되는 건가?
소프트웨어, 정말 되는 건가?Minsuk Lee
 
소프트웨어, 소프트웨어 개발자
소프트웨어, 소프트웨어 개발자소프트웨어, 소프트웨어 개발자
소프트웨어, 소프트웨어 개발자Minsuk Lee
 
프로그램 기초
프로그램 기초프로그램 기초
프로그램 기초Minsuk Lee
 
Software Company, Open Soure Software Company
Software Company, Open Soure Software CompanySoftware Company, Open Soure Software Company
Software Company, Open Soure Software CompanyMinsuk Lee
 
Open Source 그리고 git과 github, code review
Open Source 그리고 git과 github, code reviewOpen Source 그리고 git과 github, code review
Open Source 그리고 git과 github, code reviewMinsuk Lee
 
Data and Sorting Algoritm
Data and Sorting AlgoritmData and Sorting Algoritm
Data and Sorting AlgoritmMinsuk Lee
 
국민대학교 컴퓨터프로그래밍
국민대학교 컴퓨터프로그래밍국민대학교 컴퓨터프로그래밍
국민대학교 컴퓨터프로그래밍Minsuk Lee
 

Mais de Minsuk Lee (20)

CES 처음 가는 분을 위한 가이드
CES 처음 가는 분을 위한 가이드CES 처음 가는 분을 위한 가이드
CES 처음 가는 분을 위한 가이드
 
NIA-PaaS-TA Pub 키노트
NIA-PaaS-TA Pub 키노트NIA-PaaS-TA Pub 키노트
NIA-PaaS-TA Pub 키노트
 
모두콘, 어떻게 배울 것인가 발제.
모두콘,  어떻게 배울 것인가 발제.모두콘,  어떻게 배울 것인가 발제.
모두콘, 어떻게 배울 것인가 발제.
 
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
 
개발자, 회사.. 왜 오픈소스를 해야할까?
개발자, 회사.. 왜 오픈소스를 해야할까?개발자, 회사.. 왜 오픈소스를 해야할까?
개발자, 회사.. 왜 오픈소스를 해야할까?
 
진정한 소프트웨어 융합교육에 대하여
진정한 소프트웨어 융합교육에 대하여 진정한 소프트웨어 융합교육에 대하여
진정한 소프트웨어 융합교육에 대하여
 
FOSS CON Korea 2018
FOSS CON Korea 2018FOSS CON Korea 2018
FOSS CON Korea 2018
 
소프트웨어 공부하는법
소프트웨어 공부하는법소프트웨어 공부하는법
소프트웨어 공부하는법
 
자기소개서, 이력서 쓰는 법
자기소개서, 이력서 쓰는 법자기소개서, 이력서 쓰는 법
자기소개서, 이력서 쓰는 법
 
왜 우리는 개발자에 집중하지 않는가?
왜 우리는 개발자에 집중하지 않는가?왜 우리는 개발자에 집중하지 않는가?
왜 우리는 개발자에 집중하지 않는가?
 
Somul 2017-이민석
Somul 2017-이민석Somul 2017-이민석
Somul 2017-이민석
 
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
 
왜 소프트웨어를 배워야할까?
왜 소프트웨어를 배워야할까?왜 소프트웨어를 배워야할까?
왜 소프트웨어를 배워야할까?
 
소프트웨어, 정말 되는 건가?
소프트웨어, 정말 되는 건가?소프트웨어, 정말 되는 건가?
소프트웨어, 정말 되는 건가?
 
소프트웨어, 소프트웨어 개발자
소프트웨어, 소프트웨어 개발자소프트웨어, 소프트웨어 개발자
소프트웨어, 소프트웨어 개발자
 
프로그램 기초
프로그램 기초프로그램 기초
프로그램 기초
 
Software Company, Open Soure Software Company
Software Company, Open Soure Software CompanySoftware Company, Open Soure Software Company
Software Company, Open Soure Software Company
 
Open Source 그리고 git과 github, code review
Open Source 그리고 git과 github, code reviewOpen Source 그리고 git과 github, code review
Open Source 그리고 git과 github, code review
 
Data and Sorting Algoritm
Data and Sorting AlgoritmData and Sorting Algoritm
Data and Sorting Algoritm
 
국민대학교 컴퓨터프로그래밍
국민대학교 컴퓨터프로그래밍국민대학교 컴퓨터프로그래밍
국민대학교 컴퓨터프로그래밍
 

07.using vi

  • 1. Using vi editor Minsuk Lee Hansung University, Seoul, Korea minsuk@hansung.ac.kr NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 2. Why vi ? • vi: Terminal based text editor – vi doesn’t need mouse, Function/Arrow keys • Just regular keyboards • High speed editing – vi works with other source code tools • ctag, … • The original code for vi was written by Bill Joy in 1976, as the visual mode for a line editor called ex that Joy had written with Chuck Haley. [wikipedia ‘vi’]. NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 3. Vi as a modal editor • Modes of vi – Command Mode • Cursor movement, delete, … – For cursor movement, You can also use arrow, [HOME],[END],[PgUp],[PgDn] keys – Input Mode • Edit (typing the document) – Ex Mode • Line command (write, cancel, quit, help, and ‘ex’ command) $ vi file ‘i’, ‘a’ ‘:’ Input Command ex Mode Mode Mode [ESC] [ESC] [ENTER] NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 4. vi Menu for Gnome-Terminal not for vi vi screen NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 5. Survival guide of vi 1. $ vi filename 2. You are in [Command Mode] 3. EDITTING YOUR TEXT – Type ‘i’ to change into [Input Mode] – EDIT [Type whatever you want] – Type ESC to return [Command Mode] – Move cursors using arrow keys or ‘h’, ‘k’, ‘k’, ‘l’, ‘w’, ‘b’ – Delete a character using ‘x’ 4. If done, ‘ZZ’ or ‘:wq’ to save and quit, or ‘:q!’ to just quit 5. $ cat filename NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 6. If you see this screen • It’s the result of unwanted stop. (e.g., killed) NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 7. Recover message Found a swap file by the name ".myfile.swp" owned by: myuser dated: Sun Aug 28 11:12:41 2011 modified: no While opening file "myfile“ dated: Sun Aug 28 11:46:35 2011 NEWER than swap file! (1) Another program may be editing the same file. … Quit, or continue with caution. (2) An edit session for this file crashed. If this is the case, use ":recover" or "vi -r myfile“ to recover. If you did this already, delete the swap file ".myfile.swp" to avoid this message. NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 8. vi commands (1) • Command mode to Input Mode – ‘i’ : from the cursor position – ‘a’ : after the current character – ‘I’ : from the starting column – ‘A’ : after the last character of the line • Cursor movement – ‘gg’ : move to 1st line of the file – ‘G’ : move to the last line of the file – ‘H’ : move to top right corner of the screen – ‘nnG’ or ‘:nn [ENTER]’ : move to nnth line – ‘h’, ’j’, ’k’, ’l’ : move left, down, up, right by one character (nn) – ‘w’, ‘b’ : move to next, previous word (nn) NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 9. vi commands (2) • Delete, modify – ‘x’, [DEL] : delete character under cursor (nn) – ‘X’ [BS] : delete the previous character (nn) – ‘dw’ : delete word (nn) UNDO ? – ‘dd’ : delete a line (nn) Try ‘u’ – ‘cw’ : modify to the end of current word (nn) – ‘cc’ : modify whole line (nn) – ‘C’ : modify to the end of current line – ‘r’ : replace one character under cursor (nn) REPEAT ? – ‘R’ : replace characters • Copy and paste Try ‘.’ – ‘yw’ : copy word (nn) – ‘yy’ : copy current line (nn) – ‘p’ : paste copied or deleted item, next (nn) – ‘P’ : paste before (nn) NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 10. vi commands (3) • Search – ‘/word ’ : search ‘word ’ forward – ‘n’ find next (nn) – ‘?’ change search direction backword – ‘/’ change search direction forward • Replace – ‘:s/source/destination’ : replace source to destination – ‘:%s/source/destination’ : replace the FIRST occurrence of all lines – ‘:%s/source/destination/g’ : replace the ALL occurrence of all lines – ‘:aa,bbs/source/destination/g’ : replace from line aa to bb NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 11. vi commands (4) • File Commands – ‘:w’ : save – ‘:w filename’ : save as filename – ‘:wq’ or ‘ZZ’ : save and quit – ‘:q’ : quit without save, if modified, ‘:q!’ – ‘:e filename’ : read and edit filename – ‘:r filename’ : read and insert filename – ‘:!<command> : run shell command – ‘:n’ : next file without save, ‘:n!’ if modified – ‘:wn’ : write and next NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 12. Configuration of vi • ‘:set <command>’ or in configuration file ~/.exrc – set autoindent : auto indentation – set cindent : auto indentation for C language – set autowrite : automatic write when modify – set smartindent : smarter indentation – set textwidth=nn : wrap after nn th column – set wrap : auto wrap Unset ? – set backup : do not make backup :set no<command> – set tabstop=nn : set tab with nn – set shiftwidth=n : set indentation with n – set ignorecase : ignore case when search – set showmode : show current mode in bottom line – set number : show line number NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 13. And more • Vi has millions of functions – http://vimdoc.sourceforge.net/htmldoc/help.html#help.txt – http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.h tml – http://wiki.kldp.org/KoreanDoc/html/Vim_Guide- KLDP/Vim_Guide-KLDP.html (KOREAN) – http://weezzle.net/1575 (KOREAN) • Look for ‘vi cheat sheet’ !!! – Single page command lists NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 14. Vi cheat sheets <www.viemu.com> <IBM> NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 15. gedit • Gnome editor NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 16. Small tips for source code editing • Syntax Highlighting (use vim, rather than vi) • Keeps Indentation ! (editor can help) • Do not use tab, but use 4 Spaces (editor can do this) • See man pages for ALL functions you use (some IDE can help) NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 17. Let’s Practice ! • Write a C program vi, compile & run Open a terminal $ vi hello.c // show line # $ gcc –ohello hello.c // error ? Edit it !! $ ./hello $ ./hello Minsuk $ ./hello Minsuk Lee $ ./hello Minsuk Lee NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 18. hello.c : Type as is !!! NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA