GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — update gen var · chxuan/cpp-mode@34b0477

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.md
  • autoload/cppmode
    • gen_var.vim
  • ftplugin
    • cpp.vim
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+6-6Lines changed: 6 additions & 6 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ cpp-mode: A C++ IDE for vim
1717
使用
1818
------------
1919

20-
- `:CopyFun`
20+
- `:CopyCode`
2121

22-
拷贝函数,和`:PasteFun`结合使用
22+
拷贝函数或变量,和`:PasteCode`结合使用
2323

24-
- `:PasteFun`
24+
- `:PasteCode`
2525

26-
生成函数实现,和`:CopyFun`结合使用
26+
生成函数实现或变量定义,和`:CopyCode`结合使用
2727

2828
- `:GoToDefinition`
2929

@@ -46,8 +46,8 @@ cpp-mode: A C++ IDE for vim
4646

4747
请将以下配置加到 `~/.vimrc`,如果不喜欢以下映射,可根据个人喜好更改。
4848

49-
nnoremap <leader>y :CopyFun<cr>
50-
nnoremap <leader>p :PasteFun<cr>
49+
nnoremap <leader>y :CopyCode<cr>
50+
nnoremap <leader>p :PasteCode<cr>
5151
nnoremap <leader>U :GoToDefinition<cr>
5252
nnoremap <silent> <leader>a :Switch<cr>
5353
nnoremap <leader><leader>fp :FormatFunParam<cr>
Collapse file

‎autoload/cppmode/gen_var.vim‎

Copy file name to clipboardExpand all lines: autoload/cppmode/gen_var.vim
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,67 @@
55
" License: MIT
66
" ==============================================================
77

8+
" 变量声明
9+
let s:var_declaration = ""
10+
" 类名
11+
let s:class_name = ""
12+
813
" 拷贝变量
914
function! cppmode#gen_var#copy_variate()
15+
let s:var_declaration = <sid>get_var_declaration()
16+
echo s:var_declaration
1017

18+
let row_num = <sid>get_row_num_of_class_name()
19+
let s:class_name = <sid>get_class_name_of_var(row_num)
1120
endfunction
1221

1322
" 粘贴变量
1423
function! cppmode#gen_var#paste_variate()
24+
call cppmode#util#write_text_at_next_row(<sid>get_var_skeleton())
25+
endfunction
26+
27+
" 获得变量声明
28+
function! s:get_var_declaration()
29+
return cppmode#util#get_current_row_text()
30+
endfunction
31+
32+
" 获得类名所在行号
33+
function! s:get_row_num_of_class_name()
34+
let current_num = cppmode#util#get_current_row_num()
35+
36+
while current_num >= 1
37+
let text = cppmode#util#get_row_text(current_num)
38+
if (cppmode#util#is_contains(text, "class ") || cppmode#util#is_contains(text, "struct ")) && !cppmode#util#is_contains(text, "template")
39+
return current_num
40+
endif
41+
let current_num -= 1
42+
endwhile
43+
44+
return -1
45+
endfunction
46+
47+
" 获得函数所在类名
48+
function! s:get_class_name_of_var(row_num)
49+
let text = cppmode#util#get_row_text(a:row_num)
50+
return <sid>parse_class_name(text)
51+
endfunction
52+
53+
" 解析类名
54+
function! s:parse_class_name(text)
55+
return matchlist(a:text, '\(\<class\>\|\<struct\>\)\s\+\(\w[a-zA-Z0-9_]*\)')[2]
56+
endfunction
57+
58+
" 获得变量骨架代码
59+
function! s:get_var_skeleton()
60+
let skeleton = <sid>remove_var_key_words()
61+
let pos = cppmode#util#find_r(skeleton, " ")
62+
63+
return cppmode#util#substr(skeleton, 0, pos + 1) . s:class_name . "::" . cppmode#util#substr(skeleton, pos + 1, len(skeleton))
64+
endfunction
1565

66+
" 去除变量关键字
67+
function! s:remove_var_key_words()
68+
let key_words = ["static"]
69+
return cppmode#util#trim_left(cppmode#util#erase_string_list(s:var_declaration, key_words))
1670
endfunction
1771

Collapse file

‎ftplugin/cpp.vim‎

Copy file name to clipboardExpand all lines: ftplugin/cpp.vim
+35-6Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,38 @@ endif
1111

1212
let g:cppmode_loaded = 1
1313

14-
command! -nargs=0 CopyFun :call cppmode#gen_fun#copy_function()
15-
command! -nargs=0 PasteFun :call cppmode#gen_fun#paste_function()
16-
command! -nargs=0 GoToDefinition :call cppmode#go_to_definition#go_to_definition()
17-
command! -nargs=0 FormatFunParam :call cppmode#format_fun_param#format_function_param()
18-
command! -nargs=0 FormatIf :call cppmode#format_if#format_if()
19-
command! -nargs=0 Switch :call cppmode#switch#switch_file()
14+
let s:is_fun = 0
15+
16+
command! -nargs=0 CopyCode call <sid>copy_code()
17+
command! -nargs=0 PasteCode call <sid>paste_code()
18+
command! -nargs=0 GoToDefinition call cppmode#go_to_definition#go_to_definition()
19+
command! -nargs=0 FormatFunParam call cppmode#format_fun_param#format_function_param()
20+
command! -nargs=0 FormatIf call cppmode#format_if#format_if()
21+
command! -nargs=0 Switch call cppmode#switch#switch_file()
22+
23+
" 拷贝代码
24+
function! s:copy_code()
25+
if <sid>is_function()
26+
let s:is_fun = 1
27+
call cppmode#gen_fun#copy_function()
28+
else
29+
let s:is_fun = 0
30+
call cppmode#gen_var#copy_variate()
31+
endif
32+
endfunction
33+
34+
" 粘贴代码
35+
function! s:paste_code()
36+
if s:is_fun
37+
call cppmode#gen_fun#paste_function()
38+
else
39+
call cppmode#gen_var#paste_variate()
40+
endif
41+
endfunction
42+
43+
" 判断是否是函数
44+
function! s:is_function()
45+
let text = cppmode#util#get_current_row_text()
46+
return cppmode#util#is_contains(text, "(") && cppmode#util#is_contains(text, ")")
47+
endfunction
48+

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.