免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2077 | 回复: 0
打印 上一主题 下一主题

A sample .exrc file for vi editor users [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-02 11:44 |只看该作者 |倒序浏览

A sample .exrc file for vi editor users  
Introduction
This article presents a sample .exrc file that can be used by users of the vi editor.  The .exrc file, located in your home directory, is the startup (or configuration) file for the vi editor.
The intent of this brief article is to show some of the ways you can modify the configuration of the vi editor.
  
Brief discussion
Listing 1 shows our sample .exrc file. In this file we've changed the definition of some of the keystrokes within the editor.  Note that map commands are used to map keystrokes.  By configuring this .exrc file, we've mapped many of the function keys on your keyboard, including , , ...  (with the exception of ).
Note that the  key is mapped to run a more command on a file named .vi_help.  The .vi_help file is shown in Listing 2.  It's just a plain text file that provides some "help" for users of the vi editor.  When you hit the  key, this file will be displayed (if properly installed in your home directory).
The  key is now programmed to displayed line numbers when you select it.   performs the opposite function - it hides the line numbers, so these two keystrokes are essentially toggle switches for the number display.
  
  
set showmode
set autoindent
map #1 :!more /.vi_help
map #2 :set number
map #3 :set nonumber
map #5 o   #-------------------------------------------------------------------------#

map #6 A----------
map #7 o
map #8 o
map #9 :1,$s/
  
Listing 1:
  exrc - a sample .exrc file for users of the vi editor
  
Note that Listing 1 may appear a little unusual. That's because it includes control characters (such as ^V and ^M) that may not print properly on screen. If you download the .exrc file using the link shown at the end of this article, the file will be downloaded with these control characters, which it needs to work properly.
  
  
                                                                        vi Help
----------------                        -----------------
Editing Commands                        Deleting Commands
----------------                        -----------------
i        insert                                x        delete character
o        open a new line (below)                X        delete character to left
O        open a new line (above)                d0        delete to beginning of line
a        append                                d$        delete to end of line
A        append at end of line                dd        delete line
u        undo                                5dd        delete 5 lines
.        repeat last command
-------------------                        -----------------
Cutting and Pasting                        Movement Commands
-------------------                        -----------------
yy        yank                                H        move to top of screen (high)
5yy        yank 5 lines                        M        move to middle
p        paste                                L        move to low
P        paste above current position        10G        go to line 10
                                        w        go to next word
                                        b        go back to previous word
                                        0        beginning of line
                                        $        end of line
------------------
Searching Commands
------------------
/fred                search for "fred"
?fred                search backwards for "fred"
n                repeat the last search
----------------------------------
Function Key Mappings (Customized)
----------------------------------
F1:  get help (show this screen)
F2:  set number
F3:  set nonumber
F4:
F5:  insert a comment line
---------------------
Run External Commands
---------------------
:!ls -al                list current directory (long list)
:!pwd                        print working directory
----------------------
Miscellaneous Commands
----------------------
:r                        read contents of a file into the current file
:s/FRED/BARNEY/g        swap FRED with BARNEY (current line only)
:10,20s/FRED/BARNEY/g        swap FRED with BARNEY on lines 10 through 20
:1,$s/FRED/BARNEY/g        swap every occurrence of FRED with BARNEY (entire file)
:10,20d                delete lines 10 through 20
:10,20y                yank (copy) lines 10 through 20 to the buffer
----------------
Auto-Indentation
----------------
Your ~/.exrc file is configured to automatically indent each line.  
To move backwards (and eliminate indentation), hit
        ^d
  
Listing 2:
.vi_help - This file is displayed when the user hits the  function key.  Both this file and the .exrc file shown in Listing 1 must be installed in the user's home directory.
  
  
Installation and comments
If you're interested in seeing how the .exrc and .vi_help files affect your version of the vi editor, just download the files using the links shown below. After you've downloaded the files, just copy them to your home directory. (As always, if you have files with these same names in your home directory already, make a backup copy of them before installing these files.)
Once you've installed these files in your home directory, just start the vi editor, and try using the various function keys that we've defined.
If you have good ideas for a .exrc file, please feel free to
write us with your suggestions
.  We'd love to hear from you, and we'll include your thoughts/comments as an addition to this article!
Other commands that readers have recommended:

  • set ignorecase

Download the files
If you'd like to download these files, just click on the links below.  After you click on each file, just select File|Save As... from your browser to save the .profile to your local filesystem.

文件:
exrc.rar
大小:
1KB
下载:
下载



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/30557/showart_290513.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP