一些提高效率的技巧:
智能运动
*和#在向前/向后光标下搜索单词。
W到下一个单词
W到下一个空格分隔的单词
B /e到当前单词的开头/结尾。(B / E只代表空格)
gg / G跳转到文件的开始/结束。
%跳转到匹配{..}或(..)等. .
{/}跳转到下一段。
”。跳转回上次编辑的行。
g;跳回上次编辑的位置。
快速编辑命令
我在开头插入。
end的附加语句。
o / o打开一个新的行后/前电流。
v / v / Ctrl+ v可视模式(选择文本!)
Shift+R替换文本
C更改剩余部分行。
结合命令
大多数命令接受数量和方向,例如:
改变直到单词结束
改变3个单词
BcW =开始全字,更改全字
ciW =改变内心的词。
Ci " =改变内部之间的".."
Ci(=更改文本之间(..)
Ci < = change text between < ..>(需要在vimrc中设置匹配对+=<:>)
4dd =删除4行
3x =删除3个字符。
3s =替换3个字符。
有用的程序员命令
R替换一个字符(例如rd用d替换当前字符)。
~改变情况。
J连接两条线
Ctrl+A / Ctrl+X增加/减少一个数字。
. 重复最后一个命令(一个简单的宏)
==修复行缩进
>缩进块(可视模式下)
< unindent block(在可视模式下)
宏录制
按q[键]开始录音。
然后按q键停止录制。
宏可以使用@[key]播放。
通过使用非常特定的命令和动作,VIM可以为下一行重新播放这些确切的动作。(例如A表示尾尾,b / e表示将光标移动到单词的开头或结尾)
良好设置的示例
# reset to vim-defaults
if &compatible # only if not set before:
set nocompatible # use vim-defaults instead of vi-defaults (easier, more user friendly)
endif
# display settings
set background=dark # enable for dark terminals
set nowrap # dont wrap lines
set scrolloff=2 # 2 lines above/below cursor when scrolling
set number # show line numbers
set showmatch # show matching bracket (briefly jump)
set showmode # show mode in status bar (insert/replace/...)
set showcmd # show typed command in status bar
set ruler # show cursor position in status bar
set title # show file in titlebar
set wildmenu # completion with menu
set wildignore=*.o,*.obj,*.bak,*.exe,*.py[co],*.swp,*~,*.pyc,.svn
set laststatus=2 # use 2 lines for the status bar
set matchtime=2 # show matching bracket for 0.2 seconds
set matchpairs+=<:> # specially for html
# editor settings
set esckeys # map missed escape sequences (enables keypad keys)
set ignorecase # case insensitive searching
set smartcase # but become case sensitive if you type uppercase characters
set smartindent # smart auto indenting
set smarttab # smart tab handling for indenting
set magic # change the way backslashes are used in search patterns
set bs=indent,eol,start # Allow backspacing over everything in insert mode
set tabstop=4 # number of spaces a tab counts for
set shiftwidth=4 # spaces for autoindents
#set expandtab # turn a tabs into spaces
set fileformat=unix # file mode is unix
#set fileformats=unix,dos # only detect unix file format, displays that ^M with dos files
# system settings
set lazyredraw # no redraws in macros
set confirm # get a dialog when :q, :w, or :wq fails
set nobackup # no backup~ files.
set viminfo='20,\"500 # remember copy registers after quitting in the .viminfo file -- 20 jump links, regs up to 500 lines'
set hidden # remember undo after quitting
set history=50 # keep 50 lines of command history
set mouse=v # use mouse in visual mode (not normal,insert,command,help mode
# color settings (if terminal/gui supports it)
if &t_Co > 2 || has("gui_running")
syntax on # enable colors
set hlsearch # highlight search (very useful!)
set incsearch # search incremently (search while typing)
endif
# paste mode toggle (needed when using autoindent/smartindent)
map <F10> :set paste<CR>
map <F11> :set nopaste<CR>
imap <F10> <C-O>:set paste<CR>
imap <F11> <nop>
set pastetoggle=<F11>
# Use of the filetype plugins, auto completion and indentation support
filetype plugin indent on
# file type specific settings
if has("autocmd")
# For debugging
#set verbose=9
# if bash is sh.
let bash_is_sh=1
# change to directory of current file automatically
autocmd BufEnter * lcd %:p:h
# Put these in an autocmd group, so that we can delete them easily.
augroup mysettings
au FileType xslt,xml,css,html,xhtml,javascript,sh,config,c,cpp,docbook set smartindent shiftwidth=2 softtabstop=2 expandtab
au FileType tex set wrap shiftwidth=2 softtabstop=2 expandtab
# Confirm to PEP8
au FileType python set tabstop=4 softtabstop=4 expandtab shiftwidth=4 cinwords=if,elif,else,for,while,try,except,finally,def,class
augroup END
augroup perl
# reset (disable previous 'augroup perl' settings)
au!
au BufReadPre,BufNewFile
\ *.pl,*.pm
\ set formatoptions=croq smartindent shiftwidth=2 softtabstop=2 cindent cinkeys='0{,0},!^F,o,O,e' " tags=./tags,tags,~/devel/tags,~/devel/C
# formatoption:
# t - wrap text using textwidth
# c - wrap comments using textwidth (and auto insert comment leader)
# r - auto insert comment leader when pressing <return> in insert mode
# o - auto insert comment leader when pressing 'o' or 'O'.
# q - allow formatting of comments with "gq"
# a - auto formatting for paragraphs
# n - auto wrap numbered lists
#
augroup END
# Always jump to the last known cursor position.
# Don't do it when the position is invalid or when inside
# an event handler (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif # has("autocmd")
设置可以存储在~/中。Vimrc,或在/etc/vimrc.系统范围Local,然后从/etc/vimrc文件中读取:
source /etc/vimrc.local
(为了使它在VIM中工作,您必须将# comment字符替换为“”,我想在这里给出正确的语法高亮显示)。
我在这里列出的命令都是非常基本的,也是到目前为止我使用的主要命令。它们已经让我变得更有效率,而不需要知道所有花哨的东西。