qtvimqt-creator

How to set user command in Qt Fakevim?


(1) For example, I want to set map gd g* in Qt's Fakevim like below but failed. enter image description here

(2) And also I'd like to set F3 as the save command, how to do it?

(3) In Fakevim, it provides an option "Read .vimrc", but where to find the file .vimrc?


Solution

  • It doesn't look like there is a lot of documentation for FakeVim, so official sources might not exist. Most of this was obtained by experimentation.

    If you want to dig deeper, I guess there's no source as official as the actual source: http://qt.gitorious.org/qt-creator/qt-creator/blobs/0809986e501415fe2c8508800b94b5b3169dc048/src/plugins/fakevim/fakevimplugin.cpp

    User commands

    First off, realize that in Tools>Options>FakeVim>User Command Mapping, you're only setting what your user actions will perform, not how you perform them.

    By default, user command #1 is triggered by pressing Alt-V, then 1.

    Alt-V, then 2, triggers user action #2, and so on.

    You can change the keyboard shortcuts through the general QtCreator configuration interface, under Tools>Options>Environment>Keyboard. There is a "FakeVim" section with all the user actions listed. Select your user action of choice, press the little "erase" icon in the input field under "Shortcut", then press your desired shortcut key, which should appear in the input field.

    Second, to finish a command where you would normally press enter, you should literally type in <CR> after the commands. You also need to enter in ':' to enter command mode.

    So if you wanted to map the vim save command, ":w", to F3 via FakeVim, you would:

    Now, every time you're in the editor, you should be able to click F3 and have the FakeVim :w command execute, which will save your file.

    Note that there is also an option to set a shortcut for "Save" directly in the QtCreator keyboard settings, so for this particular shortcut you don't actually need to go through FakeVim.

    Setting shortcuts for other vim commands should be similar. Note that you're restricted to the subset of vim commands that FakeVim implements. Refer to the source, linked above, for checking any particular command you're wondering about.

    Vimrc file

    On Linux this would be ~/.vimrc, a file in the user's home directory. I presume you're asking about Windows.

    The best source I can find is this bug report about it being hard to use Fakevim's vimrc on Windows: https://bugreports.qt.io/browse/QTCREATORBUG-8748

    Following that, the file Fakevim looks for is ".vimrc" in %USERPROFILE% (you can enter a name like that in Explorer to go to the folder). However, it's tricky to access a file with a name like that on Windows. (Thus why the real vim uses '_vimrc' on Windows -- but FakeVim apparently doesn't, at least at the moment.)

    Here is a superuser page with workarounds for how to create such files on Windows: https://superuser.com/questions/64471/create-rename-a-file-folder-that-begins-with-a-dot-in-windows