VIM
一 、Vim 简介
Vim 是Linux系统上的最著名的文本/代码编辑器,最大特色是完全使用键盘命令进行编辑,使用键盘流的各种组合进行操作,完全脱离了鼠标,提高工作效率。
二、Vim 使用
Photon@ct-srv02:~$ vim Android/frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
在Xshell或者Linux 命令行输入 vimtutor
后回车,会显示详尽的《VIM 使用教程》,部分如下:
Photon@ct-srv02:~$ vimtutor
===============================================================================
= 歡 迎 閱 讀 《 V I M 教 程 》 ── 版本 1.5 =
===============================================================================
vim 是一個具有很多命令的功能非常強大的編輯器。限于篇幅,在本教程當中
不就詳細介紹了。本教程的設計目標是講述一些必要的基本命令,而掌握好這
些命令,您就能夠很容易將vim當作一個通用的萬能編輯器來使用了。
完成本教程的內容大約需要25-30分鐘,取決于您訓練的時間。
每一節的命令操作將會更改本文。推薦您復制本文的一個副本,然後在副本上
進行訓練(如果您是通過"vimtutor"來啟動教程的,那麼本文就已經是副本了)。
切記一點︰本教程的設計思路是在使用中進行學習的。也就是說,您需要通過
執行命令來學習它們本身的正確用法。如果您只是閱讀而不操作,那麼您可能
會很快遺忘這些命令的!
好了,現在請確定您的Shift-Lock(大小寫鎖定鍵)還沒有按下,然後按鍵盤上
的字母鍵 j 足夠多的次數來移動光標,直到第一節的內容能夠完全充滿屏幕。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
第一講第一節︰移動光標
※※ 要移動光標,請依照說明分別按下 h、j、k、l 鍵。 ※※
^
k 提示︰ h 的鍵位于左邊,每次按下就會向左移動。
< h l > l 的鍵位于右邊,每次按下就會向右移動。
j j 鍵看起來很象一支尖端方向朝下的箭頭。
v
三、配置自定义.vimrc文件
Photon@ct-srv02:~$ ls -al | grep .vim
drwxr-xr-x 2 tanhongguang tanhongguang 4096 5月 4 2017 .vim
-rw------- 1 tanhongguang tanhongguang 21364 4月 23 10:54 .viminfo
-rw-rw-r-- 1 tanhongguang tanhongguang 10468 4月 28 2017 .vimrc
将如下代码保存成.vimrc
文件,替换工作目录下默认的.vimrc
文件:
" maintainer:
" Amir Salihefendic
" http://amix.dk - amix@amix.dk
"
" Version:
" 5.0 - 29/05/12 15:43:36
"
" Blog_post:
" http://amix.dk/blog/post/19691#The-ultimate-Vim-configuration-on-Github
"
" Awesome_version:
" Get this config, nice color schemes and lots of plugins!
"
" Install the awesome version from:
"
" https://github.com/amix/vimrc
"
" Syntax_highlighted:
" http://amix.dk/vim/vimrc.html
"
" Raw_version:
" http://amix.dk/vim/vimrc.txt
"
" Sections:
" -> General
" -> VIM user interface
" -> Colors and Fonts
" -> Files and backups
" -> Text, tab and indent related
" -> Visual mode related
" -> Moving around, tabs and buffers
" -> Status line
" -> Editing mappings
" -> vimgrep searching and cope displaying
" -> Spell checking
" -> Misc
" -> Helper functions
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=500
" Enable filetype plugins
filetype plugin on
filetype indent on
" Set to auto read when a file is changed from the outside
set autoread
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = &