diff options
author | 2024-12-24 20:02:23 +0800 | |
---|---|---|
committer | 2024-12-24 20:02:23 +0800 | |
commit | bfbd3b4f8722aa54d031459b2792d116c4f50ad6 (patch) | |
tree | df477fd4199c865bd59535dd57de749e0001e5e4 | |
parent | 5cdf252e523414ab73cccd1a3bfd334c606dbac1 (diff) | |
download | vimrc-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-- | vimrc | 2 | ||||
-rw-r--r-- | vimrcs/codecmd.vim | 21 | ||||
-rw-r--r-- | vimrcs/myset.vim | 24 | ||||
-rw-r--r-- | vimrcs/plugs.vim | 78 | ||||
-rw-r--r-- | vimrcs/statusline.vim | 2 |
5 files changed, 52 insertions, 75 deletions
@@ -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 | |||
21 | autocmd FileType php set omnifunc=phpcomplete#CompletePHP | 21 | autocmd FileType php set omnifunc=phpcomplete#CompletePHP |
22 | autocmd FileType c set omnifunc=ccomplete#Complete | 22 | autocmd FileType c set omnifunc=ccomplete#Complete |
23 | 23 | ||
24 | " 要求格式化后的不要移动光标,并不要删除换行符和空行,保留原来的视图 | 24 | " gg=G的 |
25 | autocmd BufReadPost,BufWritePre *.html,*.vim,*.sh,*.py normal! g1G=G`"z<CR> | 25 | nnoremap gg=G :call PreserveCursorAndFormat()<CR> |
26 | " 在保存时自动使用clang-format格式化代码 | 26 | function! PreserveCursorAndFormat() |
27 | augroup 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) | 32 | endfunction |
33 | augroup END | 33 | |
34 | 34 | ||
35 | command! -nargs=0 ClangFormat :call ClangFormat() | 35 | command! -nargs=0 ClangFormat :call ClangFormat() |
36 | autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR> | 36 | autocmd 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 |
103 | endfunc | 102 | endfunc |
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 | |||
3 | set fileencoding=utf-8 | 3 | set fileencoding=utf-8 |
4 | set fileencodings=ucs-bom,utf-8,GB18030,cp936,big5,euc-jp,euc-kr,latin1 | 4 | set fileencodings=ucs-bom,utf-8,GB18030,cp936,big5,euc-jp,euc-kr,latin1 |
5 | set fileformat=unix | 5 | set fileformat=unix |
6 | set helplang=cn " 帮助中文支持 | 6 | set helplang=cn " 帮助中文支持 |
7 | set mouse=a " 设置鼠标 | 7 | set mouse=a " 设置鼠标 |
8 | set noeb " 去掉输入错误的提示声音 | 8 | set noeb " 去掉输入错误的提示声音 |
9 | set confirm " 在处理未保存或只读文件的时候,弹出确认 | 9 | set confirm " 在处理未保存或只读文件的时候,弹出确认 |
10 | set langmenu=zh_CN.UTF-8 " 设置菜单语言 | 10 | set langmenu=zh_CN.UTF-8 " 设置菜单语言 |
11 | set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 | 11 | set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 |
12 | set vb t_vb= " 关闭错误提示声音 | 12 | set vb t_vb= " 关闭错误提示声音 |
13 | 13 | ||
14 | colorscheme industry " 设置配色方案 | 14 | colorscheme industry " 设置配色方案 |
15 | syntax on | 15 | syntax on |
16 | set rnu " 设置相对行号 | 16 | set rnu " 设置相对行号 |
17 | set nu " 设置绝对行号 | 17 | set nu " 设置绝对行号 |
18 | set list " 显示tab和空格 | 18 | set list " 显示tab和空格 |
19 | set listchars=tab:>-,trail:- " 设置tab和空格的显示方式 | 19 | set listchars=tab:>-,trail:-,eol:$,extends:>, " 设置tab和空格的显示方式 |
20 | set cul | 20 | set cul |
21 | set cuc | 21 | set cuc |
22 | autocmd VimEnter * hi CursorLine cterm=NONE ctermbg=red ctermfg=NONE guibg=darkblue guifg=NONE | 22 | autocmd 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 | 50 | hi PMenu ctermbg=white ctermfg=NONE guibg=white guifg=NONE |
51 | " hi PMenuSel ctermfg=21 ctermbg=34 guifg=darkblue guibg=darkred | 51 | hi PMenuSel ctermbg=brown ctermfg=NONE guibg=brown guifg=NONE |
52 | hi PMenu ctermfg=darkgrey ctermbg=21 guifg=darkred guibg=darkblue | ||
53 | hi PMenuSel ctermfg=yellow ctermbg=34 guifg=darkblue guibg=darkred | ||
54 | nnoremap gdec :YcmCompleter GoToDeclaration<CR> | 52 | nnoremap gdec :YcmCompleter GoToDeclaration<CR> |
55 | nnoremap gdef :YcmCompleter GoToDefinition<CR> | 53 | nnoremap gdef :YcmCompleter GoToDefinition<CR> |
56 | nnoremap gd :YcmCompleter GoToDefinitionElseDeclaration<CR> | 54 | nnoremap gd :YcmCompleter GoToDefinitionElseDeclaration<CR> |
@@ -95,7 +93,6 @@ let g:NERDTreeGitStatusUntrackedFilesMode = 'all' " a heavy feature too. default | |||
95 | let g:translator_target_lang = 'zh' | 93 | let g:translator_target_lang = 'zh' |
96 | let g:translator_source_lang = 'auto' | 94 | let g:translator_source_lang = 'auto' |
97 | let g:translator_default_engines = ['youdao', 'bing', 'google', 'haici'] | 95 | let g:translator_default_engines = ['youdao', 'bing', 'google', 'haici'] |
98 | " let g:translator_default_engines = ['bing'] | ||
99 | let g:translator_history_enable = v:true | 96 | let g:translator_history_enable = v:true |
100 | let g:translator_window_type = 'popup' " 可选值为 'popup' 和 'preview',默认为 'popup' | 97 | let 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 | |||
105 | nmap <silent> <Leader>w <Plug>TranslateW | 102 | nmap <silent> <Leader>w <Plug>TranslateW |
106 | vmap <silent> <Leader>w <Plug>TranslateWV | 103 | vmap <silent> <Leader>w <Plug>TranslateWV |
107 | " Close the translation window | 104 | " Close the translation window |
108 | " nmap <silent> <Leader>cl <Plug>TranslateC | 105 | nmap <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 |
116 | let g:indent_guides_enable_on_vim_startup = 1 " 启动时自动开启缩进线 | 108 | let g:indent_guides_enable_on_vim_startup = 1 " 启动时自动开启缩进线 |
117 | let g:indent_guides_guide_size = 1 " 缩进线宽度 | 109 | let g:indent_guides_guide_size = 1 " 缩进线宽度 |
118 | let g:indent_guides_start_level = 2 " 从第二级开始显示缩进线 | 110 | let g:indent_guides_start_level = 2 " 从第二级开始显示缩进线 |
119 | let g:indent_guides_auto_colors = 0 " 自动颜色 | 111 | let g:indent_guides_auto_colors = 1 " 自动颜色 |
120 | autocmd VimEnter * highlight IndentGuidesOdd ctermbg=gray " 缩进线颜色 | 112 | let g:indent_guides_tab_guides = 0 |
121 | autocmd 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 |
124 | let g:NERDSpaceDelims = 1 " 在注释符号前后加空格 | 117 | let g:NERDSpaceDelims = 1 " 在注释符号前后加空格 |
125 | " let g:NERDCompactSexyComs = 1 " 紧凑的注释格式 | 118 | let 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> " | 121 | map <space>tl Tlist<CR> " |
134 | " let Tlist_Ctags_Cmd='/usr/local/bin/ctags' " 因为我们放在环境变量里,所以可以直接执行 | 122 | let Tlist_Ctags_Cmd='/usr/local/bin/ctags' " 因为我们放在环境变量里,所以可以直接执行 |
135 | " let Tlist_Use_Right_Window=1 " 让窗口显示在右边,0的话就是显示在左边 | 123 | let Tlist_Use_Right_Window=1 " 让窗口显示在右边,0的话就是显示在左边 |
136 | " let Tlist_Show_One_File=1 " 让taglist可以同时展示多个文件的函数列表 | 124 | let Tlist_Show_One_File=1 " 让taglist可以同时展示多个文件的函数列表 |
137 | " let Tlist_File_Fold_Auto_Close=0 " 非当前文件列表折叠隐藏 | 125 | let Tlist_File_Fold_Auto_Close=0 " 非当前文件列表折叠隐藏 |
138 | " let Tlist_Exit_OnlyWindow=1 " 当taglist是最后一个分割窗口时,自动推出vim | 126 | let Tlist_Exit_OnlyWindow=1 " 当taglist是最后一个分割窗口时,自动推出vim |
139 | " let Tlist_Process_File_Always=1 " 是否一直处理tags.1:处理;0:不处理 | 127 | let Tlist_Process_File_Always=1 " 是否一直处理tags.1:处理;0:不处理 |
140 | " let Tlist_Inc_Winwidth=1 " 不是一直实时更新tags,因为没有必要 | 128 | let Tlist_Inc_Winwidth=1 " 不是一直实时更新tags,因为没有必要 |
141 | " " 每隔多少秒更新一次tags,如果为0则不更新 | 129 | " 每隔多少秒更新一次tags,如果为0则不更新 |
142 | " let Tlist_Update_Time=5 | 130 | let Tlist_Update_Time=5 |
143 | " " 在每个标签页打开相同的函数列表 | 131 | " 在每个标签页打开相同的函数列表 |
144 | " autocmd BufWinEnter * if getcmdwintype() == '' | silent TlistUpdate | endif | 132 | autocmd BufWinEnter * if getcmdwintype() == '' | silent TlistUpdate | endif |
145 | " " 打开新标签页时自动打开函数列表 | 133 | " 打开新标签页时自动打开函数列表 |
146 | " autocmd BufWinEnter * if (winnr("$") == 1 && exists("b:NERDTree") | 134 | autocmd 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'] | 140 | let g:syntastic_python_checkers=['pylint'] |
153 | " let g:syntastic_python_pylint_args=['--disable=C0111,R0903,C0301'] | 141 | let g:syntastic_python_pylint_args=['--disable=C0111,R0903,C0301'] |
154 | " let g:syntastic_asm_checkers=['as86'] " GNU as汇编语言语法检查,需要安装as86和ld86 | 142 | let 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名 |