@@ -145,18 +145,38 @@ function! s:instance_cwd(instance_id) abort
145145 return ' '
146146 endif
147147 " Normalise both sides to forward slashes for a reliable comparison.
148- let l: inst = substitute (a: instance_id , ' \\ ' , ' /' , ' g ' )
149- let l: cwd = substitute (getcwd (), ' \\ ' , ' /' , ' g ' )
148+ let l: inst = tr (a: instance_id , ' \' , ' /' )
149+ let l: cwd = tr (getcwd (), ' \' , ' /' )
150150 if l: inst == # l: cwd
151151 return ' '
152152 endif
153153 " Return an OS-native path so term_start's cwd option works on all platforms.
154154 if has (' win32' )
155- return substitute (a: instance_id , ' /' , ' \\ ' , ' g ' )
155+ return tr (a: instance_id , ' /' , ' \' )
156156 endif
157157 return a: instance_id
158158endfunction
159159
160+ " Paste from system clipboard into the terminal buffer.
161+ " Bypasses terminal mappings using term_sendkeys().
162+ function ! claude_code#terminal#paste () abort
163+ let l: bnr = bufnr (' %' )
164+ if getbufvar (l: bnr , ' &buftype' ) !=# ' terminal'
165+ return
166+ endif
167+
168+ " Use + register (system clipboard) if available, fallback to * or default.
169+ let l: reg = has (' clipboard' ) ? ' +' : ' "'
170+ let l: text = getreg (l: reg )
171+ if empty (l: text ) && l: reg == ' +'
172+ let l: text = getreg (' *' )
173+ endif
174+
175+ if ! empty (l: text )
176+ call term_sendkeys (l: bnr , l: text )
177+ endif
178+ endfunction
179+
160180" Create a brand-new Claude Code terminal.
161181function ! s: create_new (instance_id) abort
162182 call claude_code#util#debug (' terminal: creating new instance for ' . a: instance_id )
0 commit comments