SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
RedHat Enterprise Linux Essential
  Unit 5: vim: An Advanced Text Editor
vim: An Advanced Text Editor
   Introducing vim
   vim: A Modal Editor
   vim Basics
   Opening a file in vim
   Modifying a File Insert Mode
   Saving a File and Exiting vim Ex Mode
   Using Command Mode
   Moving Around Command Mode
   Search and Replace Command Mode
   Manipulating Text Command Mode
   Undoing Changes Command Mode
   Visual Mode
   Using multiple "windows“
   Configuring vi and vim
   Learning more
Introducing vim
 Newer version of vi, the standard Unix text editor
     Executing vi runs vim by default
 gvim: Graphical version of vim
     Applications + Programming -> Vi iMproved
     Provided by vim-X11 package
 Advantages:
    Speed: Do more with fewer keystrokes
    Simplicity: No dependence on mouse/GUI
    Availability: Included with most Unix-like OSes
 Disadvantages
    Difficulty: Steeper learning curve than simpler editors
        • Key bindings emphasize speed over intuitiveness
vim Basics

 To use vim, you must at least be able to
    Open a file

    Modify a file (insert mode)

    Save a file (ex mode)
Opening a file in vim


 To start vi:

    vim filename

    If the file exists, the file is opened and the contents are displayed

    If the file does not exist, vi creates it when the edits are saved for the

     first time
Modifying a File Insert Mode

 i begins insert mode at the cursor

 Many other options exist
    A append to end of line

    I insert at beginning of line

    o insert new a line (below)

    O insert new line (above)
Saving a File and Exiting vim Ex Mode


 Enter Ex Mode with :
    Creates a command prompt at bottom-left of screen

 Common write/quit commands:
    :w writes (saves) the file to disk

    :wq writes and quits

    :q! quits, even if changes are lost
Using Command Mode


 Default mode of vim

 Keys describe movement and text manipulation commands

 Commands repeat when preceded by a number

 Example
    Right Arrow moves right one character

    5, Right Arrow moves right five characters
Moving Around Command Mode

 Move by character: Arrow Keys, h, j, k, l
    Non-arrow keys useful for remote connections to older systems

 Move by word: w, b

 Move by sentence: ), (

 Move by paragraph: }, {

 Jump to line x: xG

 Jump to end: G
Search and Replace Command Mode

 Search as in less
    /, n, N

 Search/Replace as in sed
    Affects current line by default

    Use x,y ranges or % for whole file

               :1,5s/cat/dog/

               :%s/cat/dog/gi
Manipulating Text Command Mode
Undoing Changes Command Mode


 u undo most recent change

 U undo all changes to the current line since the cursor landed
  on the line

 Ctrl-r redo last "undone" change
Visual Mode


 Allows selection of blocks of text
    v starts character-oriented highlighting

    V starts line-oriented highlighting

    Activated with mouse in gvim

 Visual keys can be used in conjunction with movement keys:
    w, ), }, arrows, etc

 Highlighted text can be deleted, yanked, changed, filtered,
  search/replaced, etc.
Using multiple "windows"


 Multiple documents can be viewed in a single vim screen.

       $ vim –o ~/.bashrc ~/.bash_profile
    Ctrl-w, s splits the screen horizontally

    Ctrl-w, v splits the screen vertically

    Ctrl-w, Arrow moves between windows

 Ex-mode instructions always affect the current window

 :help windows displays more window commands
Configuring vi and vim
 Configuring on the fly
                :set or :set all
 Configuring permanently
                ~/.vimrc or ~/.exrc
 A few common configuration items
      :set number
      :set autoindent
      :set textwidth=65 (vim only)
      :set wrapmargin=15
      :set ignorecase
 Run :help option-list for a complete list
Learning more


 vi/vim built-in help
    :help

    :help topic

    Use :q to exit help

 vimtutor command
Unit 5 vim an advanced text editor

Más contenido relacionado

La actualidad más candente

Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script Amit Ghosh
 
system management -shell programming by gaurav raikar
system management -shell programming by gaurav raikarsystem management -shell programming by gaurav raikar
system management -shell programming by gaurav raikarGauravRaikar3
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foobrian_dailey
 
Terminal commands ubuntu 2
Terminal commands ubuntu 2Terminal commands ubuntu 2
Terminal commands ubuntu 2raj upadhyay
 
Shell programming 2
Shell programming 2Shell programming 2
Shell programming 2Gourav Varma
 
Shell programming 2
Shell programming 2Shell programming 2
Shell programming 2Kalkey
 
Gnome terminal basics
Gnome terminal basicsGnome terminal basics
Gnome terminal basicsKamrul Hasan
 
Linux commd
Linux commdLinux commd
Linux commdragav03
 
Linux commd
Linux commdLinux commd
Linux commdragav03
 
[PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list [PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list nisivaasdfghj
 
Basic basic solaris quick referent card
Basic basic solaris quick referent cardBasic basic solaris quick referent card
Basic basic solaris quick referent cardBui Van Cuong
 
VI Editors
VI EditorsVI Editors
VI EditorsDeivanai
 

La actualidad más candente (20)

Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
system management -shell programming by gaurav raikar
system management -shell programming by gaurav raikarsystem management -shell programming by gaurav raikar
system management -shell programming by gaurav raikar
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
 
Terminal commands ubuntu 2
Terminal commands ubuntu 2Terminal commands ubuntu 2
Terminal commands ubuntu 2
 
Ubuntu Terminal
Ubuntu TerminalUbuntu Terminal
Ubuntu Terminal
 
Intro commandline
Intro commandlineIntro commandline
Intro commandline
 
Rhel2
Rhel2Rhel2
Rhel2
 
Shell programming 2
Shell programming 2Shell programming 2
Shell programming 2
 
Shell programming 2
Shell programming 2Shell programming 2
Shell programming 2
 
Vi editor in linux
Vi editor in linuxVi editor in linux
Vi editor in linux
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Gnome terminal basics
Gnome terminal basicsGnome terminal basics
Gnome terminal basics
 
Linux commd
Linux commdLinux commd
Linux commd
 
Linux commd
Linux commdLinux commd
Linux commd
 
[PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list [PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list
 
Basic basic solaris quick referent card
Basic basic solaris quick referent cardBasic basic solaris quick referent card
Basic basic solaris quick referent card
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
VI Editors
VI EditorsVI Editors
VI Editors
 
Babitha.linux
Babitha.linuxBabitha.linux
Babitha.linux
 

Similar a Unit 5 vim an advanced text editor

Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to VimBrandon Liu
 
Tuffarsi in vim
Tuffarsi in vimTuffarsi in vim
Tuffarsi in vimsambismo
 
Augusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim IntroductionAugusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim IntroductionKeith Pickett
 
andrew's guide to vim
andrew's guide to vimandrew's guide to vim
andrew's guide to vimAndrew Yi
 
Text editor In RHEL
Text editor In RHELText editor In RHEL
Text editor In RHELVarnnit Jain
 
lectuer 21-22.pptx
lectuer 21-22.pptxlectuer 21-22.pptx
lectuer 21-22.pptxpoonam256394
 
Vim Editor And Basic Scripting (Ch-7)
Vim Editor And Basic Scripting (Ch-7)Vim Editor And Basic Scripting (Ch-7)
Vim Editor And Basic Scripting (Ch-7)MohsinHusenManasiya
 
Linux network manager configure
Linux network manager configureLinux network manager configure
Linux network manager configureInfoExcavator
 
Linux network manager configuration
Linux network manager configurationLinux network manager configuration
Linux network manager configurationMd Meherab Hossen
 
Linux text editors Vim nano
Linux text editors Vim nano Linux text editors Vim nano
Linux text editors Vim nano Md Meherab Hossen
 
1_Editors_in_Unix
1_Editors_in_Unix1_Editors_in_Unix
1_Editors_in_UnixGautam Raja
 
Quick-Start-UNIX.pdf
Quick-Start-UNIX.pdfQuick-Start-UNIX.pdf
Quick-Start-UNIX.pdfHODCA1
 
Lesson 3 Working with Files in Linux
Lesson 3 Working with Files in LinuxLesson 3 Working with Files in Linux
Lesson 3 Working with Files in LinuxSadia Bashir
 

Similar a Unit 5 vim an advanced text editor (20)

Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to Vim
 
Tuffarsi in vim
Tuffarsi in vimTuffarsi in vim
Tuffarsi in vim
 
Augusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim IntroductionAugusta Linux User Group - Vim Introduction
Augusta Linux User Group - Vim Introduction
 
andrew's guide to vim
andrew's guide to vimandrew's guide to vim
andrew's guide to vim
 
Text editor In RHEL
Text editor In RHELText editor In RHEL
Text editor In RHEL
 
lectuer 21-22.pptx
lectuer 21-22.pptxlectuer 21-22.pptx
lectuer 21-22.pptx
 
Vim Editor And Basic Scripting (Ch-7)
Vim Editor And Basic Scripting (Ch-7)Vim Editor And Basic Scripting (Ch-7)
Vim Editor And Basic Scripting (Ch-7)
 
Linux network manager configure
Linux network manager configureLinux network manager configure
Linux network manager configure
 
Linux network manager configuration
Linux network manager configurationLinux network manager configuration
Linux network manager configuration
 
Vim knowhow
Vim knowhowVim knowhow
Vim knowhow
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
 
Linux text editors Vim nano
Linux text editors Vim nano Linux text editors Vim nano
Linux text editors Vim nano
 
Linux text editors
Linux text editorsLinux text editors
Linux text editors
 
1_Editors_in_Unix
1_Editors_in_Unix1_Editors_in_Unix
1_Editors_in_Unix
 
Vim survival guide
Vim survival guideVim survival guide
Vim survival guide
 
Vim Vi Improved
Vim Vi ImprovedVim Vi Improved
Vim Vi Improved
 
Quick-Start-UNIX.pdf
Quick-Start-UNIX.pdfQuick-Start-UNIX.pdf
Quick-Start-UNIX.pdf
 
swl--3 (1).docx
swl--3 (1).docxswl--3 (1).docx
swl--3 (1).docx
 
Vi editor
Vi editorVi editor
Vi editor
 
Lesson 3 Working with Files in Linux
Lesson 3 Working with Files in LinuxLesson 3 Working with Files in Linux
Lesson 3 Working with Files in Linux
 

Más de root_fibo

Unit 13 network client
Unit 13 network clientUnit 13 network client
Unit 13 network clientroot_fibo
 
Unit 12 finding and processing files
Unit 12 finding and processing filesUnit 12 finding and processing files
Unit 12 finding and processing filesroot_fibo
 
Unit3 browsing the filesystem
Unit3 browsing the filesystemUnit3 browsing the filesystem
Unit3 browsing the filesystemroot_fibo
 
Unit 10 investigating and managing
Unit 10 investigating and managingUnit 10 investigating and managing
Unit 10 investigating and managingroot_fibo
 
Unit 9 basic system configuration tools
Unit 9 basic system configuration toolsUnit 9 basic system configuration tools
Unit 9 basic system configuration toolsroot_fibo
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing toolsroot_fibo
 
Unit 7 standard i o
Unit 7 standard i oUnit 7 standard i o
Unit 7 standard i oroot_fibo
 
Unit 4 user and group
Unit 4 user and groupUnit 4 user and group
Unit 4 user and grouproot_fibo
 

Más de root_fibo (9)

Unit 13 network client
Unit 13 network clientUnit 13 network client
Unit 13 network client
 
Unit 12 finding and processing files
Unit 12 finding and processing filesUnit 12 finding and processing files
Unit 12 finding and processing files
 
Unit3 browsing the filesystem
Unit3 browsing the filesystemUnit3 browsing the filesystem
Unit3 browsing the filesystem
 
Unit 10 investigating and managing
Unit 10 investigating and managingUnit 10 investigating and managing
Unit 10 investigating and managing
 
Unit 9 basic system configuration tools
Unit 9 basic system configuration toolsUnit 9 basic system configuration tools
Unit 9 basic system configuration tools
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing tools
 
Unit 7 standard i o
Unit 7 standard i oUnit 7 standard i o
Unit 7 standard i o
 
Unit 4 user and group
Unit 4 user and groupUnit 4 user and group
Unit 4 user and group
 
Unit2 help
Unit2 helpUnit2 help
Unit2 help
 

Último

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"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
 
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
 

Último (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"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
 
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
 

Unit 5 vim an advanced text editor

  • 1. RedHat Enterprise Linux Essential Unit 5: vim: An Advanced Text Editor
  • 2. vim: An Advanced Text Editor  Introducing vim  vim: A Modal Editor  vim Basics  Opening a file in vim  Modifying a File Insert Mode  Saving a File and Exiting vim Ex Mode  Using Command Mode  Moving Around Command Mode  Search and Replace Command Mode  Manipulating Text Command Mode  Undoing Changes Command Mode  Visual Mode  Using multiple "windows“  Configuring vi and vim  Learning more
  • 3. Introducing vim  Newer version of vi, the standard Unix text editor  Executing vi runs vim by default  gvim: Graphical version of vim  Applications + Programming -> Vi iMproved  Provided by vim-X11 package  Advantages:  Speed: Do more with fewer keystrokes  Simplicity: No dependence on mouse/GUI  Availability: Included with most Unix-like OSes  Disadvantages  Difficulty: Steeper learning curve than simpler editors • Key bindings emphasize speed over intuitiveness
  • 4. vim Basics  To use vim, you must at least be able to  Open a file  Modify a file (insert mode)  Save a file (ex mode)
  • 5. Opening a file in vim  To start vi:  vim filename  If the file exists, the file is opened and the contents are displayed  If the file does not exist, vi creates it when the edits are saved for the first time
  • 6. Modifying a File Insert Mode  i begins insert mode at the cursor  Many other options exist  A append to end of line  I insert at beginning of line  o insert new a line (below)  O insert new line (above)
  • 7. Saving a File and Exiting vim Ex Mode  Enter Ex Mode with :  Creates a command prompt at bottom-left of screen  Common write/quit commands:  :w writes (saves) the file to disk  :wq writes and quits  :q! quits, even if changes are lost
  • 8. Using Command Mode  Default mode of vim  Keys describe movement and text manipulation commands  Commands repeat when preceded by a number  Example  Right Arrow moves right one character  5, Right Arrow moves right five characters
  • 9. Moving Around Command Mode  Move by character: Arrow Keys, h, j, k, l  Non-arrow keys useful for remote connections to older systems  Move by word: w, b  Move by sentence: ), (  Move by paragraph: }, {  Jump to line x: xG  Jump to end: G
  • 10. Search and Replace Command Mode  Search as in less  /, n, N  Search/Replace as in sed  Affects current line by default  Use x,y ranges or % for whole file :1,5s/cat/dog/ :%s/cat/dog/gi
  • 12. Undoing Changes Command Mode  u undo most recent change  U undo all changes to the current line since the cursor landed on the line  Ctrl-r redo last "undone" change
  • 13. Visual Mode  Allows selection of blocks of text  v starts character-oriented highlighting  V starts line-oriented highlighting  Activated with mouse in gvim  Visual keys can be used in conjunction with movement keys:  w, ), }, arrows, etc  Highlighted text can be deleted, yanked, changed, filtered, search/replaced, etc.
  • 14. Using multiple "windows"  Multiple documents can be viewed in a single vim screen. $ vim –o ~/.bashrc ~/.bash_profile  Ctrl-w, s splits the screen horizontally  Ctrl-w, v splits the screen vertically  Ctrl-w, Arrow moves between windows  Ex-mode instructions always affect the current window  :help windows displays more window commands
  • 15. Configuring vi and vim  Configuring on the fly :set or :set all  Configuring permanently ~/.vimrc or ~/.exrc  A few common configuration items  :set number  :set autoindent  :set textwidth=65 (vim only)  :set wrapmargin=15  :set ignorecase  Run :help option-list for a complete list
  • 16. Learning more  vi/vim built-in help  :help  :help topic  Use :q to exit help  vimtutor command