博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Vim学习笔记——定制你的Vim
阅读量:4218 次
发布时间:2019-05-26

本文共 4384 字,大约阅读时间需要 14 分钟。

6.1 vimrc文件

    如果你厌倦了手工键入常用的命令,或者要使你喜好的选项和映射一次性准备好,这时可以统统写入到vimrc(vim run command)的文件里,Vim在启动时会读取这个文件.

    vimrc位置:

    Unix and OS/2:  ~/.vimrc

    Windows      :  $VIM\_vimrc

6.2 vimrc示例文件

 

" An example for a vimrc file.

    " Maintainer:       DaiDai

    " Last change:      2017年6月29日

    " When started as "evim", evim.vim will already have done these settings.

    if v:progname =~? "evim"

      finish

    endif

    " Use Vim settings, rather than Vi settings (much better!).

    " This must be first, because it changes other options as a side effect.

    set nocompatible

    " allow backspacing over everything in insert mode

    set backspace=indent,eol,start

    if has("vms")

      set nobackup              " do not keep a backup file, use versions instead

    else

      set backup                " keep a backup file (restore to previous version)

      set undofile              " keep an undo file (undo changes after closing)

    endif

    set history=50              " keep 50 lines of command line history

    set ruler           " show the cursor position all the time

    set showcmd         " display incomplete commands

    set incsearch               " do incremental searching

 

    " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries

    " let &guioptions = substitute(&guioptions, "t", "", "g")

 

    " Don't use Ex mode, use Q for formatting

    map Q gq

 

    " CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,

    " so that you can undo CTRL-U after inserting a line break.

    inoremap <C-U> <C-G>u<C-U>

 

    " In many terminal emulators the mouse works just fine, thus enable it.

    if has('mouse')

      set mouse=a

    endif

    " Switch syntax highlighting on, when the terminal has colors

    " Also switch on highlighting the last used search pattern.

    if &t_Co > 2 || has("gui_running")

      syntax on

    " 打开语法高亮

      set hlsearch

    endif

 

    " Only do this part when compiled with support for autocommands.

    if has("autocmd")

 

      " Enable file type detection.

      " 'cindent' is on in C files, etc.

      " Also load indent files, to automatically do language-dependent indenting.

 

      " Put these in an autocmd group, so that we can delete them easily.

      augroup vimrcEx

      au!

 

     " For all text files set 'textwidth' to 78 characters.

      autocmd FileType text setlocal textwidth=78

      " When editing a file, 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("'\"") >= 1 && line("'\"") <= line("$") |

        \   exe "normal! g`\"" |

        \ endif

      augroup END

 

    else

 

      set autoindent            " always set autoindenting on

 

    endif " has("autocmd")

 

    " Convenient command to see the difference between the current buffer and the

    " file it was loaded from, thus the changes you made.

    " Only define it when not defined already.

    if !exists(":DiffOrig")

      command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis

                      \ | wincmd p | diffthis

    endif

    if has('langmap') && exists('+langnoremap')

      " Prevent that the langmap option applies to characters that result from a

      " mapping.  If unset (default), this may break plugins (but it's backward

      " compatible).

      set langnoremap

    endif

 

    " Add optional packages.

    "

    " The matchit plugin makes the % command work better, but it is not backwards

    " compatible.

    packadd matchit

 

6.3 简单的映射

    一个映射可以把一连串Vim命令用一个按键来表示.

    如:用一个功能键或字符串,将某个word单词,变成{word},可以使用:map命令.

    :map <F5> i{<Esc>ea}<Esc>

    :map \abc i{<Esc>ea}<Esc>

    {amount}

6.4 选项窗口

    :options命令:在帮助主题中寻找或设置相应的选项.

    " Each "set" line shows the current value of an option (on the left).

    " Hit <CR> on a "set" line to execute it.

    "            A boolean option will be toggled.

    "            For other options you can edit the value before hitting <CR>.

    " Hit <CR> on a help line to open a help window on this option.

    " Hit <CR> on an index line to jump there.

    " Hit <Space> on a "set" line to refresh it.

    :set all命令:查看所有的设置选项.

6.5 常用选项

    :help 'wrap':查看某个选项的帮助.

    :set shiftwidth&:shiftwidth修改为默认值8.

 

    set nowrap:不要折行.

    set sidescroll=10:自动左右滚动10个字符.

    set whichwrap=b,s :跨行移动命令

    set whichwrap=b,s,<,> :跨行移动命令 智能上上下下

    set whichwrap=b,s,<,>,[,] :跨行移动命令 智能上上下下 Insert模式下,也能如此.

    set list  :show <Tab> as ^I and end-of-line as $ 显示特殊字符如Tab或换行符

    set listchars=tab:>-,trail:-,eol:$$  :修改样式

    set iskeyword=@,48-57,_,192-255      :关键字默认字符要求 @:代表所有的字母;48-57 ASCII从48>到57 即0到9;192-225 可以打印的字符;

    set iskeyword+=-  :增加连词符

    set iskeyword-=-  :去掉连词符

        fdafd-fdasfdasfs

    set cmdheight=3 :number of lines used for the command-line 命令行高度.

6.6 使用高亮

    :syntax enable:打开语法支持

    :set filetype=c     :改变当前文件所属类型.

    :set filetype=java  :int boolean

    :set filetype=vim

    :syntax clear  关闭当前高亮.

    :colorscheme evening:打开不同的颜色主题.

转载地址:http://tdxmi.baihongyu.com/

你可能感兴趣的文章
java.util.concurrent详解
查看>>
java事务大总结(一) 先理解数据库的事务以mysql为例
查看>>
java事务大总结(二) 理解JDBC事务的工作机制
查看>>
java事务大总结(三) 理解学习 JTA(Java Transaction API)
查看>>
java事务大总结(四)spring事务相关大总结
查看>>
驴妈妈管理的一点经验总结
查看>>
IOS开发学习的好资料大搜藏
查看>>
SSH的认证终结(无需密码的git操作或者ssh链接无需密码)
查看>>
Jetty 的工作原理以及与 Tomcat 的比较
查看>>
ssh-keygen的使用方法 注意权限问题
查看>>
zookeeper的server的集群配置实例[张振华-Jack]
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第一篇:互联网时代U盘化生存方式 【张振华.Jack】
查看>>
CentOS6.4配置Hadoop-2.6.0集群配置安装指南(经过实战演练)【张振华.Jack】
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第二篇:专注的力量 [张振华.Jack]
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第三篇:我的舍与得的2014[张振华.Jack]
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第五篇:不要给自己找任何借口【张振华.Jack】
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第七篇:请留意我们身边的风景 【张振华.Jack】
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第八篇:坚持的力量 【张振华.Jack】
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第九篇:春节那些事-过年回家不需要理由【张振华.Jack】
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第十一篇:马云乌镇40分钟演讲实录【张振华.Jack】
查看>>