首页 > 技术文章 > vim基本操作

docnan 2017-07-01 18:37 原文

在Linux系统中有多种代码编辑器,例如vim, gedit, emacs。这这些编辑器各有所长,就我个人而言,对于比较短的代码,一般可以用vim解决就不用其它的工具,而长代码的情况下更喜欢用gedit,这个gnome自带的代码编辑器是完全够用的,而对emacs的使用并不是非常熟悉,虽然有很多大神强烈推荐。这就相当于学习游泳,自由泳和蛙泳都可以游,而我可以游较好的蛙泳,但是自由泳就是怎么学也无法熟练。所以下面只介绍一下vim的常用命令和使用方法。

  1. undo
:u
  1. exit without change
:q
  1. exit with saved change
:x
  1. save change in vim
:w
  1. Vim易用配置:配置文件是~/.vimrc
# 显示语法高亮,针对主流的编程语言
syntax on
# 设置利用鼠标自由地移动光标
set mouse=a
  1. vim记住上次编辑和浏览的位置,可以在~/.vimrc中添加如下代码段[2]:
"remember last update or view postion"
 " Only do this part when compiled with support for autocommands 
 if has("autocmd")
 " In text files, always limit the width of text to 78 characters 
 autocmd BufRead *.txt set tw=78
 " When editing a file, always jump to the last cursor position 
 autocmd BufReadPost *
 \ if line("'\"") > 0 && line ("'\"") <= line("$") |
 \ exe "normal g'\"" |
 \ endif 
 endif
  1. vim开启单词拼写检查[3]
:set spell

虽然也可以将这个设置写进.vimrc中,但是单词拼写的检查和多时候只是针对latex和txt文件中临时出现的英语单词进行的,在更多的时候vim操作的对象是程序代码,里面并没有正确的英语单词,所以拼写检查是完全没有必要的,因此只要可以临时对拼写进行检查就可以了。

参考:
[1]http://blog.csdn.net/hzhsan/article/details/45498749
[2]http://www.cnblogs.com/jiuyueguang/p/3153798.html
[3]http://www.linuxidc.com/wap.aspx?nid=73212&cid=5&sp=1027

推荐阅读