vim配置方案

警告
本文最后更新于 2022-12-18 11:18,文中内容可能已过时。

效果

16136-rtytmf4ycw.png
16136-rtytmf4ycw.png

  1. 下载配色
1
2
mkdir $HOME/.vim/colors
wget https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim -O $HOME/.vim/colors/molokai.vim

2.修改vimrc

1
wget https://raw.githubusercontent.com/SoulChildTc/SoulChildTc/main/Individuation/.vimrc -O ~/.vimrc

or

vim $HOME/.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
 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
" "set history=500
" 光标列高亮
set cursorcolumn
" display numbers
set nu
"visual edit everywhere
""set virtualedit=all

"show command
set showcmd
set cmdheight=2
set scrolloff=3

" Enable filetype plugins
filetype plugin on
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread

set nocompatible

" Search
set ignorecase    " Ignore case when searching
set smartcase     " When searching try to be smart about cases
set hlsearch      " Highlight search results
set incsearch     " Makes search act like search in modern browsers

" Don't redraw while executing macros (good performance config)
set lazyredraw


" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2

" No annoying sound on errors
set noerrorbells
"set novisualbell
set t_vb=
set tm=500

" Add a bit extra margin to the left
" set foldcolumn=1
" set fdm=marker

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax enable

colorscheme molokai
"colorscheme monokai
"colorscheme murphy
"colorscheme solarized
"let g:solarized_termcolors=256
"let g:solarized_contrast="high"    "default value is normal
set t_Co=256      "set vim terminal color
set background=dark
"set guifont=Mono\ 13
set guifont=monaco\ 14


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Statusline setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set statusline=%1*\ [%{Disp_Mode()}]\ %*\ %-5.58(%F%m%r%h%w%)\ %2*\ %-5.58(CWD:\ %{getcwd()}%)\ %*\ Format:\ [%{&fenc!=''?&fenc:&enc}]\ %3*\ FileType:\ %y\ %*\ %([L:\ %l,C:\ %c][%p%%]%)%<
hi User1 guibg=slateblue guifg=Gray ctermfg=Gray ctermbg=93
hi User2 guibg=#4876FF guifg=Gray ctermfg=Gray ctermbg=53
hi User3 guibg=Brown guifg=Gray ctermfg=Gray ctermbg=160
hi StatusLine guibg=#cccccc guifg=#222222
set laststatus=2  "2:always display

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => file coding and decoding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set utf8 as standard encoding and en_US as the standard language
set termencoding=utf-8
set encoding=utf8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,latin1     "decoding list
set fileencoding=utf-8


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 1 tab == 4 spaces
set shiftwidth=4
" tab 的宽度
set tabstop=4

set softtabstop=1
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs
" set smarttab

"toggle paste mode with hitting F2 key
set pastetoggle=<F2>
set paste    "open paste mode

set ai "Auto indent
set si "Smart indent
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Wrap and breakline setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Linebreak on 500 characters
set lbr                 "linebreak
set tw=500              "break at 500 words
set showbreak==>\          "show "=>" before the break line
set wrap "Wrap lines

"configure backspace
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

" Highlight the current line
set cursorline
"highlight CursorLine          guibg=#003853 ctermbg=24  gui=none cterm=none

"set clipboard=unnamed    "yank unnamed register to the system register

" Return to last edit position when opening files (You want this!)  
autocmd! BufReadPost *  
     \ if line("'\"") > 0 && line("'\"") <= line("$") |  
     \   exe "normal! g`\"" |  
     \ endif

"auto load ~/.vimrc
autocmd! BufWritePost $MYVIMRC source $MYVIMRC

"let mapleader = ','
let g:mapleader = ','

""""""""""""""""""""""""""""""""""""""
"save and quit
""""""""""""""""""""""""""""""""""""""
"quit without save
map <leader>q :q!<cr>    
"save and quit
map <leader>w :wq!<cr>    
"save force with :W
"command! W w !sudo tee % > /dev/null

""""""""""""""""""""""""""""""""""""""
"save and quit
""""""""""""""""""""""""""""""""""""""
map <leader>tn :tabnew<cr>
map <leader>tc :tabclose<cr>
map <C-tab> :tabn<cr>
map <C-S-tab> :tabp<cr>

" no highlight
map <leader>/ :nohl<cr>

" Merge selected text into one line
vmap <leader>m J

" change all the tab into space
nmap <leader>rt :retab!<cr>

" update when diff two files
nmap <leader>du :diffupdate<cr>


""""""""""""""""""""""""""""""""""""""
"auto complete (),[],{}and so on
""""""""""""""""""""""""""""""""""""""  
:inoremap ( ()<Left>
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<Left>
autocmd FileType c,cpp :inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<Left>
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<Left>
"autocmd Filetype c,cpp,python,perl :inoremap ' ''<ESC>i
function! ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endfunction

""""""""""""""""""""""""""""""""""""""
"自动插入文件头
""""""""""""""""""""""""""""""""""""""
autocmd! BufNewFile * silent! 0r ~/.vim/skel/Template.%:e
autocmd! BufNewFile *.cpp,*.[ch],*.sh,*.java,*.v,*.sv,*.vhd,*.py exec ":call SetTitle()"
function! SetTitle()
    "如果文件类型为脚本文件
    if &filetype =~ 'sh\|perl\|python'
        if &filetype == 'sh'
            call setline(1,"#!/bin/bash")
        elseif &filetype == 'perl'
            call setline(1,"#!/usr/bin/perl -w")
        elseif &filetype == 'python'
            call setline(1,"#!/usr/bin/env python")
        endif
        call append(line("."), "")
    elseif &filetype =~ 'verilog\|systemverilog\|c\|cpp'
        call setline(1          , "\//------------------------------------------------------------------------")
        call append(line(".")   , "\// File Name   : ".expand("%"))
        call append(line(".")+1 , "\// Author      : xxxxx (xxxxx@163.com)")
        call append(line(".")+2 , "\// Version     : V0.1 ")
        call append(line(".")+3 , "\//------------------------------------------------------------------------")
        call append(line(".")+4 , "\// Description :" )
        call append(line(".")+5 , "\//     " )
        call append(line(".")+6 , "\//------------------------------------------------------------------------")
        call append(line(".")+7 , "\// Revision History:" )
        call append(line(".")+8 , "\// *Version* | *Modifier* | *Modified Date* | *Description*")
        call append(line(".")+9 , "\//   V0.1    |   Victor   |   ".strftime("%Y-%m-%d")."    | Fisrt Created.")
        call append(line(".")+10, "\//------------------------------------------------------------------------")        
        call append(line(".")+11, "" )
    endif
    if &filetype == 'cpp'
        call append(line(".")+12, "#include<iostream>")
        call append(line(".")+13, "using namespace std;")
        call append(line(".")+14, "")
    endif
    if &filetype == 'c'
        call append(line(".")+12, "#include<stdio.h>")
        call append(line(".")+13, "")
    endif
    if &filetype =~ 'verilog\|systemverilog'
        if expand("%:r") =~ 'tb$'
            call append(line(".")+12, "`timescale 1ns/1ps")
            call append(line(".")+13, "")
            call append(line(".")+14, "module ".expand("%:r")."();")
            call append(line(".")+15, "")
            call append(line(".")+16, "initial begin")
            call append(line(".")+17, "    $fsdbDumpfile(\"wave.fsdb\");")
            call append(line(".")+18, "    $fsdbDumpvars(0);")
            call append(line(".")+19, "\//    $fsdbDumpMDA(0);")
            call append(line(".")+20, "end")
            call append(line(".")+21, "")
            call append(line(".")+22, "endmodule")
        else
            call append(line(".")+12, "module ".expand("%:r")."(")
            call append(line(".")+13, "    input clk   ,")
            call append(line(".")+14, "    input rst_n ,")
            call append(line(".")+15, ");")
            call append(line(".")+16, "")
            call append(line(".")+17, "\//==============================================")
            call append(line(".")+18, "\// Definition of regs and wires")
            call append(line(".")+19, "\//==============================================")
            call append(line(".")+20, "")
            call append(line(".")+21, "\//**********************************************")
            call append(line(".")+22, "\// Function")
            call append(line(".")+23, "\//**********************************************")
            call append(line(".")+24, "")
            call append(line(".")+25, "endmodule")
        endif
    endif
    "新建文件后,自动定位到文件末尾
    exec "normal G"
endfunc

"""""""""""""""""""""""""""""""""""""""""
""实现上面函数中的,Last Modified功能
"""""""""""""""""""""""""""""""""""""""""
"autocmd! BufWrite,BufWritePre,FileWritePre  *.cpp,*.[ch],*.sh,*.java,*.v,*.sv,*.vhd,*.py  ks|call LastModified()|'s  
"function! LastModified()
"       if line("$") > 20
"               let l = 20
"       else
"               let l = line("$")
"       endif
"       exec "1,".l."g/Last Modified: /s/Last Modified: .*/Last Modified:".
"                       \strftime(" %Y-%m-%d %H:%M:%S") . "/e"
"endfunc

" Returns true if paste mode is enabled
function! HasPaste()
    if &paste
        return '[PASTE MODE]  '
    endif
    return ''
endfunction

"""""""""""""""""""""""""""""""""""""""""
" return vim mode
"""""""""""""""""""""""""""""""""""""""""
function! Disp_Mode()
    let mode=mode()
    if mode ==# 'v'
        return 'Visual'
    elseif mode ==# 'V'
        return 'V-Line'
    elseif mode ==# ''
        return 'V-Block'
    elseif mode ==# 's'
        return 'Select'
        elseif mode ==# 'S'
        return 'S-Line'
        elseif mode ==# ''
        return 'S-Block'
        elseif mode =~# '\vi'
        return 'Insert'
        elseif mode =~# '\v(R|Rv)'
        return 'Replace'
        else
        return 'Normal'
        endif
endfunction


"""""""""""""""""""""""""""""""""""""""""
" filetype
"""""""""""""""""""""""""""""""""""""""""
au BufNewFile,BufRead readme,README setf help

"""""""""""""""""""""""""""""""""""""""""
" plugin: supertab
"""""""""""""""""""""""""""""""""""""""""
let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabMappingForward = '<s-space>'
let g:SuperTabMappingBackward = '<s-c-space>'

"""""""""""""""""""""""""""""""""""""""""
" plugin: NERDTree
"""""""""""""""""""""""""""""""""""""""""
"autocmd vimenter * NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
map <F3> :NERDTreeToggle<CR>
let NERDTreeShowHidden=0
let NERDTreeWinSize=25
let NERDTreeIgnore=['\~$', '\.swap$', '.pyc$']

"""""""""""""""""""""""""""""""""""""""""
" plugin: UltiSnips
"""""""""""""""""""""""""""""""""""""""""
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<c-b>"

" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
请我喝杯水
SoulChild 微信号 微信号
SoulChild 微信打赏 微信打赏
0%