SlideShare ist ein Scribd-Unternehmen logo
1 von 40
The “ vi “ Text Editor




Alessandro Manfredi                     Lug Roma 3 - http://www.lugroma3.org
?




Alessandro Manfredi   The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Roadmap
              • Yes, I’m going to convince you to use this tool
              • Who, What, When, Where, Why
              • How to
              • Examples & Training


Alessandro Manfredi                 The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Once Upon a Time ...

                           The 5 ‘w’



Alessandro Manfredi          The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
The editor war
                          •   Modal Editor

                          •   Small and Fast

                          •   Textual env

                          •   Extensive use of chords

                          •   Bells & Whistles

                          •   GUI

                      Both have a difcult learning curve
Alessandro Manfredi                    The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
And the winner is ...


       POSIX ( IEEE 1003 – ISO/IEC 9945 )
                      SUS ( IEEE & The Open Group )
    ( that means there is no actual winner, you can use whatever you want
   but since vi is part of the standard you should really know how to use it )




Alessandro Manfredi                The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Wait, I never missed anyth using ...
                                                • gedit
                                                • kate / kwrite
                                                • nano
                                                • joe
                                                • oowriter
                                                • notepad
                                                • ... whatever
Alessandro Manfredi    The “ vi “ Text Editor          Lug Roma 3 - http://www.lugroma3.org
So why ? ( running into where )


                 • Again, IT IS PART OF THE STANDARD
                 • That means you find it everywhere
                      including BSD*, Mac Os X, Solaris, HP-UX,
                      AIX, Windows with SFU, your microwave
                      oven (if it’s posix-compliant), etc.



Alessandro Manfredi                  The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Other strong reasons
                        (that you will probably ignore)

       • Really powerful editor
          • Complex tasks with few keystrokes
          • Effective regex support
       • Makes you damned fast
                                              (especially with touchtyping)

       • You can never raise hands from keyboard
       • Someone says modal editing increase productivity
Alessandro Manfredi               The “ vi “ Text Editor      Lug Roma 3 - http://www.lugroma3.org
What (the jargon le says..)

              vi: /V-I/, not, /vi:/, never, /siks/, n. [from ‘Visual
              Interface’] A screen editor crufted together by Bill Joy for
              an early BSD release. Became the de facto standard Unix
              editor and a nearly undisputed hacker favorite outside of
              MIT until the rise of EMACS after about 1984.

              Tends to frustrate new users no end, as it will neither take
              commands while expecting input text nor vice versa [... ]


Alessandro Manfredi                   The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
How the ADM3A Keyboard
                              looks like




                 • Esc was where now TAB is
                 • No arrows, just H , J , K , L
Alessandro Manfredi                 The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Clones
           • Vim           Any clone extends the basic ‘vi’
           • Elvis         program with addictional functions
                           but all of them share the common
           • nvi           mode and subset of commands you
           • gvim          are (hopefully) going to learn
           • bvi           hint: try $which vi
           • calvin
           • lemmy, elwin, winvi, ...
Alessandro Manfredi           The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
How to ...




Alessandro Manfredi     The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Modal Editing
    • Command Mode
        • Cursor is on the text
        • Can’t see what you’re typing, just its effects
    • Input Mode
        • Text typing and ONLY text typing
    • Directive Mode
        • Entered with <:>
        • You can see what you type this time =)
Alessandro Manfredi         The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Switching Modes (1)


                                   Command Mode




                      Input Mode                              : Directive Mode




Alessandro Manfredi                  The “ vi “ Text Editor            Lug Roma 3 - http://www.lugroma3.org
Enter the editor
                 •    vi


                 • vi filename
                 •    vi filename1 filename2 filename3

                 •    vi -r filename

                 •    vi +cmd filename

                 •    vi +lnum filename

                 •    vi @rcfile

                 •    ...



Alessandro Manfredi                            The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Very Basic usage example

                      <a> Hello folks! <Esc> <:><w><q> <Enter>
                         ( btw, ‘<x>’ means ‘ press the ‘x’ key )

                                    $ cat lename




Alessandro Manfredi                    The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Switching Modes (2)
    • Command Mode > Input Mode
        • <a>, <A>,<i>,<I>, <o>,<O>, ...
    • Input Mode > Command Mode
        • <Esc>
    • Command Mode > Directive Mode
        • <:>
    • Directive Mode > Command Mode
        • clean the directive line ‘:’ included
Alessandro Manfredi          The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Some Directive Line Commands
  :w                                                          ‘write’ (save)
  :w lename                                               save as lename
  :q                                                                    quit’
  :q!                                        quit’ forced (forget changes)
  :wq ( :x )                                   Combination of ‘w’ and ‘q’
  :e filename                                                 ‘edit’ filename
  :r filename                                   read’ filename (copy next)
  :n                                                    open the ‘next’ file
  :rew                                                     ‘rewind’ file list
  :ab token expression                     create a ‘token’ macro for exp
  :unab token                                     delete the ‘token’ macro
  :n                                                            go to line n
Alessandro Manfredi      The “ vi “ Text Editor            Lug Roma 3 - http://www.lugroma3.org
Alessandro Manfredi   The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Moving Cursor
  h, j, k,l                                           left, down, up, right
  G                                         to the end of the document
  {}                                   beginning / end of the paragraph
  ()                                    beginning / end of the sentence
  $                                                to the end of the line
  ^                                          to the beginning of the line
  n|                                                  to the n-th column
  w                                          beginning of the next word
  e                                               end of the next word
  +                                          rst non-blank of next line
  -                                      rst non-blank of previous line
  fx                                       first occurence of the ‘x’ char
  n cmd                                             repeat ‘n’ times ‘cmd’
Alessandro Manfredi       The “ vi “ Text Editor         Lug Roma 3 - http://www.lugroma3.org
Editing Commands
  i,a,I,A,o,O                                             input mode editing
  u                                                     undo the last change
  U                                          undo all the changes on the line
  J                                            join current line and the next
  << , >>                                          move the line left or right
  <L , >L                                    move the following lineset l or r
  y#                                                         yank the # range
  p#                                                        paste the # range
  d#                                                       delete the # range
  yy, pp, dd                                      yank, paste, delete one line
  Commands can be combined, e.g. 6yy yanks 6 lines
  Possible ranges # are w, ), }, fx, nj, $ as word, paragraph, sentence,
  rst x occurrence, till the n-th line and till the end of the line.
Alessandro Manfredi             The “ vi “ Text Editor       Lug Roma 3 - http://www.lugroma3.org
Examples
                      ( and Training )



Alessandro Manfredi        The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
The % and the ‘ . ‘ commands


      •%              , in command mode is the block range
                 •     match things like vdDASFgvfd(sdf,rgae,##,adSDf)



      • ‘ . ‘ , just repeat the last command
                 •     consider that ‘ <i> [type text] <Esc> ‘ is still a command



Alessandro Manfredi                       The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
‘ . ‘ and the programmer day ...
 • ... that often starts with the need to implement some
        functions from signature already in the headers
 • ‘3yy’ and ‘p’ to copy something like
                         bool check(int a, char c);
                         int value(int strange);
                         int failure(int my_process);
 •      The first task is replace semicolon with the blocks
                  <A><backspace> { <Enter> } <Esc> <j.j.>
Alessandro Manfredi                 The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Good way to modal editing
    • One mode for each task support tasks separation
    • Command mode should be the most used
    • Insert text in input mode is a command too
        • and should be used “transactionally”
        • e.g. reading should be achieved in command mode
        • words replacement too! e.g. <cw>newword<Esc>
Alessandro Manfredi             The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
‘ % ‘ and the programmer day ...
    • ... that goes on extracting function calls from
           complex expressions and assigning ‘em to a variable
    • something like
           if (!my_st.enf && do_smtg( s.isopn(), s.isdmz) && ( a & b.c )){ ... }

    •      <fdc%> var <Esc><O> var = <Ctrl+R> ; <Esc>

    • turns that into
           var = do_smtg( s.isopn(), s.isdmz) ;
           if (!my_st.enf && var && ( a & b.c )){ ... }
Alessandro Manfredi                    The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Keep the audience awake
                             or pull them to leave the room



• What do these commands do ?
      3J , 3dl , 3iHi<Esc>u , yf6 , dfyp , cfyp , llcfxy<Esc>hp

• What is the difference between these commands?
      ‘ 4c( ‘ and ‘ 2c2( ‘

• How to find the next 3 ‘ x ‘ char ?
• How to replace the next 3 sentences with ‘-censored-’
Alessandro Manfredi                   The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Search
  fx                                      nd the next occurrence of x
  tx                                                scroll to the next x
  Fx                                                 nd the previous x
  Tx                                    scroll backwards to the prev x
  /exp                                           search forward for exp
  ?exp                                         search backwards for exp
  ;                                                   repeat last search
  ,                                        reverse the last search order
  / ,?                                            repeat the last search

Alessandro Manfredi   The “ vi “ Text Editor            Lug Roma 3 - http://www.lugroma3.org
Regexp

    • “A regular expression (regex or regexp for short) is
           a special text string for describing a search pattern”
    • Very common in programming languages
    • Different syntaxes
    • Match regular languages
    • In short is a string made of chars, wildcards,
           multipliers and escape sequences, that can match an
           entire class of other strings.

Alessandro Manfredi              The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Some regexp elements (in vi)
  ^                                                           beginning of the line
  $                                                                  end of the line
  w                                                            alphanumeric chars
  W                                                      non-alphanumeric chars
  exp?                                                    exp, 0 or 1 occurrences
  exp+                                               exp, 1 or more occurrences
  exp*                                               exp, 0 or more occurrences
  exp|pxe                                                               exp or pxe
  .                                                                      ANY char
  <                                                           beginning of a word
  >                                                                 end of a word

Alessandro Manfredi          The “ vi “ Text Editor                Lug Roma 3 - http://www.lugroma3.org
Search and replace
                             ...with regexp from directive line


   • : <range> s / <exp> / <replace> / <mod>
   • Ranges: n, . , $, %, n,m
          ( for ‘n lines’, ‘single line’, ‘till the end’, ‘whole file’,’from n to m’ )

   • Mods: c, g, n
          ( for ‘ask confirm’, global and ‘first n matches’ )

   • Search and execute command
   • : <range> g / <exp> / <command>
Alessandro Manfredi                      The “ vi “ Text Editor    Lug Roma 3 - http://www.lugroma3.org
Search Options


                 • :set (no)ic
                 • :set (no)hlsearch
                 • :set (no)incsearch
                 • :set (no)...


Alessandro Manfredi                The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
More Directive Line Commands

                 • :map key cmd
                 • :unmap key
                 • :[n,m]w filename
                 • :!shcmd
                 • :r shcmd
                 • :sh
Alessandro Manfredi                  The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Clones Conguration (vim)
     • VIM (:r $VIMRUNTIME/vimrc_example.vim)
        • :e ~/.vimrc               ( linux & some unix )
        • :e $VIM/_vimrc            ( windows )
        • :e /usr/share/vim/vimrc ( Mac OS X )
     • set ai                      (set AutoIndex)
     • set ruler                   (show cursor position)
     • syntax on                   (enable syntax hl)
     • set nohlsearch             (disable hlsearch)
Alessandro Manfredi             The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Keep in mind that ...

           • Be good at modal editing means
                      think complex commands ... fast!
           • Learn with practice!
           • Don’t read these slides again and again! But ...

Alessandro Manfredi              The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
What’s next ?
      • Use vimtutor !
      • Build your own reference, at first with few
             commands, then improve that when you need it.
      • Don’t practice as an exercise, use the editor when
             you need to edit texts.
      • Don’t be surprised if you will find yourself
             typing :wq even when not using vi


Alessandro Manfredi              The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
Q? /(& A)?/




Alessandro Manfredi      The “ vi “ Text Editor   Lug Roma 3 - http://www.lugroma3.org
How vi would seem if has been made by Microsoft
    Credits to Marigan’s Blog - http://blogs.sun.com/marigan/entry/how_the_vi_editor_would




Alessandro Manfredi                      The “ vi “ Text Editor      Lug Roma 3 - http://www.lugroma3.org
Online References
  •      Wikipedia
                                                               http://en.wikipedia.org/wiki/vi
  •      The vi lovers homepage
                                                                http://thomer.com/vi/vi.html
  •      Why do those nutheads use vi?
                                      http://www.viemu.com/a-why-vi-vim.htm
  •      Vi Reference Manual
                                                   http://drumlin.thehutt.org/vi/
  •      (Book) O'REILLY - Learning the vi Editor, Sixth Edition
                                            http://www.oreilly.com/catalog/vi6/



Alessandro Manfredi                   The “ vi “ Text Editor              Lug Roma 3 - http://www.lugroma3.org

Weitere ähnliche Inhalte

Andere mochten auch

Different types of Editors in Linux
Different types of Editors in LinuxDifferent types of Editors in Linux
Different types of Editors in LinuxBhavik Trivedi
 
Introduction to vi editor
Introduction to vi editorIntroduction to vi editor
Introduction to vi editorU.P Police
 
Emacs presentation
Emacs presentationEmacs presentation
Emacs presentationLingfei Kong
 
File permission in linux
File permission in linuxFile permission in linux
File permission in linuxPrakash Poudel
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linuxanandvaidya
 
The Search for Meaning in B2B Marketing
The Search for Meaning in B2B MarketingThe Search for Meaning in B2B Marketing
The Search for Meaning in B2B MarketingVelocity Partners
 
Permission chmod
Permission chmodPermission chmod
Permission chmodmfstep
 
Ftp.75 to 76
Ftp.75 to 76Ftp.75 to 76
Ftp.75 to 76myrajendra
 
Linux unix-commands
Linux unix-commandsLinux unix-commands
Linux unix-commandsZeelogic Solu
 
Implement text editor
Implement text editorImplement text editor
Implement text editorAmaan Shaikh
 
Useful linux-commands
Useful linux-commandsUseful linux-commands
Useful linux-commandsHimani Singh
 
MS BI SSIS Project Portfolio
MS BI SSIS Project PortfolioMS BI SSIS Project Portfolio
MS BI SSIS Project Portfoliopencarver
 
Basics of Batch Scripting
Basics of Batch ScriptingBasics of Batch Scripting
Basics of Batch ScriptingArik Fletcher
 
Using VI Editor in Red Hat by Rohit Kumar
Using VI Editor in Red Hat by Rohit KumarUsing VI Editor in Red Hat by Rohit Kumar
Using VI Editor in Red Hat by Rohit KumarRohit Kumar
 
1359 Vi Editor
1359 Vi Editor1359 Vi Editor
1359 Vi Editortechbed
 

Andere mochten auch (20)

Vi editor
Vi editorVi editor
Vi editor
 
Different types of Editors in Linux
Different types of Editors in LinuxDifferent types of Editors in Linux
Different types of Editors in Linux
 
Vi Editor
Vi EditorVi Editor
Vi Editor
 
Vi editor
Vi   editorVi   editor
Vi editor
 
Introduction to vi editor
Introduction to vi editorIntroduction to vi editor
Introduction to vi editor
 
Emacs presentation
Emacs presentationEmacs presentation
Emacs presentation
 
File permission in linux
File permission in linuxFile permission in linux
File permission in linux
 
Basic Unix
Basic UnixBasic Unix
Basic Unix
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linux
 
The Search for Meaning in B2B Marketing
The Search for Meaning in B2B MarketingThe Search for Meaning in B2B Marketing
The Search for Meaning in B2B Marketing
 
Permission chmod
Permission chmodPermission chmod
Permission chmod
 
Chmod
ChmodChmod
Chmod
 
Ftp.75 to 76
Ftp.75 to 76Ftp.75 to 76
Ftp.75 to 76
 
Linux unix-commands
Linux unix-commandsLinux unix-commands
Linux unix-commands
 
Implement text editor
Implement text editorImplement text editor
Implement text editor
 
Useful linux-commands
Useful linux-commandsUseful linux-commands
Useful linux-commands
 
MS BI SSIS Project Portfolio
MS BI SSIS Project PortfolioMS BI SSIS Project Portfolio
MS BI SSIS Project Portfolio
 
Basics of Batch Scripting
Basics of Batch ScriptingBasics of Batch Scripting
Basics of Batch Scripting
 
Using VI Editor in Red Hat by Rohit Kumar
Using VI Editor in Red Hat by Rohit KumarUsing VI Editor in Red Hat by Rohit Kumar
Using VI Editor in Red Hat by Rohit Kumar
 
1359 Vi Editor
1359 Vi Editor1359 Vi Editor
1359 Vi Editor
 

Ähnlich wie The "vi" Text Editor

Vi and redirection & piping in linux
Vi and redirection & piping in linuxVi and redirection & piping in linux
Vi and redirection & piping in linuxNeethu Jose
 
Linuxppt
LinuxpptLinuxppt
LinuxpptReka
 
Rabbits, indians and... Symfony meets queueing brokers
Rabbits, indians and...  Symfony meets queueing brokersRabbits, indians and...  Symfony meets queueing brokers
Rabbits, indians and... Symfony meets queueing brokersGaetano Giunta
 
Rustbridge
RustbridgeRustbridge
Rustbridgekent marete
 
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 survival guide
Vim survival guideVim survival guide
Vim survival guideBen McCormick
 

Ähnlich wie The "vi" Text Editor (11)

Vi and redirection & piping in linux
Vi and redirection & piping in linuxVi and redirection & piping in linux
Vi and redirection & piping in linux
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
What is Vim?
What is Vim?What is Vim?
What is Vim?
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Rabbits, indians and... Symfony meets queueing brokers
Rabbits, indians and...  Symfony meets queueing brokersRabbits, indians and...  Symfony meets queueing brokers
Rabbits, indians and... Symfony meets queueing brokers
 
Rustbridge
RustbridgeRustbridge
Rustbridge
 
Augusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim IntroductionAugusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim Introduction
 
Linex
LinexLinex
Linex
 
Vim survival guide
Vim survival guideVim survival guide
Vim survival guide
 
swl--3 (1).docx
swl--3 (1).docxswl--3 (1).docx
swl--3 (1).docx
 

Mehr von Alessandro Manfredi

Hey Cloud, it’s the user calling, he says he wants the security back
Hey Cloud, it’s the user calling, he says he wants the security backHey Cloud, it’s the user calling, he says he wants the security back
Hey Cloud, it’s the user calling, he says he wants the security backAlessandro Manfredi
 
WhyMCA HappyHour - EUHackathon Part II
WhyMCA HappyHour - EUHackathon Part IIWhyMCA HappyHour - EUHackathon Part II
WhyMCA HappyHour - EUHackathon Part IIAlessandro Manfredi
 
LUG - Ricompilazione kernel
LUG - Ricompilazione kernelLUG - Ricompilazione kernel
LUG - Ricompilazione kernelAlessandro Manfredi
 
LUG - Logical volumes management
LUG - Logical volumes managementLUG - Logical volumes management
LUG - Logical volumes managementAlessandro Manfredi
 

Mehr von Alessandro Manfredi (9)

Hey Cloud, it’s the user calling, he says he wants the security back
Hey Cloud, it’s the user calling, he says he wants the security backHey Cloud, it’s the user calling, he says he wants the security back
Hey Cloud, it’s the user calling, he says he wants the security back
 
WhyMCA HappyHour - EUHackathon Part II
WhyMCA HappyHour - EUHackathon Part IIWhyMCA HappyHour - EUHackathon Part II
WhyMCA HappyHour - EUHackathon Part II
 
Connect (4|n)
Connect (4|n)Connect (4|n)
Connect (4|n)
 
LUG - Ricompilazione kernel
LUG - Ricompilazione kernelLUG - Ricompilazione kernel
LUG - Ricompilazione kernel
 
LUG - Logical volumes management
LUG - Logical volumes managementLUG - Logical volumes management
LUG - Logical volumes management
 
LUG - Install Fest 2008
LUG - Install Fest 2008LUG - Install Fest 2008
LUG - Install Fest 2008
 
Find me a roof!
Find me a roof!Find me a roof!
Find me a roof!
 
Advanced Shell Scripting
Advanced Shell ScriptingAdvanced Shell Scripting
Advanced Shell Scripting
 
ExAlg Overview
ExAlg OverviewExAlg Overview
ExAlg Overview
 

KĂźrzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂşjo
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

KĂźrzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

The "vi" Text Editor

  • 1. The “ vi “ Text Editor Alessandro Manfredi Lug Roma 3 - http://www.lugroma3.org
  • 2. ? Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 3. Roadmap • Yes, I’m going to convince you to use this tool • Who, What, When, Where, Why • How to • Examples & Training Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 4. Once Upon a Time ... The 5 ‘w’ Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 5. The editor war • Modal Editor • Small and Fast • Textual env • Extensive use of chords • Bells & Whistles • GUI Both have a difcult learning curve Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 6. And the winner is ... POSIX ( IEEE 1003 – ISO/IEC 9945 ) SUS ( IEEE & The Open Group ) ( that means there is no actual winner, you can use whatever you want but since vi is part of the standard you should really know how to use it ) Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 7. Wait, I never missed anyth using ... • gedit • kate / kwrite • nano • joe • oowriter • notepad • ... whatever Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 8. So why ? ( running into where ) • Again, IT IS PART OF THE STANDARD • That means you nd it everywhere including BSD*, Mac Os X, Solaris, HP-UX, AIX, Windows with SFU, your microwave oven (if it’s posix-compliant), etc. Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 9. Other strong reasons (that you will probably ignore) • Really powerful editor • Complex tasks with few keystrokes • Effective regex support • Makes you damned fast (especially with touchtyping) • You can never raise hands from keyboard • Someone says modal editing increase productivity Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 10. What (the jargon le says..) vi: /V-I/, not, /vi:/, never, /siks/, n. [from ‘Visual Interface’] A screen editor crufted together by Bill Joy for an early BSD release. Became the de facto standard Unix editor and a nearly undisputed hacker favorite outside of MIT until the rise of EMACS after about 1984. Tends to frustrate new users no end, as it will neither take commands while expecting input text nor vice versa [... ] Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 11. How the ADM3A Keyboard looks like • Esc was where now TAB is • No arrows, just H , J , K , L Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 12. Clones • Vim Any clone extends the basic ‘vi’ • Elvis program with addictional functions but all of them share the common • nvi mode and subset of commands you • gvim are (hopefully) going to learn • bvi hint: try $which vi • calvin • lemmy, elwin, winvi, ... Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 13. How to ... Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 14. Modal Editing • Command Mode • Cursor is on the text • Can’t see what you’re typing, just its effects • Input Mode • Text typing and ONLY text typing • Directive Mode • Entered with <:> • You can see what you type this time =) Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 15. Switching Modes (1) Command Mode Input Mode : Directive Mode Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 16. Enter the editor • vi • vi lename • vi lename1 lename2 lename3 • vi -r lename • vi +cmd lename • vi +lnum lename • vi @rcle • ... Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 17. Very Basic usage example <a> Hello folks! <Esc> <:><w><q> <Enter> ( btw, ‘<x>’ means ‘ press the ‘x’ key ) $ cat lename Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 18. Switching Modes (2) • Command Mode > Input Mode • <a>, <A>,<i>,<I>, <o>,<O>, ... • Input Mode > Command Mode • <Esc> • Command Mode > Directive Mode • <:> • Directive Mode > Command Mode • clean the directive line ‘:’ included Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 19. Some Directive Line Commands :w ‘write’ (save) :w lename save as lename :q quit’ :q! quit’ forced (forget changes) :wq ( :x ) Combination of ‘w’ and ‘q’ :e lename ‘edit’ lename :r lename read’ lename (copy next) :n open the ‘next’ le :rew ‘rewind’ le list :ab token expression create a ‘token’ macro for exp :unab token delete the ‘token’ macro :n go to line n Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 20. Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 21. Moving Cursor h, j, k,l left, down, up, right G to the end of the document {} beginning / end of the paragraph () beginning / end of the sentence $ to the end of the line ^ to the beginning of the line n| to the n-th column w beginning of the next word e end of the next word + rst non-blank of next line - rst non-blank of previous line fx rst occurence of the ‘x’ char n cmd repeat ‘n’ times ‘cmd’ Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 22. Editing Commands i,a,I,A,o,O input mode editing u undo the last change U undo all the changes on the line J join current line and the next << , >> move the line left or right <L , >L move the following lineset l or r y# yank the # range p# paste the # range d# delete the # range yy, pp, dd yank, paste, delete one line Commands can be combined, e.g. 6yy yanks 6 lines Possible ranges # are w, ), }, fx, nj, $ as word, paragraph, sentence, rst x occurrence, till the n-th line and till the end of the line. Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 23. Examples ( and Training ) Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 24. The % and the ‘ . ‘ commands •% , in command mode is the block range • match things like vdDASFgvfd(sdf,rgae,##,adSDf) • ‘ . ‘ , just repeat the last command • consider that ‘ <i> [type text] <Esc> ‘ is still a command Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 25. ‘ . ‘ and the programmer day ... • ... that often starts with the need to implement some functions from signature already in the headers • ‘3yy’ and ‘p’ to copy something like bool check(int a, char c); int value(int strange); int failure(int my_process); • The rst task is replace semicolon with the blocks <A><backspace> { <Enter> } <Esc> <j.j.> Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 26. Good way to modal editing • One mode for each task support tasks separation • Command mode should be the most used • Insert text in input mode is a command too • and should be used “transactionally” • e.g. reading should be achieved in command mode • words replacement too! e.g. <cw>newword<Esc> Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 27. ‘ % ‘ and the programmer day ... • ... that goes on extracting function calls from complex expressions and assigning ‘em to a variable • something like if (!my_st.enf && do_smtg( s.isopn(), s.isdmz) && ( a & b.c )){ ... } • <fdc%> var <Esc><O> var = <Ctrl+R> ; <Esc> • turns that into var = do_smtg( s.isopn(), s.isdmz) ; if (!my_st.enf && var && ( a & b.c )){ ... } Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 28. Keep the audience awake or pull them to leave the room • What do these commands do ? 3J , 3dl , 3iHi<Esc>u , yf6 , dfyp , cfyp , llcfxy<Esc>hp • What is the difference between these commands? ‘ 4c( ‘ and ‘ 2c2( ‘ • How to nd the next 3 ‘ x ‘ char ? • How to replace the next 3 sentences with ‘-censored-’ Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 29. Search fx nd the next occurrence of x tx scroll to the next x Fx nd the previous x Tx scroll backwards to the prev x /exp search forward for exp ?exp search backwards for exp ; repeat last search , reverse the last search order / ,? repeat the last search Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 30. Regexp • “A regular expression (regex or regexp for short) is a special text string for describing a search pattern” • Very common in programming languages • Different syntaxes • Match regular languages • In short is a string made of chars, wildcards, multipliers and escape sequences, that can match an entire class of other strings. Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 31. Some regexp elements (in vi) ^ beginning of the line $ end of the line w alphanumeric chars W non-alphanumeric chars exp? exp, 0 or 1 occurrences exp+ exp, 1 or more occurrences exp* exp, 0 or more occurrences exp|pxe exp or pxe . ANY char < beginning of a word > end of a word Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 32. Search and replace ...with regexp from directive line • : <range> s / <exp> / <replace> / <mod> • Ranges: n, . , $, %, n,m ( for ‘n lines’, ‘single line’, ‘till the end’, ‘whole le’,’from n to m’ ) • Mods: c, g, n ( for ‘ask conrm’, global and ‘first n matches’ ) • Search and execute command • : <range> g / <exp> / <command> Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 33. Search Options • :set (no)ic • :set (no)hlsearch • :set (no)incsearch • :set (no)... Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 34. More Directive Line Commands • :map key cmd • :unmap key • :[n,m]w lename • :!shcmd • :r shcmd • :sh Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 35. Clones Conguration (vim) • VIM (:r $VIMRUNTIME/vimrc_example.vim) • :e ~/.vimrc ( linux & some unix ) • :e $VIM/_vimrc ( windows ) • :e /usr/share/vim/vimrc ( Mac OS X ) • set ai (set AutoIndex) • set ruler (show cursor position) • syntax on (enable syntax hl) • set nohlsearch (disable hlsearch) Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 36. Keep in mind that ... • Be good at modal editing means think complex commands ... fast! • Learn with practice! • Don’t read these slides again and again! But ... Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 37. What’s next ? • Use vimtutor ! • Build your own reference, at rst with few commands, then improve that when you need it. • Don’t practice as an exercise, use the editor when you need to edit texts. • Don’t be surprised if you will nd yourself typing :wq even when not using vi Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 38. Q? /(& A)?/ Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 39. How vi would seem if has been made by Microsoft Credits to Marigan’s Blog - http://blogs.sun.com/marigan/entry/how_the_vi_editor_would Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 40. Online References • Wikipedia http://en.wikipedia.org/wiki/vi • The vi lovers homepage http://thomer.com/vi/vi.html • Why do those nutheads use vi? http://www.viemu.com/a-why-vi-vim.htm • Vi Reference Manual http://drumlin.thehutt.org/vi/ • (Book) O'REILLY - Learning the vi Editor, Sixth Edition http://www.oreilly.com/catalog/vi6/ Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org