vim 笔记

来源:互联网 发布:java handler是什么 编辑:程序博客网 时间:2024/06/06 19:54

命令模式:

<C-R> 

CTRL-U 表示光标到首行,U=UP,向上滚动N行,默认是半个屏幕

CTRL-D 表示光标到尾行,D=DOWN,向下滚动N行,默认是半个屏幕

CTRL-E 表示向下滚动一行

CTRL-F 表示向下滚动一个屏幕

CTRL-G 表示显示当前文件名称,和行数,以及浏览百分几

CTRL-L 重绘屏幕

CTRL-M  CTRL-N等于光标插入到下一行的行首

CTRL-P 等于光标插入到上一行的行首

CTRL-R 重做u撤销的改变(恢复)

CTRL-^  数字切换第几个文件编辑

'(按两下单冒号) 自动跳转上次光标所在的行首

'{              光标移动到当前段落的首部所在行的第一个 CHAR

'}              光标移动到当前段落的尾部所在行的第一个 CHAR

(               光标回退 N 个句子
)               光标前进 N 个句子

* 高亮当前光标所在单词,重复按下会向下查找下一个匹配的词,与#对应

+ 等于回车

- 当前行的光标移动到上一行的行首

/内容 搜索内容

/回车 根据上次的搜索进行下一次的搜索

数字: 数字+冒号会在命令行显示当前行,当前行+数字-1的一个命令前缀,比如3:就会显示.,.+2,.(点)表示显示当前行

<数字 左移多少个TAB

>数字 右移多少个TAB

W 向前移动一个单词,移动到单词的起始位置

E 向前移动一个单词,移动到单词的结束位置

gg 移动到行首

# 会高亮当前光标的单词的操作!重复操作,会循环自动向上查找下一个匹配的词!

fa 先按下f键盘,然后再按下需要查找的内容,fa表示查找与光标最近的内容a,查找到光标自动跳转到a的字符上

dt+字符 删除光标与字符串之间的内容

g_ 按下g然后再shift-(+号旁边的键盘)可以将光标移动到当前行的末尾,末尾的空字符不包含上,移动到末尾非空字符串!

cw 当前单词光标后的所有字符都会给删除,并且进入INSERT模式

y $输入y之后再输入美元符号$,复制当前行起始的单词到当前行的最后一个单词,包含了行末的所有空格

y g_ 输入y之后再输入g和_ 复制当前行起始的单词到当前行的最后一个单词,行末的空格

ye 拷贝当前光标后的一个单词

gU 将当前的行所有字符都变大写,亲身试用的时候需要重复按两次才生效!

gu 将当前的行所有字符都变小写,亲身试用的时候需要重复按两次才生效!

t字符 按下t然后按别的字符,把光标移动到该字符前,比如ta,表示移动到a的字符前,T向后移动到该字符前

gd 高亮所有当前光标下的单词

输入:(冒号)这类型的命令

% 在当前行查找下一行的{ 或者 }

nohl 取消高亮显示

?搜索内容 进行反向搜索,搜索的顺序从后面搜到的显示

?立刻 回车表示搜索继续搜索上一次反向搜索的内容

@:执行上一次的命令

``(TAB 键盘上的~)移动到光标上一次执行的位置

`{移动到段落的起始处

`}移动到段落的结束处

b反向移动一个单词和E对应

q{0-9a-zA-Z"}记录输入的字符到寄存器0-9a-zA-Z"中

(大写Q用于添加)

q: 查询:(冒号)输入过的命令和执行

q/ 查询/(反斜杠)输入过的命令和执行

q? 查询?(问好)输入过的命令和执行

r 替换字符

s 删除字符并且进入插入模式

v 进入可视模式

w 光标递进到下一个单词

x 删除字符

yy 复制一行

{ 光标移动到段落起始

} 光标移动到段落的结束

~ 光标递增移动,并且遇到的字符都转换为大写

G 大写G按键,直接到文档末尾

gg 直接到文档头部

!! 执行上一次的命令

6,9 co 12 表示复制6到9行的数据到第12的下面也就是13行

ma mbmc表示光标移动到mark点a,mark点b,mark点c,然后再命令行'a,'b m 'c就可以多行复制了

go+数字 光标会移动多少个数字,起始点从第一个字符开始算!

编辑模式(INSERT):

CTRL-E 插入当前光标下方的字符

CTRL-H 等于退格键的作用

CTRL-J 等于回车换行的作用

CTRL-M 等于回车换行的作用

CTRL-W 删除当前光标的单词

CTRL-[ 等同Esc

CTRL-D 删除当前缩进行(在行首按了TAB键,此时你按住CTRL-D就会把TAB键盘的内容删了)


CTRL-X CTRL-E  按下CTRL-X 后然后接着按 CTRL-E 会进行向上滚动一行的操作

CTRL-X CTRL-Y 按下CTRL-X 后然后接着按CTRL-Y会进行向下滚动一行的操作

CTRL-X CTRL-F  按下CTRL-X 后然后接着按CTRL-F 会以一个下拉框列出当前的文件列表

CTRL-X CTRL-P 按下CTRL-X 后然后接着按CTRL-P会自动补全字符(上一个,P=Prefore),例如:你的文本内容包含了hello,你敲h之后CTRL-X 接着CTRL-P就会在h变hello!

如果存在多个补全的,会以下啦列表显示,让你选择!

CTRL-X CTRL-P 按下CTRL-X 后然后接着按CTRL-N会自动补全字符(下一个,N=Next),例如:你的文本内容包含了hello,你敲h之后CTRL-X 接着CTRL-P就会在h变hello!

如果存在多个补全的,会以下啦列表显示,让你选择!

CTRL-X CTRL-V  按下CTRL-X后然后接着CTRL-V 会列出常规需要的字符,会以一个下拉列表显示!

窗口命令

CTRL+W - 缩小窗口字体
CTRL+W + 放大窗口字体
CTRL+W h 分割窗体向左边窗体跳转
CTRL+W i 分割窗体
CTRL+W j 分割窗体后向下的窗体跳转
CTRL+W l 分割窗体后向右边窗体跳转
CTRL+W k 分割窗体后向上的窗体跳转
CTRL+W n 打开新窗体
CTRL+W o 关闭除了当前窗口以外的所有窗体
CTRL+W p 转到前面一个窗口
CTRL+W q 退出当前窗口
CTRL+W r 光标向下跳到窗口
CTRL+W v 将当前窗口垂直分割
CTRL+W w 来回切换窗口,类似windows的alt+tab键,切换
CTRL+W x 交换当前窗口和下一个窗口


vim 日常使用记录:
我们经常看到.vimrc 文件存在一些命令包含了                                       
<leader> 这些关键字,这个是引导键的意思,刚开始我也不知道是什么意思,最后才弄懂了,
在vim 命令行中输入:help <Leader>,我们可以看到如下帮助信息:
 <Leader> mapleader
To define a mapping which uses the "mapleader" variable, the special string"<Leader>" can be used.  It is replaced with the string value of "mapleader".If "mapleader" is not set or empty, a backslash is used instead.  
定义一个"mapleader"变量的映射,那么这个特殊的字符串<Leader>可以被使用!他可以替换"mapleader"这个字符串,如果"mapleader"没有设置或者空,默认是反斜杠\!
Example(示例):
        :map <Leader>A  oanother line<Esc>
Works like(上面的示例是这样工作的):
        :map \A  oanother line<Esc> 按下\A 则会出现新的一行
But after:
        :let mapleader = ","
It works like: 
        :map ,A  oanother line<Esc>

我的vim配置
" #####vundle Configureau VimEnter * NERDTreeset nuset nocompatiblefiletype offset rtp+=~/.vim/bundle/vundle/call vundle#rc()Bundle 'Valloric/YouCompleteMe'Bundle 'scrooloose/syntastic'Bundle 'The-NERD-tree'Bundle 'The-NERD-Commenter'Bundle 'jistr/vim-nerdtree-tabs'Bundle 'tpope/vim-abolish'Bundle 'SirVer/ultisnips' Bundle 'honza/vim-snippets'Bundle 'vim-scripts/taglist.vim'Bundle 'kien/ctrlp.vim'"Bundle 'tpope/vim-surround'Bundle 'Raimondi/delimitMate'" #####vundle COnfigure" #####vim Configurefiletype plugin indent onsyntax onset tabstop=3set softtabstop=3set shiftwidth=3set autoindentset cindentset cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s"colorscheme solarized"colorscheme asmanian2set guifont=Courier_New:h10:cANSIautocmd InsertLeave * se culautocmd InsertEnter * se culset showcmdset laststatus=2set foldenableif version >= 603<span style="white-space:pre"></span>set helplang=cnendifset fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936set termencoding=utf-8set encoding=utf-8set fileencodings=ucs-bom,utf-8,cp936set fileencoding=utf-8autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java,*.js,*.php,*.html,*.htm exec ":call SetTitle()"func SetTitle()<span style="white-space:pre"></span>if &filetype == 'sh'<span style="white-space:pre"></span>call setline(1,"\############################################")<span style="white-space:pre"></span>call append(line("."),"\# File Name:".expand("%"))<span style="white-space:pre"></span>call append(line(".")+1,"\# Author:YourName")<span style="white-space:pre"></span>call append(line(".")+2,"\# Email:YourEmail")<span style="white-space:pre"></span>call append(line(".")+3,"\# Create Time:".strftime("%Y-%m-%d",localtime()))<span style="white-space:pre"></span>call append(line(".")+4,"\###################################")<span style="white-space:pre"></span>call append(line(".")+5,"\#!/bin/bash")<span style="white-space:pre"></span>call append(line(".")+6,"")<span style="white-space:pre"></span>else<span style="white-space:pre"></span>call setline(1,"/********************************************")<span style="white-space:pre"></span>call append(line("."),"<span style="white-space:pre"></span>> File Name:".expand("%"))<span style="white-space:pre"></span>call append(line(".")+1,"<span style="white-space:pre"></span>> Author:YourName")<span style="white-space:pre"></span>call append(line(".")+2,"<span style="white-space:pre"></span>> Email:YourEmail")<span style="white-space:pre"></span>call append(line(".")+3,"<span style="white-space:pre"></span>> Created Time:".strftime("%Y-%m-%d",localtime()))<span style="white-space:pre"></span>call append(line(".")+4,"**************************************/")<span style="white-space:pre"></span>call append(line(".")+5,"")<span style="white-space:pre"></span>endif<span style="white-space:pre"></span>if &filetype == 'cpp'<span style="white-space:pre"></span>call append(line(".")+6,"#include <iostream>")<span style="white-space:pre"></span>call append(line(".")+7,"using namespace std;")<span style="white-space:pre"></span>call append(line(".")+8,"")<span style="white-space:pre"></span>endif<span style="white-space:pre"></span>if &filetype == 'c' <span style="white-space:pre"></span>call append(line(".")+6,"#include <stdio.h>")<span style="white-space:pre"></span>call append(line(".")+7,"")<span style="white-space:pre"></span>endif<span style="white-space:pre"></span>autocmd BufNewFile * normal G<span style="white-space:pre"></span>endfunc<span style="white-space:pre"></span>map <C-c> ymap <C-x> dmap <C-A> <Esc>ggVG"map <C-w> :w!<CR>nmap <tab> V>nmap <s-tab> V<vmap <tab> V>vmap <s-tab> V>set cursorlineset noexpandtabset mouse=aset selection=exclusiveset selectmode=mouse,keyset smartindentau BufRead,BufNewFile * setfiletyp txt:inoremap ( ()<ESC>i:inoremap { {}<ESC>i:inoremap [ []<ESC>i:inoremap ' ''<ESC>i:inoremap " ""<ESC>i:inoremap < <><ESC>i":inoremap > <c-r>=ClosePair( '> ')<CR>"function! ClosePair(char)"<span style="white-space:pre"></span>if getline('. ')[col('. ')-1] == a:char"<span style="white-space:pre"></span>return "\<Right>""<span style="white-space:pre"></span>else"<span style="white-space:pre"></span>return a:char"<span style="white-space:pre"></span>endif"endfunction" #####vim Configure" #####YouCompleteMe Configure let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'" 自动补全配置set completeopt=longest,menu<span style="white-space:pre"></span>"让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)autocmd InsertLeave * if pumvisible() == 0|pclose|endif<span style="white-space:pre"></span>"离开插入模式后自动关闭预览窗口inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"<span style="white-space:pre"></span>"回车即选中当前项"上下左右键的行为 会显示其他信息inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"inoremap <expr> <Up>       pumvisible() ? "\<C-p>" : "\<Up>"inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"inoremap <expr> <PageUp>   pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>""youcompleteme  默认tab  s-tab 和自动补全冲突"let g:ycm_key_list_select_completion=['<c-n>']let g:ycm_key_list_select_completion = ['<Down>']"let g:ycm_key_list_previous_completion=['<c-p>']let g:ycm_key_list_previous_completion = ['<Up>']let g:ycm_confirm_extra_conf=0 "关闭加载.ycm_extra_conf.py提示let g:ycm_collect_identifiers_from_tags_files=1<span style="white-space:pre"></span>" 开启 YCM 基于标签引擎let g:ycm_min_num_of_chars_for_completion=1<span style="white-space:pre"></span>" 从第2个键入字符就开始罗列匹配项let g:ycm_cache_omnifunc=0<span style="white-space:pre"></span>" 禁止缓存匹配项,每次都重新生成匹配项let g:ycm_seed_identifiers_with_syntax=1<span style="white-space:pre"></span>" 语法关键字补全nnoremap <F5> :YcmForceCompileAndDiagnostics<CR><span style="white-space:pre"></span>"force recomile with syntastic"nnoremap <leader>lo :lopen<CR><span style="white-space:pre"></span>"open locationlist"nnoremap <leader>lc :lclose<CR><span style="white-space:pre"></span>"close locationlistinoremap <leader><leader> <C-x><C-o>"在注释输入中也能补全let g:ycm_complete_in_comments = 1"在字符串输入中也能补全let g:ycm_complete_in_strings = 1"注释和字符串中的文字也会被收入补全let g:ycm_collect_identifiers_from_comments_and_strings = 0let g:clang_user_options='|| exit 0'nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳转到定义处let g:ycm_semantic_triggers={}let g:ycm_semantic_triggers.c=['->','.',' ','(','[','&']" #####YouCompleteMe Configure " ####syntastic let g:syntastic_error_symbol='✗'let g:syntastic_warning_symbol='⚠'let g:syntastic_check_on_open=1let g:syntastic_check_on_wq=0let g:syntastic_enable_highlighting=1let g:syntastic_python_checkers=['pyflakes'] " 使用pyflakes,速度比pylint快let g:syntastic_javascript_checkers = ['jsl', 'jshint']let g:syntastic_html_checkers=['tidy', 'jshint']let g:syntastic_cpp_include_dirs=['/usr/include/']let g:syntastic_cpp_remove_include_errors=1let g:syntastic_cpp_check_header=1let g:syntastic_cpp_compiler='clang++'let g:syntastic_cpp_compiler_options='-std=c++11 -stdlib=libstdc++'let g:syntastic_enable_ballons=1" 修改高亮的背景色, 适应主题highlight SyntasticErrorSign guifg=white guibg=black" to see error location listlet g:syntastic_always_populate_loc_list = 0let g:syntastic_auto_loc_list = 0let g:syntastic_loc_list_height = 5function! ToggleErrors()    let old_last_winnr = winnr('$')        lclose            if old_last_winnr == winnr('$')                    " Nothing was closed, open syntastic error location                    panel                            Errors                                endifendfunction" ####syntastic" ####NERDTree "let g:NERDTreeShowLineNumbers=1let g:NERDTreeQuitOnOpen = 0" ####NERDTree   "  " ####NERDTree tabs "  "let g:nerdtree_tabs_smart_startup_focus =2  let g:nerdtree_tabs_open_on_console_startup =1 " ####NERDTree tabs    " ####neocomplcache" "source neocomplcache.conf " ####neocomplcache" " #####ultisnips" let g:UltiSnipsExpandTrigger="<tab>" let g:UltiSnipsJumpForwardTrigger="<c-b>" let g:UltiSnipsJumpBackwardTrigger="<c-z>" " If you want :UltiSnipsEdit to split your window. let g:UltiSnipsEditSplit="vertical" " #####ultisnips" " #####ctag list " let Tlist_Ctags_Cmd='/usr/bin/ctags' let Tlist_ShowOne_File=1 let Tlist_Exit_OnlyWIndow=1 let Tlist_Use_Right_Window=1 let Tlist_GainFocus_On_ToggleOpen=1 let Tlist_Auto_Open=1 let Tlist_Process_File_Always=1 map <silent> <F9> :TlistToggle<cr> " #####ctag list " " #####ctrlP "        " #####ctrlP filetype plugin indent on



0 0
原创粉丝点击