RHCE033 Unit9 vim: An Advanced Text Editor

Objectives
Upon completion of this unit, you should be able to:
  • Use the three primary modes of vi and vim
  • Navigate text and enter Insert mode
  • Change, delete, yank and put text
  • Undo changes
  • Search a document
  • Save and exit
Introducing vim
1) New version of vi, the standard Unix text editor
  • Executing vi runs vim by default
2) gvim: Graphical version of vim
  • Applications + Programming –> Vi iMproved
  • Provided by vim-X11 package
3) Advantages:
  • Speed: Do more with fewer keystrokes
  • Simplicity: No dependence on mouse/GUI
  • Availability: Included with most Unix-like OSes
4) Disadvantages:
  • Difficulty: Steeper learning curve than simpler editor. Key bindings emphasizes speed over intuitiveness
vim: A Modal Editor
1) Keystroke behavior is dependent upon vim’s “mode”
2) Three main modes
  • Command mode (default): Move cursor, cut/paste text, change mode
  • Insert mode: Modify text
  • Ex Mode: Save, quit, etc
3) Esc exits current mode
4) EscEsc always returns to command mode
vim Basics
1) To use vim, you must at least be able to
  • Open a file
  • Modify a file (insert mode)
  • Save a file (ex mode)
Openig a file in vim
1) 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
1) i begins insert mode at the cursor
2) Many other options exist
  • A append to end of line
  • I insert at the begining of the line
  • o insert a new line (below)
  • O insert a new line (above)
Saving a File and Exiting vim – Ex Mode
1) Enter Ex mode with:
  • Creates a command prompt at bottom-left of screen
2) Common write/quit commands:
  • :w writes (saves) the file to disk
  • :wq wirtes and quits
  • :q! quits, even if changes are lost
Using Command Mode
1) Default mode of vim
2) Keys describe movement and text manipulation commands
3) Commands repeate when preceded by a number
4) Example
  • Right Arrow moves right one character
  • 5, Right Arrow moves five characters
Moving  Around Command Mode
1) Move by characters: Arrow Keys, h, j, k, l
2) Move by word: w, b
3) Move by sentence: ), (
4) Move by paragraph: }, {
5) Jump to line x: xG
6) Jump to end: G
Search and Replace Comomand Mode
1) Search as in less: /, n, N
2) Search/ Replace as in sed
  • Affects current line by default
  • Use x,y range of % for whole file
:1, 5s/cat/dog/
:%s/cat/dog/gi
Manipulating Text Command Mode
 Change
(replace)
Delete
(cut)
Yank
(copy)
Lineccddyy
Lettercldlyl
Wordcwdwyw
Sentence aheadc)d)y)
Sentence behind c(d(y(
Paragraph above c{d
{
y{
Paragraph belowc}d}y}
Undoing Changes Command Mode
1) u undo most recent changes
2) U undo all changes to the current line since the cursor landed on the line
3) Ctrl+r redo last “undo” change
Visual Mode
1) Allows selection of blocks of text
  • v starts character-oriented highlighting
  • V starts line-oriented highlighting
  • Activated with mouse in gvim
2) Visual keys can be used in conjuction with movement keys: w, ), }, arrow, etc
3) Highlighted text can be deleted, yanked, changed, filtered, search/replace, etc.
Using multiple “Windows”
1) Multiple documents can be viewed in a single vim screen
  • Ctrl+w, s splits the screen horizontally
  • Ctrl+w, v splits the screen vertically
  • Ctrl+w, Arrow moves between windows
2) Ex-mode instructions always affect the current window
3) :help windows displays more window commands.
Configuring vi and vim
1) Configuring on the fly
  • :set or :set all
2) Configuring permanently
  • ~/.vimrc or ~/.exrc
3) A few common configuration items
  • :set number
  • :set autoindent
  • :set text (vim only)
  • :set wrapmargin=15
  • :set ignorecase
4) Run: help option-list for a complete file
Learning more
1) vi/ vim built-in help
  • :help
  • :help topic
  • Use :q to exit help
2) vimtutor command
End of Unit9
1) Questions and Answers
2) Summary
  • Use the three primary modes of vi and vim
  • Move the cursor and enter Insert mode
  • Change, delete, yank and put text
  • Undo changes
  • Search a document
  • Save and exit
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值