Linux环境下的vim编辑器默认功能不够强大,如果要进行Shell脚本的开发,还需要进行适当的设置,从而达到高效开发的目的。vim编辑器有一个可以用来调整配置的配置文件,默认放置在用户家目录下,全路径及名字组合为:〜/.vimrc (全局路径为/etc/vimrc),这是一个隐藏文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
[root@lb01 ~]# vim /etc/vimrc set nocompatible set history=100 filetype on filetype plugin on filetype indent on set autoread hi cursorline guibg=#00ff00 hi CursorColumn guibg=#00ff00 set nofen set fdl=0 set expandtab set tabstop=4 set shiftwidth=4 set softtabstop=4 set smarttab set ai set si set wrap set sw=4 set wildmenu set cmdheight=1 set lz set backspace=eol,start,indent set whichwrap+=<,>,h,l set magic set noerrorbells set novisualbell set showmatch set mat=2 set hlsearch set ignorecase set encoding=utf-8 set fileencodings=utf-8 set termencoding=utf-8 set smartindent set cin set showmatch set guioptions-=T set guioptions-=m set vb t_vb= set laststatus=2 set pastetoggle=<F9> set background=dark highlight Search ctermbg=black ctermfg=white guifg=white guibg=black autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()" function SetTitle() if expand("%:e") == 'sh' call setline(1, "#!/usr/bin/env bash") call setline(2, "#Author:xiaolang") call setline(3, "#Blog:https://www.cnblogs.com/xiaolang666") call setline(4, "#Time:".strftime("%F %T")) call setline(5, "#Name:".expand("%")) call setline(6, "#Version:VI.0") call setline(7, "#Discription:To " ) endif endfunction |
详解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
#关闭兼容模式 set nocompatible #设置历史记录步数 set history=100 #开启相关插件 filetype on filetype plugin on filetype indent on "当文件在外部被修改时,自动更新该文件" set autoread "激活鼠标的使用" set mouse=a "字体和颜色开启语法" syntax enable "设置字体" set guifont=dejaVu\ Sans\ MONOX 10 "设置配色" colorscheme desert "高亮显示当前行" set cursorline hi cursorline guibg=#00ff00 hi CursorColumn guibg=#00ff00 "=>代码折叠功能by oldboy-激活折叠功能" set foldenable "设置按照语法方式折叠(可简写set fdm=XX)" "有6种折叠方法:" " manual 手工定义折叠 indent 更多的缩进表示更高级别的折叠 expr 用表达式来定义折叠 syntax 用语法高亮来定义折叠 diff 对没有更改的文本进行折叠 marker 对文中的标志进行折叠" set foldmethod=manual "设置折叠区域的宽度 如果不为0,则在屏幕左侧显示一个折叠标识列 分别用和“ + ”来表示打开和关闭的折叠。" set foldcolumn=0 "设置折叠层数为3" setlocal foldlevel=3 "设置为自动关闭折叠" set foldclose=all "用空格键来代替ZO和ZC快捷键实现开关折叠" ZO O-pen a fold (打开折叠) ZC C-lose a fold (关闭折叠) zf F-old creation (创建折叠) nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' "使用空格来替换Tab" set expandtab 设置所有的Tab和缩进为4个空格 set tabstop=4 "设定 << 和 >> 命令移动时的宽度为4" set shiftwidth=4 "使得按退棺键时可以一次删掉4个空格" set softtabstop=4 set smarttab "缩进,自动缩进(继承前一行的缩进)" set autoindent命令关闭自动缩进,是下面配置的缩写。 "可使用 autoindent 命令的简写,即 “:set ai” 和 “:set noai”。" "还可以使用:set ai sw=4”在一个命令中打开缩进并设置缩进级别。" set ai "智能缩进" set si "自动换行" set wrap "设置软宽度" set sw=4 "=> Vim 界面 by oldboy" Turn on WiLd menu set wildmenu "显示标尺" set ruler "设置命令行的高度" set cmdheight=l "显示行数" set nu "Do not redraw, when running macros.. lazyredraw" set lz "设置退格" set backspace=eol,start,indent "Bbackspace and cursor keys wrap to" set whichwrap+=<,>,h,1 Set magic on (设置魔术) set magic "关闭遇到错误时的声音提示 关闭错误信息响铃" set noerrorbells "关闭使用可视响铃代替呼叫" set novisualbell "显示匹配的括号(U和}])" set showmatch "How many tenths of a second to blink" set mat=2 '搜索时高亮显示搜索到的内容' set hlsearch "搜索时不区分大小写" "还可以使用简写(“:set ic”和“:set noic”)" set ignorecase "=>编码设置,设置编码" set encoding=utf-8 "设置文件编码" set fileencodings=utf-8 "设置终端编码" set termencoding=utf-8 "=> 其他设置 by oldboy 2010" "开启新行时使用智能自动缩进" set smartindent set cin set showmatch "隐藏工具栏" set guioptions-=T "隐藏菜单栏" set guioptions-=m "置空错误铃声的终端代码" set vb t_vb= "显示状态栏(默认值为1,表示无法显示状态栏)" set laststatus=2 "粘贴不换行问题的解决方法" set pastetoggle=<F9> "设置背景色" set background=dark "设置高亮相关" highlight Search ctermbg=black ctermfg=white guifg=white guibg=black "在Shell脚本的开头自动增加解释器及作者等版权信息" autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()" func SetTitle() if expan ("%:e") == 'sh' call setline(1, "#!/bin/bash") call setline(2, "#Author:ANY") call setline(3, "#Blog: http://") call setline(4, "#Time:".strftime("%F %T")) call setline(5, "#Name:".expand("%")) call setline(6, "#Version:VI.0") call setline(7, "#Description:This is a test script.") endif endfuunc |