0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Neovimで気軽にClaudeCodeを開けるようにしてみた

Posted at

AI使うならNeovim

ClaudeCodeのようなCLIベースのAIが使われるようになった時、こう思いました「Neovim上でサクッとだしたい...

CLI系AI × Vimのメリット

一言で言うと「コピーが楽」と言うことに尽きます。コピペが必要な文章とかをさくっとコピーできるのがVimのterminalモードの魅力。それを120%活かせるのがAIだと私は確信を持っています。
また、Vimはデフォルトでは周りにいろいろ書かれていないので集中を削ぐUIが少ないこととterminalが共存できることもVSCode系にはあまりみられない大きな魅力に感じています。

何もしていない場合のフロー(Neovim完結の場合)

  1. Neovimを開く
  2. :terminal もしくは :splitからの:terminal
  3. iでterminal insertモードに入ってからのclaudeコマンド実行

これは、考えることが3stepになっていて大変ですね。我々は✝️思考の速度でClaudeCodeを開きたい✝️なわけですからもう少し改善してみましょう。

改善するためにClaudeCodeVimコマンドを用意した

完全にClaudeCodeに書かせました。
使い方は:ClaudeStart split のようにしてあげることです。これでClaudeが起動し終了したらそのVim上のタブごと閉じてくれます。便利。Vimは保管が強く効かせやすいので:Cl<tab><enter>くらいで実質Claudeを開いています。

-- Custom commands

-- ClaudeStart: Open Claude CLI in terminal mode
vim.api.nvim_create_user_command('ClaudeStart', function(opts)
  -- Parse arguments
  local split_type = opts.args or 'vsplit'

  -- Open terminal in split
  if split_type == 'split' or split_type == 'sp' then
    vim.cmd('split | terminal npx @anthropic-ai/claude-code')
  elseif split_type == 'vsplit' or split_type == 'vs' then
    vim.cmd('vsplit | terminal npx @anthropic-ai/claude-code')
  elseif split_type == 'tabnew' or split_type == 'tab' then
    vim.cmd('tabnew | terminal npx @anthropic-ai/claude-code')
  else
    -- Default to current window
    vim.cmd('terminal npx @anthropic-ai/claude-code')
  end

  -- Enter insert mode automatically
  vim.cmd('startinsert')
end, {
  nargs = '?',
  complete = function()
    return {'split', 'vsplit', 'tabnew'}
  end,
  desc = 'Start Claude CLI in terminal mode'
})

Claudeを便利に使うツールをClaudeで作ろう

今回はNeovimで爆速ClaudeCodeを利用する方法を紹介しました。ClaudeCodeでNvimのコマンド作成などをすることで盆栽作業が捗りますのでぜひ使ってみてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?