summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWe-unite <weunite1848@gmail.com>2024-12-24 20:02:23 +0800
committerWe-unite <weunite1848@gmail.com>2024-12-24 20:02:23 +0800
commitbfbd3b4f8722aa54d031459b2792d116c4f50ad6 (patch)
treedf477fd4199c865bd59535dd57de749e0001e5e4
parent5cdf252e523414ab73cccd1a3bfd334c606dbac1 (diff)
downloadvimrc-bfbd3b4f8722aa54d031459b2792d116c4f50ad6.tar.gz
vimrc-bfbd3b4f8722aa54d031459b2792d116c4f50ad6.zip
Fix some important bugs
- For all files, `gg=G`is changed to make the cursor position fixed after the file gets formatted. - For files in git repo, the old way to show branch is totally wrong, because the space of `git branch` is deleted. - Show EOL and wrap char in vim - Other things
-rw-r--r--vimrc2
-rw-r--r--vimrcs/codecmd.vim21
-rw-r--r--vimrcs/myset.vim24
-rw-r--r--vimrcs/plugs.vim78
-rw-r--r--vimrcs/statusline.vim2
5 files changed, 52 insertions, 75 deletions
diff --git a/vimrc b/vimrc
index 6ab2204..f6fc5d3 100644
--- a/vimrc
+++ b/vimrc
@@ -4,7 +4,7 @@ let vimrcs = {
4 \ "myset": "自行设置", 4 \ "myset": "自行设置",
5 \ "statusline": "状态栏与标签页设置", 5 \ "statusline": "状态栏与标签页设置",
6 \ "codecmd": "代码设置", 6 \ "codecmd": "代码设置",
7 \ "keys": "自己设的快捷键", 7 \ "keys": "自己设的快捷键",
8 \ "plugs": "Vundle插件管理及插件内容", 8 \ "plugs": "Vundle插件管理及插件内容",
9 \ } 9 \ }
10 10
diff --git a/vimrcs/codecmd.vim b/vimrcs/codecmd.vim
index 4add725..179e68e 100644
--- a/vimrcs/codecmd.vim
+++ b/vimrcs/codecmd.vim
@@ -21,16 +21,16 @@ autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
21autocmd FileType php set omnifunc=phpcomplete#CompletePHP 21autocmd FileType php set omnifunc=phpcomplete#CompletePHP
22autocmd FileType c set omnifunc=ccomplete#Complete 22autocmd FileType c set omnifunc=ccomplete#Complete
23 23
24" 要求格式化不要移动光标,并不要删除换行符和空行,保留原来的视图 24" gg=G
25autocmd BufReadPost,BufWritePre *.html,*.vim,*.sh,*.py normal! g1G=G`"z<CR> 25nnoremap gg=G :call PreserveCursorAndFormat()<CR>
26" 在保存时自动使用clang-format格式化代码 26function! PreserveCursorAndFormat()
27augroup FormatAutocmd 27 let l:save_pos = getpos(".")
28 autocmd! 28 let l:save_view = winsaveview()
29 autocmd BufWritePre *.c,*.cpp,*.h :let save_cursor = getpos(".") 29 normal! gg=G
30 autocmd BufWritePre *.c,*.cpp,*.h :normal! ggVG 30 call setpos('.', l:save_pos)
31 autocmd BufWritePre *.c,*.cpp,*.h :ClangFormat 31 call winrestview(l:save_view)
32 autocmd BufWritePost *.c,*.cpp,*.h :call setpos('.', save_cursor) 32endfunction
33augroup END 33
34 34
35command! -nargs=0 ClangFormat :call ClangFormat() 35command! -nargs=0 ClangFormat :call ClangFormat()
36autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR> 36autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR>
@@ -98,6 +98,5 @@ func SetTitle()
98 call append(line(".")+9, "") 98 call append(line(".")+9, "")
99 endif 99 endif
100 endif 100 endif
101 " 光标移动到文件末尾
102 normal G 101 normal G
103endfunc 102endfunc
diff --git a/vimrcs/myset.vim b/vimrcs/myset.vim
index b977223..4dab14c 100644
--- a/vimrcs/myset.vim
+++ b/vimrcs/myset.vim
@@ -3,20 +3,20 @@ set encoding=utf-8
3set fileencoding=utf-8 3set fileencoding=utf-8
4set fileencodings=ucs-bom,utf-8,GB18030,cp936,big5,euc-jp,euc-kr,latin1 4set fileencodings=ucs-bom,utf-8,GB18030,cp936,big5,euc-jp,euc-kr,latin1
5set fileformat=unix 5set fileformat=unix
6set helplang=cn " 帮助中文支持 6set helplang=cn " 帮助中文支持
7set mouse=a " 设置鼠标 7set mouse=a " 设置鼠标
8set noeb " 去掉输入错误的提示声音 8set noeb " 去掉输入错误的提示声音
9set confirm " 在处理未保存或只读文件的时候,弹出确认 9set confirm " 在处理未保存或只读文件的时候,弹出确认
10set langmenu=zh_CN.UTF-8 " 设置菜单语言 10set langmenu=zh_CN.UTF-8 " 设置菜单语言
11set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 11set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离
12set vb t_vb= " 关闭错误提示声音 12set vb t_vb= " 关闭错误提示声音
13 13
14colorscheme industry " 设置配色方案 14colorscheme industry " 设置配色方案
15syntax on 15syntax on
16set rnu " 设置相对行号 16set rnu " 设置相对行号
17set nu " 设置绝对行号 17set nu " 设置绝对行号
18set list " 显示tab和空格 18set list " 显示tab和空格
19set listchars=tab:>-,trail:- " 设置tab和空格的显示方式 19set listchars=tab:>-,trail:-,eol:$,extends:>, " 设置tab和空格的显示方式
20set cul 20set cul
21set cuc 21set cuc
22autocmd VimEnter * hi CursorLine cterm=NONE ctermbg=red ctermfg=NONE guibg=darkblue guifg=NONE 22autocmd VimEnter * hi CursorLine cterm=NONE ctermbg=red ctermfg=NONE guibg=darkblue guifg=NONE
diff --git a/vimrcs/plugs.vim b/vimrcs/plugs.vim
index 8ef3e2a..fee1b2e 100644
--- a/vimrcs/plugs.vim
+++ b/vimrcs/plugs.vim
@@ -47,10 +47,8 @@ let g:ycm_semantic_triggers = {
47 \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'], 47 \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
48 \ 'cs,lua,javascript': ['re!\w{2}'], 48 \ 'cs,lua,javascript': ['re!\w{2}'],
49 \ } 49 \ }
50" hi PMenu ctermfg=34 ctermbg=21 guifg=darkred guibg=darkblue 50hi PMenu ctermbg=white ctermfg=NONE guibg=white guifg=NONE
51" hi PMenuSel ctermfg=21 ctermbg=34 guifg=darkblue guibg=darkred 51hi PMenuSel ctermbg=brown ctermfg=NONE guibg=brown guifg=NONE
52hi PMenu ctermfg=darkgrey ctermbg=21 guifg=darkred guibg=darkblue
53hi PMenuSel ctermfg=yellow ctermbg=34 guifg=darkblue guibg=darkred
54nnoremap gdec :YcmCompleter GoToDeclaration<CR> 52nnoremap gdec :YcmCompleter GoToDeclaration<CR>
55nnoremap gdef :YcmCompleter GoToDefinition<CR> 53nnoremap gdef :YcmCompleter GoToDefinition<CR>
56nnoremap gd :YcmCompleter GoToDefinitionElseDeclaration<CR> 54nnoremap gd :YcmCompleter GoToDefinitionElseDeclaration<CR>
@@ -95,7 +93,6 @@ let g:NERDTreeGitStatusUntrackedFilesMode = 'all' " a heavy feature too. default
95let g:translator_target_lang = 'zh' 93let g:translator_target_lang = 'zh'
96let g:translator_source_lang = 'auto' 94let g:translator_source_lang = 'auto'
97let g:translator_default_engines = ['youdao', 'bing', 'google', 'haici'] 95let g:translator_default_engines = ['youdao', 'bing', 'google', 'haici']
98" let g:translator_default_engines = ['bing']
99let g:translator_history_enable = v:true 96let g:translator_history_enable = v:true
100let g:translator_window_type = 'popup' " 可选值为 'popup' 和 'preview',默认为 'popup' 97let g:translator_window_type = 'popup' " 可选值为 'popup' 和 'preview',默认为 'popup'
101" Echo translation in the cmdline 98" Echo translation in the cmdline
@@ -105,60 +102,41 @@ vmap <silent> <Leader>t <Plug>TranslateV
105nmap <silent> <Leader>w <Plug>TranslateW 102nmap <silent> <Leader>w <Plug>TranslateW
106vmap <silent> <Leader>w <Plug>TranslateWV 103vmap <silent> <Leader>w <Plug>TranslateWV
107" Close the translation window 104" Close the translation window
108" nmap <silent> <Leader>cl <Plug>TranslateC 105nmap <silent> <Leader>wc <Plug>TranslateC
109" Replace the text with translation
110" nmap <silent> <Leader>r <Plug>TranslateR
111" vmap <silent> <Leader>r <Plug>TranslateRV
112" Translate the text in clipboard
113" nmap <silent> <Leader>x <Plug>TranslateX
114 106
115" vim-indent-guides 107" vim-indent-guides
116let g:indent_guides_enable_on_vim_startup = 1 " 启动时自动开启缩进线 108let g:indent_guides_enable_on_vim_startup = 1 " 启动时自动开启缩进线
117let g:indent_guides_guide_size = 1 " 缩进线宽度 109let g:indent_guides_guide_size = 1 " 缩进线宽度
118let g:indent_guides_start_level = 2 " 从第二级开始显示缩进线 110let g:indent_guides_start_level = 2 " 从第二级开始显示缩进线
119let g:indent_guides_auto_colors = 0 " 自动颜色 111let g:indent_guides_auto_colors = 1 " 自动颜色
120autocmd VimEnter * highlight IndentGuidesOdd ctermbg=gray " 缩进线颜色 112let g:indent_guides_tab_guides = 0
121autocmd VimEnter * highlight IndentGuidesEven ctermbg=darkgrey " 缩进线颜色 113" autocmd VimEnter * highlight IndentGuidesOdd ctermbg=gray " 缩进线颜色
114" autocmd VimEnter * highlight IndentGuidesEven ctermbg=darkgrey " 缩进线颜色
122 115
123" nerdcommenter 116" nerdcommenter
124let g:NERDSpaceDelims = 1 " 在注释符号前后加空格 117let g:NERDSpaceDelims = 1 " 在注释符号前后加空格
125" let g:NERDCompactSexyComs = 1 " 紧凑的注释格式 118let g:NERDCompactSexyComs = 1 " 紧凑的注释格式
126
127" vim-terminal-help
128" set termwinsize=10*106
129" let g:terminal_key = ''
130" 设置光标在终端与编辑器间切换的快捷键
131 119
132" 进行Taglist的设置 120" 进行Taglist的设置
133" map <space>tl Tlist<CR> " 121map <space>tl Tlist<CR> "
134" let Tlist_Ctags_Cmd='/usr/local/bin/ctags' " 因为我们放在环境变量里,所以可以直接执行 122let Tlist_Ctags_Cmd='/usr/local/bin/ctags' " 因为我们放在环境变量里,所以可以直接执行
135" let Tlist_Use_Right_Window=1 " 让窗口显示在右边,0的话就是显示在左边 123let Tlist_Use_Right_Window=1 " 让窗口显示在右边,0的话就是显示在左边
136" let Tlist_Show_One_File=1 " 让taglist可以同时展示多个文件的函数列表 124let Tlist_Show_One_File=1 " 让taglist可以同时展示多个文件的函数列表
137" let Tlist_File_Fold_Auto_Close=0 " 非当前文件列表折叠隐藏 125let Tlist_File_Fold_Auto_Close=0 " 非当前文件列表折叠隐藏
138" let Tlist_Exit_OnlyWindow=1 " 当taglist是最后一个分割窗口时,自动推出vim 126let Tlist_Exit_OnlyWindow=1 " 当taglist是最后一个分割窗口时,自动推出vim
139" let Tlist_Process_File_Always=1 " 是否一直处理tags.1:处理;0:不处理 127let Tlist_Process_File_Always=1 " 是否一直处理tags.1:处理;0:不处理
140" let Tlist_Inc_Winwidth=1 " 不是一直实时更新tags,因为没有必要 128let Tlist_Inc_Winwidth=1 " 不是一直实时更新tags,因为没有必要
141" " 每隔多少秒更新一次tags,如果为0则不更新 129" 每隔多少秒更新一次tags,如果为0则不更新
142" let Tlist_Update_Time=5 130let Tlist_Update_Time=5
143" " 在每个标签页打开相同的函数列表 131" 在每个标签页打开相同的函数列表
144" autocmd BufWinEnter * if getcmdwintype() == '' | silent TlistUpdate | endif 132autocmd BufWinEnter * if getcmdwintype() == '' | silent TlistUpdate | endif
145" " 打开新标签页时自动打开函数列表 133" 打开新标签页时自动打开函数列表
146" autocmd BufWinEnter * if (winnr("$") == 1 && exists("b:NERDTree") 134autocmd BufWinEnter * if (winnr("$") == 1 && exists("b:NERDTree")
147" \ && b:NERDTree.IsTabTree()) | 135 \ && b:NERDTree.IsTabTree()) |
148" \silent TlistToggle | endif 136 \silent TlistToggle | endif
149 137
150" syntastic 138" syntastic
151" YouCompleteMe插件对该插件支持过于优秀,一般不再需要配置,故废弃 139" YouCompleteMe插件对该插件支持过于优秀,一般不再需要配置,故废弃
152" let g:syntastic_python_checkers=['pylint'] 140let g:syntastic_python_checkers=['pylint']
153" let g:syntastic_python_pylint_args=['--disable=C0111,R0903,C0301'] 141let g:syntastic_python_pylint_args=['--disable=C0111,R0903,C0301']
154" let g:syntastic_asm_checkers=['as86'] " GNU as汇编语言语法检查,需要安装as86和ld86 142let g:syntastic_asm_checkers=['as86'] " GNU as汇编语言语法检查,需要安装as86和ld86
155
156" powerline
157" let laststatus=2
158" let g:airlinr_powerline_fonts=1 " 使用官方打过补丁的字体
159" let g:Powerline_symbols='fancy'
160
161" " everforest
162" autocmd VimEnter * colorscheme everforest " 设置颜色主题
163" let g:everforest_background = 'soft'
164" let g:everforest_enable_italic = 1
diff --git a/vimrcs/statusline.vim b/vimrcs/statusline.vim
index 9216343..8105a31 100644
--- a/vimrcs/statusline.vim
+++ b/vimrcs/statusline.vim
@@ -68,7 +68,7 @@ function! ShowGit()
68 " 查看当前所在分支 68 " 查看当前所在分支
69 let s:branch = system(l:git . " branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/' | tr -d '\n' | tr -d ' '") 69 let s:branch = system(l:git . " branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/' | tr -d '\n' | tr -d ' '")
70 " 字符串匹配,匹配不到"HEAD detached at"或者”头指针在xxx分离“则返回branch 70 " 字符串匹配,匹配不到"HEAD detached at"或者”头指针在xxx分离“则返回branch
71 if match(s:branch, 'HEAD detached at') == -1 && match(s:branch, '分离') == -1 71 if match(s:branch, 'HEADdetachedat') == -1 && match(s:branch, '分离') == -1
72 return strlen(s:branch) ? 'b: '.s:branch.'> ' : '' 72 return strlen(s:branch) ? 'b: '.s:branch.'> ' : ''
73 endif 73 endif
74 " 查看当前是否在tag上,如果是则返回tag名 74 " 查看当前是否在tag上,如果是则返回tag名