Call to a shared object by key sequence from vi / Vim

I have a shared library (in binary form, I have a source) that I use to invert / loop between characters in the source files in Visual Studio.

I would like to be able to use the same functionality in vi and / or Vim.

In particular, I would like to make the following scenario:

  • the cursor is on the word
  • I press a sequence of keys, for example. CTRL-I
  • vi / vim is developing the whole word i'm on.
  • vi / vim calls my shared library, passes the word and gets an invert / loop replacement
  • vi / wim replaces the original word with a new word

I have no clue if / how to get vi / Vim to do this, and I have no search for good luck.

Any advice gratefully received ...

+3
3

Try

inoremap <C-i> <esc>"hciw<C-R>=libcall('path/to/your.dll', 'func', @h)<CR>

:

  • < Ctrl + >
  • < & ESC GT; "hciw h
  • < C-r >=
  • libcall (...) .
  • @h - "h".

, ,

inoremap <C-i> <esc>"hciw<C-R>=substitute(system('mybin --word='.@h), "\n", '', 'g')<CR>
+6

, vim, python , vim 7, , python script vim.
, , python:

:version

vim, ; python, "+ python" - ( "-python" ). python, , vim python.

python , :

python << EOF
import vim
import MySharedLibraryPythonBinding

def MyFunction():
    # get word under cursor
    x = vim.eval('expand ("<cword>")')
    # get replacement
    MySharedLibraryPythonBinding.GetReplacement(x)
    # replace contents (you'll need some work here...)
    vim.current.line = "add something sensible here..."
EOF

nmap <F3> :py MyFunction( expand("<cword>") )<CR>

, , , , .

+1

(: h expand(),...). )

:nnoremap triggerkeysequence ciw<c-r>=libcall('path/to/your.dll', 'your_function',@")<cr>

BTW: <c-i>- <tab>, are you sure you want to cancel the action on this key?

+1
source

Source: https://habr.com/ru/post/1704803/


All Articles