博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
最好用的vimrc(摘自网络)
阅读量:5072 次
发布时间:2019-06-12

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

1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  2 " Maintainer:   3 "       Amir Salihefendic  4 "       http://amix.dk - amix@amix.dk  5 "  6 " Version:   7 "       5.0 - 29/05/12 15:43:36  8 "  9 " Blog_post:  10 "       http://amix.dk/blog/post/19691#The-ultimate-Vim-configuration-on-Github 11 " 12 " Awesome_version: 13 "       Get this config, nice color schemes and lots of plugins! 14 " 15 "       Install the awesome version from: 16 " 17 "           https://github.com/amix/vimrc 18 " 19 " Syntax_highlighted: 20 "       http://amix.dk/vim/vimrc.html 21 " 22 " Raw_version:  23 "       http://amix.dk/vim/vimrc.txt 24 " 25 " Sections: 26 "    -> General 27 "    -> VIM user interface 28 "    -> Colors and Fonts 29 "    -> Files and backups 30 "    -> Text, tab and indent related 31 "    -> Visual mode related 32 "    -> Moving around, tabs and buffers 33 "    -> Status line 34 "    -> Editing mappings 35 "    -> vimgrep searching and cope displaying 36 "    -> Spell checking 37 "    -> Misc 38 "    -> Helper functions 39 " 40 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 41  42  43 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 44 " => General 45 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 46 " Sets how many lines of history VIM has to remember 47 set history=700 48  49 " Enable filetype plugins 50 filetype plugin on 51 filetype indent on 52  53 " Set to auto read when a file is changed from the outside 54 set autoread 55  56 " With a map leader it's possible to do extra key combinations 57 " like 
w saves the current file 58 let mapleader = "," 59 let g:mapleader = "," 60 61 " Fast saving 62 nmap
w :w!
63 64 65 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 66 " => VIM user interface 67 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 68 " Set 7 lines to the cursor - when moving vertically using j/k 69 set so=7 70 71 " Turn on the WiLd menu 72 set wildmenu 73 74 " Ignore compiled files 75 set wildignore=*.o,*~,*.pyc 76 77 "Always show current position 78 set ruler 79 80 " Height of the command bar 81 set cmdheight=2 82 83 " A buffer becomes hidden when it is abandoned 84 set hid 85 86 " Configure backspace so it acts as it should act 87 set backspace=eol,start,indent 88 set whichwrap+=<,>,h,l 89 90 " Ignore case when searching 91 set ignorecase 92 93 " When searching try to be smart about cases 94 set smartcase 95 96 " Highlight search results 97 set hlsearch 98 99 " Makes search act like search in modern browsers100 set incsearch 101 102 " Don't redraw while executing macros (good performance config)103 set lazyredraw 104 105 " For regular expressions turn magic on106 set magic107 108 " Show matching brackets when text indicator is over them109 set showmatch 110 " How many tenths of a second to blink when matching brackets111 set mat=2112 113 " No annoying sound on errors114 set noerrorbells115 set novisualbell116 set t_vb=117 set tm=500118 119 120 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""121 " => Colors and Fonts122 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""123 " Enable syntax highlighting124 syntax enable 125 126 colorscheme desert127 set background=dark128 129 " Set extra options when running in GUI mode130 if has("gui_running")131 set guioptions-=T132 set guioptions+=e133 set t_Co=256134 set guitablabel=%M\ %t135 endif136 137 " Set utf8 as standard encoding and en_US as the standard language138 set encoding=utf8139 140 " Use Unix as the standard file type141 set ffs=unix,dos,mac142 143 144 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""145 " => Files, backups and undo146 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""147 " Turn backup off, since most stuff is in SVN, git et.c anyway...148 set nobackup149 set nowb150 set noswapfile151 152 153 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""154 " => Text, tab and indent related155 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""156 " Use spaces instead of tabs157 set expandtab158 159 " Be smart when using tabs ;)160 set smarttab161 162 " 1 tab == 4 spaces163 set shiftwidth=4164 set tabstop=4165 166 " Linebreak on 500 characters167 set lbr168 set tw=500169 170 set ai "Auto indent171 set si "Smart indent172 set wrap "Wrap lines173 174 175 """"""""""""""""""""""""""""""176 " => Visual mode related177 """"""""""""""""""""""""""""""178 " Visual mode pressing * or # searches for the current selection179 " Super useful! From an idea by Michael Naumann180 vnoremap
* :call VisualSelection('f')
181 vnoremap
# :call VisualSelection('b')
182 183 184 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""185 " => Moving around, tabs, windows and buffers186 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""187 " Treat long lines as break lines (useful when moving around in them)188 map j gj189 map k gk190 191 " Map
to / (search) and Ctrl-
to ? (backwards search)192 map
/193 map
?194 195 " Disable highlight when
is pressed196 map
:noh
197 198 " Smart way to move between windows199 map
j200 map
k201 map
h202 map
l203 204 " Close the current buffer205 map
bd :Bclose
206 207 " Close all the buffers208 map
ba :1,1000 bd!
209 210 " Useful mappings for managing tabs211 map
tn :tabnew
212 map
to :tabonly
213 map
tc :tabclose
214 map
tm :tabmove 215 216 " Opens a new tab with the current buffer's path217 " Super useful when editing files in the same directory218 map
te :tabedit
=expand("%:p:h")
/219 220 " Switch CWD to the directory of the open buffer221 map
cd :cd %:p:h
:pwd
222 223 " Specify the behavior when switching between buffers 224 try225 set switchbuf=useopen,usetab,newtab226 set stal=2227 catch228 endtry229 230 " Return to last edit position when opening files (You want this!)231 autocmd BufReadPost *232 \ if line("'\"") > 0 && line("'\"") <= line("$") |233 \ exe "normal! g`\"" |234 \ endif235 " Remember info about open buffers on close236 set viminfo^=%237 238 239 """"""""""""""""""""""""""""""240 " => Status line241 """"""""""""""""""""""""""""""242 " Always show the status line243 set laststatus=2244 245 " Format the status line246 set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l247 248 249 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""250 " => Editing mappings251 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""252 " Remap VIM 0 to first non-blank character253 map 0 ^254 255 " Move a line of text using ALT+[jk] or Comamnd+[jk] on mac256 nmap
mz:m+
`z257 nmap
mz:m-2
`z258 vmap
:m'>+
`
mzgv`yo`z259 vmap
:m'<-2
`>my`
263 nmap
264 vmap
265 vmap
266 endif267 268 " Delete trailing white space on save, useful for Python and CoffeeScript ;)269 func! DeleteTrailingWS()270 exe "normal mz"271 %s/\s\+$//ge272 exe "normal `z"273 endfunc274 autocmd BufWrite *.py :call DeleteTrailingWS()275 autocmd BufWrite *.coffee :call DeleteTrailingWS()276 277 278 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""279 " => vimgrep searching and cope displaying280 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""281 " When you press gv you vimgrep after the selected text282 vnoremap
gv :call VisualSelection('gv')
283 284 " Open vimgrep and put the cursor in the right position285 map
g :vimgrep // **/*.
286 287 " Vimgreps in the current file288 map
:vimgrep //
%
289 290 " When you press
r you can search and replace the selected text291 vnoremap
r :call VisualSelection('replace')
292 293 " Do :help cope if you are unsure what cope is. It's super useful!294 "295 " When you search with vimgrep, display your results in cope by doing:296 "
cc297 "298 " To go to the next search result do:299 "
n300 "301 " To go to the previous search results do:302 "
p303 "304 map
cc :botright cope
305 map
co ggVGy:tabnew
:set syntax=qf
pgg306 map
n :cn
307 map
p :cp
308 309 310 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""311 " => Spell checking312 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""313 " Pressing ,ss will toggle and untoggle spell checking314 map
ss :setlocal spell!
315 316 " Shortcuts using
317 map
sn ]s318 map
sp [s319 map
sa zg320 map
s? z=321 322 323 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""324 " => Misc325 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""326 " Remove the Windows ^M - when the encodings gets messed up327 noremap
m mmHmt:%s/
//ge
'tzt'm328 329 " Quickly open a buffer for scripbble330 map
q :e ~/buffer
331 332 " Toggle paste mode on and off333 map
pp :setlocal paste!
334 335 336 337 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""338 " => Helper functions339 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""340 function! CmdLine(str)341 exe "menu Foo.Bar :" . a:str342 emenu Foo.Bar343 unmenu Foo344 endfunction 345 346 function! VisualSelection(direction) range347 let l:saved_reg = @"348 execute "normal! vgvy"349 350 let l:pattern = escape(@", '\\/.*$^~[]')351 let l:pattern = substitute(l:pattern, "\n$", "", "")352 353 if a:direction == 'b'354 execute "normal ?" . l:pattern . "^M"355 elseif a:direction == 'gv'356 call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')357 elseif a:direction == 'replace'358 call CmdLine("%s" . '/'. l:pattern . '/')359 elseif a:direction == 'f'360 execute "normal /" . l:pattern . "^M"361 endif362 363 let @/ = l:pattern364 let @" = l:saved_reg365 endfunction366 367 368 " Returns true if paste mode is enabled369 function! HasPaste()370 if &paste371 return 'PASTE MODE '372 en373 return ''374 endfunction375 376 " Don't close window, when deleting a buffer377 command! Bclose call
BufcloseCloseIt()378 function!
BufcloseCloseIt()379 let l:currentBufNum = bufnr("%")380 let l:alternateBufNum = bufnr("#")381 382 if buflisted(l:alternateBufNum)383 buffer #384 else385 bnext386 endif387 388 if bufnr("%") == l:currentBufNum389 new390 endif391 392 if buflisted(l:currentBufNum)393 execute("bdelete! ".l:currentBufNum)394 endif395 endfunction396 397 set t_Co=256398 let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : '', 'sp' : '' }399 colorscheme desert400 set nu

转载于:https://www.cnblogs.com/leealways87/archive/2012/10/04/2711664.html

你可能感兴趣的文章
CMDB学习之七-实现采集错误捕捉,日志信息处理
查看>>
CSS display 属性
查看>>
vue+element-ui 实现分页
查看>>
python基本语法1.4--初识爬虫
查看>>
leetcode weekly contest137
查看>>
Android Studio 添加Assets目录
查看>>
如何理解移动数据和移动计算
查看>>
通过PHP怎样取到android系统下apk应用的包名,版本号等信息
查看>>
Jsp 国际化访问首页选择展示不同字体小例子
查看>>
toString()和toLocaleString()的区别
查看>>
GIT入门笔记(20)- git 开发提交代码过程梳理
查看>>
api-gateway实践(05)新网关工作 - 缓存定义
查看>>
github入门:设置添加ssh key<转>
查看>>
Linux知识积累(4) Linux下chkconfig命令详解
查看>>
括号序列——我那令人智熄的操作
查看>>
Tengine
查看>>
手把手教你用nero(10.5版本)如何刻录系统盘
查看>>
【Android 多媒体应用】使用 MediaPlayer 播放视频
查看>>
整数字符串互换
查看>>
Source object main.o has EABI version 0, but target ../../../bin/ad has EABI version 5
查看>>