0

Clarification of the moving parts

First, let me clarify what I mean by "Window Title", and what I expect to achieve

  • On Windows OS, GUI programs will have three attributes: its Window Title texts, the process.exe name and its win-class name. An example of Gvim ran through Xming looks like the following: enter image description here

    • Window Title: [No Name] - - GVIM1
    • win-class name: Xming X
    • Process Name: Xming.exe
  • I am looking for a way to start Vim, so that:

    • Instead of reporting FileName -- GVIM1 as its "Win-Title", it also reports, either:
    • Filename -- GVIM1 - Insert-mode OR Filename -- GVIM1 - Normal-mode, depending on the current state of Vim.

Please advise if there is a better way to have Vim dynamically update its "Title".

Explanation

At the end of the day, I would like to detect the precise Vim mode through its "Window Title". This opens new doors for re-mapping indistinguishable pairs of keys, like <tab> and <c-i>.

For example, through AutoHotKey, which runs on Windows OS, I can happily assign <tab> (in normal mode) to a particular command-line function, while keeping <c-i> behaving "normally" (go to the next position on the jump list). AutoHotKey detects WinTitle by default and will need a lot more effort to conduct real-time OCR on the dynamic Window of Gvim, to tell its current mode. Blindly remapping the <tab> key will distort the normal usage of <tab> key in Insert-mode.

Please advise if this is achievable, as it is funny to learn that <tab> and <c-i> are identical keys in the year 2019 :)

Motivation and cross-reference (TL;DR)

Things start from this post about Vimwiki, where I re-learned that <c-i> and <tab> are indistinguishable by the Modern Vim. This brings conflict in my hard-to-change muscle memory. For the mappings in normal mode:

  • <c-i> should take me to the more recent position in the jump list (opposite of <c-o>), and
  • <tab> should handle its own business:
    • For Vimwiki, <tab> jumps to the next hyperlink, and <s-tab> jumps to the previous hyperlink
    • For other filetypes, I do not press <tab> key in normal mode.

I tend to spend a considerable amount of time in Markdown documents, and I rely on Vimwiki to nativage the stacks of Markdown files. (I maintain two websites + one personal wiki with more than 2,000 entires.)

At the end of the day, I would like to "split" the functionality of <tab> and <c-i> ==> In Normal-mode, pressing <tab> shall issue :VimwikiNextLink<CR> and <c-i> shall bring me to the next point in the Jump list.

Since it is well established that <tab> and <c-i> are treated alike by Vim, I am planning to use AutoHotKey to overwrite the <tab> key only in Normal Mode. This is where all dots should connect: through a title-matching trick in AutoHotKey, <tab> is only mapped to :VimwikiNextLink<CR> in normal mode.

Given the tweak on the titlestring option, I see the light of distinguishing modes.

3
  • Why would reporting vim's mode in the window title have any effect on whether or not you can remap <tab> and <C-i> separately? I don't know what you're trying to do, but this seems really convoluted. It's probably going to be simpler to pick a different mapping, or maybe use an <expr> mapping. (Also for the record, tab and C-i are indistinguishable because they're literally the same ASCII value, 0x09)
    – DJMcMayhem
    Commented Feb 4, 2019 at 21:28
  • Here goes my rationale: should a third-party hotkey manager (AutoHotKey) tell the precise Vim-mode, it can "overwrite" the <tab> key in normal mode, and leave <c-i> untouched. Thus, the two keys are then distinguished. Let me update my original post for the missing motivation piece.
    – llinfeng
    Commented Feb 5, 2019 at 4:26
  • @DJMcMayhem, for now, the missing piece is to indicate whether Vim enters command-line-mode through the titlestring.
    – llinfeng
    Commented Feb 5, 2019 at 13:13

1 Answer 1

2

You can try

:set titlestring=%F\ %{v:servername}\ %{mode()}

this will indicate the mode as n rsp. i and some other characters as described in :help mode()

You can improve the last expression (%{mode()}) to something longer using a ?: construct.

4
  • This is fantastic! May I ask how to deal with the visual block? (Just curious). Otherwise, the single character i and n should be telling enough for me to identify the vim-modes through the title line :)
    – llinfeng
    Commented Feb 5, 2019 at 4:11
  • Update to the previous comment ==> This is fantastic! One more question: can Vim tell its title that the "active cursor" is at the command line? I am almost there :) It turns out that when I enter the Vim-command-line through :, nothing at the title changes
    – llinfeng
    Commented Feb 5, 2019 at 4:20
  • Seems like mode() does not support indicating being in command-line-mode
    – Naumann
    Commented Feb 5, 2019 at 13:01
  • Actually, mode() does support it. However it looks like for whatever reason, Vim does not update the title for entering command mode. Commented Feb 5, 2019 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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