2

I've been learning Vi/Vim for some month and, at the moment, I'm editing many files at once splitting the window, jumping from one buffer to the others. I find it very useful.

One thing I don't like is when I have to execute commands in the shell from within vim. I use, for example :!make. This is easy to do. But when I have to run some executable I'd like to use command completion regardless of the case of the letters of the name. For instance, suppose I have to run an MPI program with :!mpirun -np 8 Convection1D; actually I'm not so fast in typing the parts :! and -np, but I could save time by using command completion for the name of the executable. The obstacle is the capital letter (or letters); it'b be very good if I was allowed to type :!mpir<tab> -np 8 con<tab><enter> (especially considering that I can press tab repeatedly to view successive completions).

  • 1
    " I use, for example :!make. This is easy to do" -- you may find the built-in :make command useful. – mMontu Apr 12 '16 at 17:39
4

Assuming that Convection1D is a file name, you can use the wildignorecase setting, which will Vim ignore case when completing file names and directories. This is available since Vim 7.3.075.

Also note you can use :!! to repeat the last :! command, which may be useful for you.

4

You can define a new command like :E instead of :! and write a custom completion function for it (see :help :command).

command! -nargs=+ -complete=custom,s:CustComp E execute "!" . "<args>"

with the function

function! <SID>CustComp(ArgLead, CmdLine, CursorPos)
    let l:current = split(a:CmdLine, '\s\+', 1)
    if len(l:current) == 2
        return system("compgen -ac")
    else
        let l:ls = split(system("ls"), "\n")
        return join(filter(ls, join(['v:val =~? "', a:ArgLead, '"'], '')), "\n")
    endif
endfunction

This assumes you are using bash, if you are using something different you need to substitute the call to compgen (including the flags of course) by some other program that list all possible commands for the given shell.

Now you can instead use :E mpir<tab> -np 8 con<tab><enter> and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.