配置文件
- 在home目录下创建 .vimrc 文件
- 然后把下面配置写入
" 基础设置
set nu " 显示行号
set cursorline " 高亮当前行
set cursorcolumn " 高亮当前列
set hlsearch " 高亮搜索结果
set incsearch " 实时搜索
set laststatus=2 " 总是显示状态栏
set nowrap " 不自动换行
set wildmenu " 命令行补全增强
set nocompatible " 禁用 Vi 兼容模式
set tabstop=4 " Tab 宽度为 4
set shiftwidth=4 " 缩进宽度为 4
set expandtab " Tab 转空格
set smarttab " 智能 Tab
set autoindent " 自动缩进
set smartindent " 智能缩进
syntax on " 语法高亮" 前导键(Leader 键)
let mapleader=";" " 将 Leader 键设为分号" 快捷键映射
nmap LB 0 " 跳到行首
nmap LE $ " 跳到行尾
nmap <Leader>q :q<CR> " 关闭当前窗口
nmap <Leader>w :w<CR> " 保存文件
nmap <Leader>Q :qa!<CR> " 强制退出所有窗口" 窗口切换
nnoremap nw <C-W><C-W> " 循环切换窗口
nnoremap <Leader>lw <C-W>l " 切换到右侧窗口
nnoremap <Leader>hw <C-W>h " 切换到左侧窗口
nnoremap <Leader>kw <C-W>k " 切换到上方窗口
nnoremap <Leader>jw <C-W>j " 切换到下方窗口" 自动重新加载配置文件
autocmd BufWritePost $MYVIMRC source $MYVIMRC
" === 鼠标设置 ===
set mouse=a " 全模式支持(不会显示注释文字)
" 新建文件自动模板
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
func SetTitle()if &filetype == 'sh'call setline(1, "#call append(line("."), "# File Name: ".expand("%"))call append(line(".")+1, "# Author: zhangxiaowei")call append(line(".")+2, "# mail: 884377698@qq.com")call append(line(".")+3, "# Created Time: ".strftime("%c"))call append(line(".")+4, "#########################################################################")call append(line(".")+5, "#!/bin/bash")call append(line(".")+6, "")
elsecall setline(1, "/*************************************************************************")call append(line("."), " > File Name: ".expand("%"))call append(line(".")+1, " > Author: zhangxiaowei")call append(line(".")+2, " > Mail: 884377698@qq.com")call append(line(".")+3, " > Created Time: ".strftime("%c"))call append(line(".")+4, " ************************************************************************/")call append(line(".")+5, "")
endifif &filetype == 'cpp'call append(line(".")+8, "")endifif &filetype == 'c'call append(line(".")+7, "")endifautocmd BufNewFile * normal G
endfunc
功能
- 可以鼠标点击后光标跳转到对应的位置
- 创建新文件后,自动加注释到开头
- 自动缩进等