前言
- 这是一篇关于
vim的使用教程
快捷键
hjkl:上下左右gg:跳到第一行G:跳到最后一行;/,:快速向后/向前重复ft查找f{char}/t{char}:跳转到本行下一个char字符出现处/出现前F{char}/T{char}:往前搜索而非往后nN:快速重复/查找
进入Insert模式(Normal模式下)
i代表insert,当前光标之前开始输入a代表append,当前光标之后开始输入o下方插入新的一行,当前光标之后开始输入s删除当前光标的字符,然后开始输入I在本行的开头开始输入A在本行的末尾开始输入O上方插入新的一行,然后开始输入S:删除当前行,然后开始输入
进入Comand模式(Normal模式下)
- Normal模式下输入
:进入Command模式
进入Visual模式(Normal模式下)
Normal模式下按v进入可视模式- 进入可视模式后可以用
Noraml模式下的移动命令选择文本 - 可视模式下
x/y剪切/复制;回到Normal模式下p:粘贴
.vimrc基本配置
vim ~/.vimrc "===================" "1.基本设置" "===================" set wildmenu"按TAB键时命令行自动补齐" set ignorecase"忽略大小写" set number "显示行号" set visualbell"禁止响铃" set ruler"显示当前光标位置" set autoread"文件在Vim之外修改过,自动重新读入" set autowrite"设置自动保存内容" set autochdir"当前目录随着被编辑文件的改变而改变" set nocp "使用vim而非vi" set mouse=a"开启鼠标支持" map 9 $"通过9跳转到行末尾,0默认跳转到行首" map <silent> <C-A> gg v G "Ctrl-A 选中所有内容" filetype on "启动文件类型检查" filetype plugin on "运行vim加载文件类型插件" "===================" "2.程序开发相关的设置" "===================" "(1)使用%来选择语句块,然后使用快捷键zf来折叠" set foldmethod=marker "(2)注释:选中文本后,输入;c即可注释,输入;u 即可取消注释" vmap <silent> ;c :s/^/\/\//<CR>:noh<CR> vmap <silent> ;u :s/\/\///<CR>:noh<CR> "(3) 编译和运行程序的快捷键" map <silent> <C-F5> :make %:r <CR>:!./%:r<CR> "Ctrl+F5: 执行makefile文件" map <silent> \rr :!gcc -Wall -g % -lm -o %:r<CR> :!./%:r<CR>"\rr: 编译并运行当前文件的对应程序" map <silent> \rc :!gcc -Wall -g -c % <CR>"\rc:编译当前文件" "(4)源文件和头文件之间快速切换" nmap ,a :find %:t:r. ",a: 切换到任意文件。需要手动输入文件的后缀" nmap ,c :find %:t:r.c<cr> ",c: 切换到同名c语言的源文件" nmap ,C :tabf %:t:r.cpp<cr> ",C: 切换到同名c++的源文件,以tabpage形式打开" nmap ,h :find %:t:r.h<cr>",h 切换到当前文件对于的头文件" "(5)其他" syn on "开启语法高亮功能" set pastetoggle=<F11> "F11来支持切换paste和nopaste状态。" "============" "3. 多窗口操作" "============" map + <C-W>+ "+:扩大窗口" map - <C-W>- "- : 缩小窗口" map <C-l> <C-W>l "C-l 移动到右侧窗口" map <C-h> <C-W>h "C-h 移动到左侧窗口" map <C-j> <C-W>j "C-j 移动到下方窗口" map <C-k> <C-W>k "C-k 移动到上方窗口" "============" "4. tabpages切换" "============" map < :tabpre<CR> map > :tabnex<CR> "=============" "5. 设置缩进" "=============" set cindent "c/c++自动缩进" set smartindent set autoindent"参考上一行的缩进方式进行自动缩进" filetype indent on "根据文件类型进行缩进" set softtabstop=4 "4 character as a tab" set shiftwidth=4 set smarttab "=================" "6. 当前文件内搜索选项" "=================" set hlsearch "开启搜索结果的高亮显示" set incsearch "边输入边搜索(实时搜索)" "==============" "7. 会话功能" "==============" autocmd VimLeave * :mksession! ~/.last.vim "保存当前会话" autocmd VimEnter * :so ~/.last.vim "加载会话" "==========================" "8.不要交换文件和备份文件,减少冲突" "==========================" set noswapfile set nobackup set nowritebackup "=============" "9. 查找和替换文本" "=============" nmap ;s :%s/\<<C-R>=expand("<cword>")<CR>\>/ nmap ;g :vimgrep <C-R>=expand("<cword>")<CR> "========================" " 10.快捷文本输入" "========================" map <silent> \d a<C-R>=strftime("%Y/%m/%d %A")<CR> "快捷输入日期" map <silent> \t a<C-R>=strftime("%Y/%m/%d %H:%M:%S")<CR>"快捷输入时间" map <silent> ,d :split ~/Dropbox/Doc/ <CR> iab --l -------------------- iab ==l ==================== "========================" "11.txt文件按照wiki语法高亮" "========================" autocmd BufNewFile *.txt set ft=confluencewiki autocmd BufEnter *.txt set ft=confluencewiki、1 " An example for a vimrc file. 2 " 3 " Maintainer: Bram Moolenaar <Bram@vim.org> 4 " Last change: 2002 Sep 19 5 " 6 " To use it, copy it to 7 " for Unix and OS/2: ~/.vimrc 8 " for Amiga: s:.vimrc 9 " for MS-DOS and Win32: $VIM\_vimrc1
2
3
4
5
6
7
8
9
* `vim-plug`插件的使用
* `https://zhuanlan.zhihu.com/p/657039661`
* `vim`常用插件
### 公司`vim`配置
10 “ for OpenVMS: sys$login:.vimrc
11
12 “ When started as “evim”, evim.vim will already have done these settings.
13
14 if v:progname =~? “evim”
15 finish
16 endif
17
18 set nu “ always set line number on
19
20 set ic
21
22 set fileencodings=utf-8,ucs-bom,chinese
23 set termencoding=utf-8
24 set encoding=utf-8
25
26 “set encoding=utf-8
27 “set fileencoding=utf-8
28
29 “ Use Vim settings, rather then Vi settings (much better!).
30 “ This must be first, because it changes other options as a side effect.
31 set nocompatible
32
33 “ allow backspacing over everything in insert mode
34 set backspace=indent,eol,start
35
36 “if has(“vms”)
37 “ set nobackup “ do not keep a backup file, use versions instead
38 “else
39 “ set backup “ keep a backup file
40 “endif
41 set history=50 “ keep 50 lines of command line history
42 set ruler “ show the cursor position all the time
43 set showcmd “ display incomplete commands
44 set incsearch “ do incremental searching
45
46 “ For Win32 GUI: remove ‘t’ flag from ‘guioptions’: no tearoff menu entries
47 “ let &guioptions = substitute(&guioptions, “t”, “”, “g”)
48
49 “ Don’t use Ex mode, use Q for formatting
50 map Q gq
51
52 “ This is an alternative that also works in block mode, but the deleted
53 “ text is lost and it only works for putting the current register.
54 “vnoremap p “_dp
55
56 “ Switch syntax highlighting on, when the terminal has colors
57 “ Also switch on highlighting the last used search pattern.
58 syntax on
59 if &t_Co > 2 || has(“gui_running”)
60 syntax on
61 set hlsearch
62 endif
63
64 “ Only do this part when compiled with support for autocommands.
65 if has(“autocmd”)
66
67 “ Enable file type detection.
68 “ Use the default filetype settings, so that mail gets ‘tw’ set to 72,
69 “ ‘cindent’ is on in C files, etc.
70 “ Also load indent files, to automatically do language-dependent indenting.
71 filetype plugin indent on
72
73 “ Put these in an autocmd group, so that we can delete them easily.
74 augroup vimrcEx
75 au!
76
77 “ For all text files set ‘textwidth’ to 78 characters.
78 autocmd FileType text setlocal textwidth=78
79
80 “ When editing a file, always jump to the last known cursor position.
81 “ Don’t do it when the position is invalid or when inside an event handler
82 “ (happens when dropping a file on gvim).
83 autocmd BufReadPost *
84 \ if line(“‘"“) > 0 && line(“‘"“) <= line(“$”) |
85 \ exe “normal g\"" | 86 \ endif 87 88 augroup END 89 90 else 91 92 set autoindent " always set autoindenting on 93 set nu " always set number on 94 95 endif " has("autocmd") 96 set ts=8 97 command Date r !date "+\%y \%m \%d \%H:\%M:\%s" 98 99 map L gt 100 map H gT 101 command -nargs=1 -complete=file T tabedit <args> 102 103 hi TabLine term=bold,reverse cterm=bold ctermfg=lightblue ctermbg=white gui=bold guifg=blue guibg=white 104 set guifont=fixedsys:h15:cGB2312 105 106 "maximum the initial window ×î´ó»¯´°¿Ú 107 au GUIEnter * simalt ~x 108 109 hi WZCursor guifg=bg guibg=red 110 set guicursor=n-v-c:ver100-WZCursor/lCursor 111 set complete=.,w,b,u,t 112 set autochdir 113 set nobackup 114 115 autocmd BufRead *.as set filetype=actionscript 116 set autoindent 117 118 "vimGrep 119 nnoremap <silent> f :Rgrep<CR> 120 let Grep_Default_Filelist = '*.lua *.c *.cpp *.h *.xml *.py *.hpp *.log *.tbl *.pto *.dat *.php *.json' 121 map f :Rgrep \b<cword>\b<CR> 122 123 "nerd tree 124 let NERDChristmasTree=1 125 "let NERDTreeAutoCenter=1 126 "let NERDTreeBookmarksFile=$VIM.'\Data\NerdBookmarks.txt' 127 let NERDTreeHightCursorline=1 128 let NERDTreeMouseMode=2 129 let NERDTreeShowBookmarks=1 130 let NERDTreeShowFiles=1 131 let NERDTreeShowHidden=1 132 let NERDTreeShowLineNumbers=1 133 let NERDTreeWinPos='left' 134 let NERDTreeWinSize=31 135 let NERDTreeIgnore=['\.swp', '\.o','\.d','\.pyc'] 136 map :NERDTreeToggle