如何格式化如下所示的PHP代码
class SomeClass
{
function insideclass()
{
}
} 在没有任何外部工具的情况下使用Vim?
class SomeClass {
function insideclass() {
}
} 我并不是说这是格式化代码的最佳方式,但这是我们团队所遵循的。
编辑:删除了对片段的引用,这导致了对这个问题的一些困惑。
发布于 2012-04-12 07:58:49
你有两个不相关的问题,你找不到唯一的解决办法。
class 代码片段.
没问题。如果它还没有出现,那么创建~/.vim/snippets/php.snippets并通过遵循其他答案定制它以适应您的团队的规则。Snipmate不够聪明,无法适应您的编码风格。- `:g/pattern` acts on all lines containing `pattern`, see `:h :global`.
- `^\s*{\s*$` matches all single `{` whatever the amount of whitespace between them and the beginning of the line.
- `normal` executes `normal` commands, see `:h :normal`.
- `kJ` goes up one line and `J`oins this line with the matched line.
- Done.ENDEDIT
发布于 2012-04-12 06:54:51
为什么不修改那个插件的源代码呢?
例如,更改以下内容:
snippet class
/**
* ${1}
*/
class ${2:ClassName}
{
${3}
function ${4:__construct}(${5:argument})
{
${6:// code...}
}
}至
snippet class
/**
* ${1}
*/
class ${2:ClassName}{
${3}
function ${4:__construct}(${5:argument}){
${6:// code...}
}
}发布于 2012-04-12 06:56:33
所有的代码片段都存储在一个目录中。转到该目录并编辑所需的文件。
direcorty存储在vim目录中,名为snippets。在这里您可以看到一个php.snippets文件。转到该文件,在第70行,您可以编辑该类的代码片段。
https://stackoverflow.com/questions/10118738
复制相似问题