How to write functions in vim that can be interacted with on the command line?
phpcn_u1582
phpcn_u1582 2017-05-16 16:38:35
0
1
586

nnoremap <leader>c :Ack '^class ' <c-r>=&path<cr><home><right><right><right><right>< ;right><right><right><right><right><right><right><right>

The general idea is to use Ack to search for pattern.

under the &path path.

The n*<right> in this mapping is so ugly. How can it be optimized?

After help from the community, I put the final method below:

" help input

function! AckClass()
    let l:classPattern = input('Pattern: ')
    execute " Ack '^class " . l:classPattern . "' " . &path
endfunction

command! AckClass call AckClass()
phpcn_u1582
phpcn_u1582

reply all(1)
PHPzhong

I don’t know how far you want to interact

function! ChangeFileencoding()
    let encodings = ['GB18030', 'GBK', 'cp936', 'utf-8', 'big5', "latin1", "euc-kr", "euc-jp", "ucs-bom", "shift-jis"]
    let prompt_encs = []
    let index = 0
    while index < len(encodings)
        call add(prompt_encs, index.'. '.encodings[index])
        let index = index + 1
    endwhile
    let choice = inputlist(prompt_encs)
    if choice >= 0 && choice < len(encodings)
        execute 'e ++enc='.encodings[choice].' %:p'
    endif
endf

This is my vimrc function that changes the encoding and opens the file. It will display a list of options for your reference

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template