vim/c -如何按字母顺序排列函数?

时间:2021-05-19 19:24:17

I have a .c file with a bunch of functions. Is there some way to put these functions in alphabetical order in vim?

我有一个带有很多函数的。c文件。有没有什么办法把这些函数按vim的字母顺序排列?

2 个解决方案

#1


2  

If you have lots and lots of functions in one file and you want do it automatically, then we can do it one more "Long" way. Again it depends on how the code is organized. Let say if code is always organized like:

如果你在一个文件中有很多函数并且你想要自动完成,那么我们可以再做一个“长”的过程。这同样取决于代码的组织方式。假设代码总是有组织的,比如:

<return Type>
FunctionName(Arguments)
{
/* Code */
}
  1. Using record feature of VIM, copy all the function names (Complete Line) to a new Split Window. (q a [[ k yy Ctrl-WW p Ctrl-WW j)
  2. 使用VIM的记录特性,将所有函数名(全行)复制到一个新的分割窗口。(q a [k yy Ctrl-WW p Ctrl-WW j])
  3. Sort the new split window. (:sort)
  4. 对新的分割窗口进行排序。(排序):
  5. Record one more macro such that delete first line of Sorted-Split window, copy as a search string in the C file, copy the complete function and paste it at the End of File. (q b yy Ctrl-WW /Ctrl-r 0 k m f jj % d'a G p Ctrl-WW) - Now run this macro number of lines in new window
  6. 再记录一个宏,例如删除分块窗口的第一行,在C文件中以搜索字符串的形式复制,复制完整的函数并粘贴到文件的末尾。(q b yy Ctrl-WW /Ctrl-r 0 k f jj % d'a G p Ctrl-WW)——现在在新窗口中运行这个宏行数

i know this is not efficient way just giving one more way to do it :)

我知道这不是一种有效的方式,只是再给一个方法去做:

#2


0  

If you use the vim Taglist plugin. Which is the top rated and most downloaded plugin for vim.

如果你使用vim标签列表插件。这是vim的最高评级和下载最多的插件。

http://vim-taglist.sourceforge.net/

http://vim-taglist.sourceforge.net/

Then you can easily view the functions ordered alphabetically or in the order they are defined.

然后,您可以轻松地查看按字母顺序排列的函数或按它们定义的顺序排列的函数。

By adding the following line to your vimrc file, the default order will be alphabetical.

通过向vimrc文件中添加以下一行,默认的顺序将按字母顺序排列。

let Tlist_Sort_Type = "name"

让Tlist_Sort_Type = "名称"

You can press the 's' key in the Taglist tab to toggle the order.

您可以在Taglist选项卡中按's'键来切换订单。

search for "Tlist_Sort_Type" in the link below for the official docs:

在下面的链接中搜索“Tlist_Sort_Type”以获取官方文档:

http://vim-taglist.sourceforge.net/manual.html

http://vim-taglist.sourceforge.net/manual.html

#1


2  

If you have lots and lots of functions in one file and you want do it automatically, then we can do it one more "Long" way. Again it depends on how the code is organized. Let say if code is always organized like:

如果你在一个文件中有很多函数并且你想要自动完成,那么我们可以再做一个“长”的过程。这同样取决于代码的组织方式。假设代码总是有组织的,比如:

<return Type>
FunctionName(Arguments)
{
/* Code */
}
  1. Using record feature of VIM, copy all the function names (Complete Line) to a new Split Window. (q a [[ k yy Ctrl-WW p Ctrl-WW j)
  2. 使用VIM的记录特性,将所有函数名(全行)复制到一个新的分割窗口。(q a [k yy Ctrl-WW p Ctrl-WW j])
  3. Sort the new split window. (:sort)
  4. 对新的分割窗口进行排序。(排序):
  5. Record one more macro such that delete first line of Sorted-Split window, copy as a search string in the C file, copy the complete function and paste it at the End of File. (q b yy Ctrl-WW /Ctrl-r 0 k m f jj % d'a G p Ctrl-WW) - Now run this macro number of lines in new window
  6. 再记录一个宏,例如删除分块窗口的第一行,在C文件中以搜索字符串的形式复制,复制完整的函数并粘贴到文件的末尾。(q b yy Ctrl-WW /Ctrl-r 0 k f jj % d'a G p Ctrl-WW)——现在在新窗口中运行这个宏行数

i know this is not efficient way just giving one more way to do it :)

我知道这不是一种有效的方式,只是再给一个方法去做:

#2


0  

If you use the vim Taglist plugin. Which is the top rated and most downloaded plugin for vim.

如果你使用vim标签列表插件。这是vim的最高评级和下载最多的插件。

http://vim-taglist.sourceforge.net/

http://vim-taglist.sourceforge.net/

Then you can easily view the functions ordered alphabetically or in the order they are defined.

然后,您可以轻松地查看按字母顺序排列的函数或按它们定义的顺序排列的函数。

By adding the following line to your vimrc file, the default order will be alphabetical.

通过向vimrc文件中添加以下一行,默认的顺序将按字母顺序排列。

let Tlist_Sort_Type = "name"

让Tlist_Sort_Type = "名称"

You can press the 's' key in the Taglist tab to toggle the order.

您可以在Taglist选项卡中按's'键来切换订单。

search for "Tlist_Sort_Type" in the link below for the official docs:

在下面的链接中搜索“Tlist_Sort_Type”以获取官方文档:

http://vim-taglist.sourceforge.net/manual.html

http://vim-taglist.sourceforge.net/manual.html