SlideShare a Scribd company logo
1 of 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 difficult 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 file 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 filename




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 filename                                               save as filename
  :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
  +                                          first non-blank of next line
  -                                      first 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,
  first 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                                      find the next occurrence of x
  tx                                                scroll to the next x
  Fx                                                 find 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 Configuration (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

More Related Content

Viewers also liked

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

Viewers also liked (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
 

Similar to The "vi" Text Editor

Similar to 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
 

More from Alessandro Manfredi

More from 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
 

Recently uploaded

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Recently uploaded (20)

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

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 difficult 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 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
  • 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 file 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 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
  • 17. Very Basic usage example <a> Hello folks! <Esc> <:><w><q> <Enter> ( btw, ‘<x>’ means ‘ press the ‘x’ key ) $ cat filename 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 filename save as filename :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
  • 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 + first non-blank of next line - first 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
  • 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, first 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 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
  • 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 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
  • 29. Search fx find the next occurrence of x tx scroll to the next x Fx find 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 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
  • 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 filename • :!shcmd • :r shcmd • :sh Alessandro Manfredi The “ vi “ Text Editor Lug Roma 3 - http://www.lugroma3.org
  • 35. Clones Configuration (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 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
  • 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