From 57315c52be96d2a2c013f0cfb0de5429980e301a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Nov 2025 17:49:34 +0900 Subject: refactor(blog): rename directory, services/{blog => nuldoc}/ --- ...sert-namespace-declaration-to-empty-php-file.dj | 205 +++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 services/nuldoc/content/posts/2024-01-10/neovim-insert-namespace-declaration-to-empty-php-file.dj (limited to 'services/nuldoc/content/posts/2024-01-10') diff --git a/services/nuldoc/content/posts/2024-01-10/neovim-insert-namespace-declaration-to-empty-php-file.dj b/services/nuldoc/content/posts/2024-01-10/neovim-insert-namespace-declaration-to-empty-php-file.dj new file mode 100644 index 0000000..483b0b9 --- /dev/null +++ b/services/nuldoc/content/posts/2024-01-10/neovim-insert-namespace-declaration-to-empty-php-file.dj @@ -0,0 +1,205 @@ +--- +[article] +uuid = "05cb16e1-05bc-4359-bc06-88ac20510740" +title = "【Neovim】 空の PHP ファイルに namespace 宣言を挿入する" +description = "Neovim で空の PHP ファイルを開いたとき、ディレクトリの構造に基づいて自動的に namespace 宣言を挿入するようにする。" +tags = [ + "neovim", + "php", +] + +[[article.revisions]] +date = "2024-01-10" +remark = "公開" +--- +::: note +この記事は [Vim 駅伝](https://vim-jp.org/ekiden/) #136 の記事です。 +::: + +{#intro} +# やりたいこと + +Neovim で空の PHP ファイルを開いたとき、そのファイルが置かれているディレクトリの構造に基づいて、自動的に `namespace` 宣言を挿入したい。具体的には、トップレベルの名前空間が `MyNamespace` であり、ファイル `src/Foo/Bar/Baz.php` を開いたときに、そのファイルが空であるなら、次のようなテンプレートが自動的に挿入されてほしい。 + +```php +