1.gvim

1
:edit $vim/_vimrc

在末尾加

image-20210805151848038

禁止生成临时文件

1
2
3
set noundofile
set nobackup
set noswapfile

2.vimwiki

Vimwiki by vimwiki

vimwiki的配置修改:

1
2
3
4
5
6
7
8
" let g:vimwiki_list = [{'path' : '/d/vimwiki/', 'path_html' : '/d/vimwiki/html/', 'auto_export' : 1, 'nested_syntaxes'     : { 'vim' : 'vim' } }]
" 生成markdown文件
let g:vimwiki_list = [{'path' : '/d/vimwiki/', 'path_html' : '/d/vimwiki/html/', 'auto_export' : 1, 'syntax':'markdown','ext':'.md'}]

let g:vimwiki_use_mouse = 1
" let g:vimwiki_w32_dir_enc = cp936
let g:vimwiki_dir_link = 'index'
let g:vimwiki_html_header_numbering = 0

3.vimrc

vimrc 在哪?

1、输入 :version 即可找到。

2、输入 :edit $vim/_vimrc 可编辑。($vim/_vimrc 为 vimrc 的路径,可能不同,通过1查看)

4.插件管理

Vundle插件管理器

1
2
3
4
5
6
7
8
9
10
11
12
13
set nocompatible
"插件管理
set rtp+=$VIM/vimfiles/bundle/Vundle.vim/ "此处根据:version路径灵活配置
call vundle#begin()
"let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim' "插件管理必须的
"my bundle plugin
Plugin 'scrooloose/nerdtree' "这两行
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'kien/ctrlp.vim'

call vundle#end()
filetype plugin indent on

call vundle#begin()call vundle#end() 之间添加完插件后,需要在vim的命令行模式下安装,命令如下:

1
2
3
4
5
6
7
常用命令
:PluginList - 查看已经安装的插件
:PluginInstall - 安装插件
:PluginUpdate - 更新插件
:PluginSearch - 搜索插件,例如 :PluginSearch xml就能搜到xml相关的插件
:PluginClean - 删除插件,把安装插件对应行删除,然后执行这个命令即可
:h vundle - 获取帮助

在使用PluginInstall时遇到一个奇葩的错误,插件vimwiki更新失败,查看日志,发现git的地址不对,地址本来是[https://github.com/vimwiki/vimwiki] ,但日志的地址变成了[https://github.com/vimwiki/118] ,一看才明白,在使用PluginInstall时,文件窗口被分割成了垂直的两个(类似使用vsplit),vimwiki的git地址也被分成了两行,第一行的结尾后面就是第二个窗口的第118行的行号,所以地址后面被改成了118……

一些有用的插件

  • NERDTree目录

    1
    2
    3
    4
    "Nerdtree
    autocmd vimenter * NERDTree "打开vim自动打开目录"
    map <F2> :NERDTreeMirror<CR> "按F2开启或关闭NERDTree目录"
    map <F2> :NERDTreeToggle<CR>

5.常用配置

1
2
3
4
5
6
7
8
9
" 设置在查找时动态匹配
set incsearch

" 设置搜索高亮显示 --不推荐
set hlsearch

" PS1一般配置
PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\033[01;32m\[\033[00m\]$ "
" 其中颜色设置 [\033[01;32m\],以[\033[00m\]结尾

6.示例文本

来自 git bash 配置文件:

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
"
" Setting some decent VIM settings for programming
" This source file comes from git-for-windows build-extra repository (git-extra/vimrc)

ru! defaults.vim " Use Enhanced Vim defaults
set mouse= " Reset the mouse setting from defaults
aug vimStartup | au! | aug END " Revert last positioned jump, as it is defined below
let g:skip_defaults_vim = 1 " Do not source defaults.vim again (after loading this system vimrc)


set nocompatible
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"call vundle#begin('~/some/path/here')

Plugin 'VundleVim/Vundle.vim'

Plugin 'vimwiki/vimwiki'

call vundle#end()
filetype plugin indent on


set ai " set auto-indenting on for programming
set showmatch " automatically show matching brackets. works like it does in bbedit.
set vb " turn on the "visual bell" - which is much quieter than the "audio blink"
set laststatus=2 " make the last line where the status is two lines deep so you can see status always
set showmode " show the current mode
set clipboard=unnamed " set clipboard to unnamed to access the system clipboard under windows
set wildmode=list:longest,longest:full " Better command line completion

" Show EOL type and last modified timestamp, right after the filename
" Set the statusline
set statusline=%f " filename relative to current $PWD
set statusline+=%h " help file flag
set statusline+=%m " modified flag
set statusline+=%r " readonly flag
set statusline+=\ [%{&ff}] " Fileformat [unix]/[dos] etc...
set statusline+=\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))}) " last modified timestamp
set statusline+=%= " Rest: right align
set statusline+=%l,%c%V " Position in buffer: linenumber, column, virtual column
set statusline+=\ %P " Position in buffer: Percentage

" User define
set autoindent
set cindent
set shiftwidth=4
set softtabstop=4
set ts=2
set expandtab
set number
set mps+=<:>
set guifont=Consolas:h10 #gvim设置字体,linux下可能不同
nmap <CR> o<ESC> #键盘映射,Enter键映射为 o + ESC
syntax on
filetype plugin on
imap {<CR> {<CR>}<ESC>O
imap [ []<ESC>i
imap ( ()<ESC>i
"设置跳出自动补全的括号
func SkipPair()
if getline('.')[col('.') - 1] == ')' || getline('.')[col('.') - 1] == ']' || getline('.')[col('.') - 1] == '"' || getline('.')[col('.') - 1] == "'" || getline('.')[col('.') - 1] == '}' || getline('.')[col('.') - 1] == '>'
return "\<ESC>la"
else
return "\t"
endif
endfunc
" 将tab键绑定为跳出括号
inoremap <TAB> <c-r>=SkipPair()<CR>

" color
hi MatchParen ctermbg=Red ctermfg=Yellow
"靠靠靠? "set cursorline
"hi CursorLine cterm=NONE ctermbg=darkblue guibg=darkred guifg=white
"靠靠靠? "set cursorcolumn
"hi CursorColumn cterm=NONE ctermbg=darkblue guibg=darkred guifg=white


if &term =~ 'xterm-256color' " mintty identifies itself as xterm-compatible
if &t_Co == 8
set t_Co = 256 " Use at least 256 colors
endif
" set termguicolors " Uncomment to allow truecolors on mintty
endif
"------------------------------------------------------------------------------
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Set UTF-8 as the default encoding for commit messages
autocmd BufReadPre COMMIT_EDITMSG,MERGE_MSG,git-rebase-todo setlocal fileencodings=utf-8

" Remember the positions in files with some git-specific exceptions"
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$")
\ && &filetype !~# 'commit\|gitrebase'
\ && expand("%") !~ "ADD_EDIT.patch"
\ && expand("%") !~ "addp-hunk-edit.diff" |
\ exe "normal g`\"" |
\ endif

autocmd BufNewFile,BufRead *.patch set filetype=diff

autocmd Filetype diff
\ highlight WhiteSpaceEOL ctermbg=red |
\ match WhiteSpaceEOL /\(^+.*\)\@<=\s\+$/
endif " has("autocmd")

" Set cursor shape and color
if &term =~ "xterm"
" INSERT mode
let &t_SI = "\<Esc>[6 q" . "\<Esc>]12;blue\x7"
" REPLACE mode
let &t_SR = "\<Esc>[3 q" . "\<Esc>]12;black\x7"
" NORMAL mode
let &t_EI = "\<Esc>[2 q" . "\<Esc>]12;green\x7"
endif
" 1 -> blinking block 闪烁的方块
" 2 -> solid block 不闪烁的方块
" 3 -> blinking underscore 闪烁的下划线
" 4 -> solid underscore 不闪烁的下划线
" 5 -> blinking vertical bar 闪烁的竖线
" 6 -> solid vertical bar 不闪烁的竖线

" vimwiki
let g:vimwiki_use_mouse = 1
let g:vimwiki_list = [{'path': '/d/vimwiki/',
\ 'path_html': '/d/vimwiki/html/',
\ 'html_header': '/d/vimwiki/template/header.tpl',}]

7.git配置分支

此项应该在bashrc中配置,之前搞错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#来源:公众号【编程珠玑】
git_branch()
{
branch=`git rev-parse --abbrev-ref HEAD 2>/dev/null`
if [ "${branch}" != "" ]
then
if [ "${branch}" = "(no branch)" ]
then
branch="(`git rev-parse --short HEAD`...)"
fi
echo "($branch)"
fi
}




PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W$(git_branch)\$ '
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\033[01;32m$(git_branch)\[\033[00m\]\$ '