Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim language: send current word to CtrlP

Tags:

vim

ctrlp

I know how to use CtrlP. I type ctrl+p, then I start to write file name, ... and so on. But, ... I am very lazy developer. I want to directly send to CtrlP current word. I know how to get current word:

let l:currentWord = expand('<cword>')

In Vim Language, ... I How can I send l:currentWord to CtrlP?

map <F6>  :call ComposerKnowWhereCurrentFileIs()<CR>
function! ComposerKnowWhereCurrentFileIs()
    let l:currentWord = expand('<cword>')
    let l:command = "grep " . l:currentWord . " ../path/to/composer -R | awk '{print $6}' | awk -F\\' '{print $2}'"
    let l:commandFileFound = l:command . ' | wc -l'
    let l:numberOfResults = system(l:commandFileFound)
    if l:numberOfResults == 1
        let l:fileName = system(l:command)
        let l:openFileCommand = 'tabe /path/to/project' . l:fileName
        exec l:openFileCommand
    else
        echo "Too many files :-( - use CtrlP ;-) "
    endif
endfunction
like image 253
sensorario Avatar asked May 22 '15 07:05

sensorario


2 Answers

<C-P><C-\>w

See :h ctrlp-mappings. You may map this combination:

map <F6> <C-P><C-\>w

In a function:

exe "normal \<C-P>" . expand('<cword>')
like image 127
lollo Avatar answered Oct 13 '22 01:10

lollo


function! LazyP()
  let g:ctrlp_default_input = expand('<cword>')
  CtrlP
  let g:ctrlp_default_input = ''
endfunction
command! LazyP call LazyP()
nnoremap <C-P> :LazyP<CR>

(this could probably be simplified but I suck at vim syntax)

like image 36
Régis B. Avatar answered Oct 13 '22 01:10

Régis B.