2025年8月4日 星期一

NVIM key mapping

 To determine if a keymap is bound in Neovim, or to see what a specific key or key combination is mapped to, several methods can be employed:

  • Using the :map command (and its variants):
    • :map: Lists all mappings in all modes.
    • :nmap: Lists mappings specifically for Normal mode.
    • :vmap: Lists mappings for Visual mode.
    • :imap: Lists mappings for Insert mode.
    • :cmap: Lists mappings for Command-line mode.
    • To check a specific key, append it to the command, e.g., :map <Leader>s to see what <Leader>s is mapped to.
  • Using verbose map:
    • To see where a mapping was defined (e.g., in a plugin or your init.vim), use verbose map followed by the key or key sequence. For example, :verbose map <C-s> will show the mapping and the file it originated from.
  • Using mapcheck():
    • The mapcheck() function can be used in a script or on the command line to programmatically check if a mapping exists for a given key sequence. For example, :echo mapcheck('<C-s>') will return a non-empty string if a mapping exists for <C-s>.
  • Using maparg():
    • To get detailed information about a specific mapping, including its right-hand side (rhs), use maparg()For instance, :echo maparg('<Leader>f', 'n') will return a dictionary containing information about the <Leader>f mapping in Normal mode.
  • Using the WhichKey plugin:
    • Plugins like folke/which-key.nvim provide a visual way to explore keymaps. As you type a key sequence, a popup appears showing the available mappings that start with those keys, making it easy to discover what a key is bound to.
These methods provide comprehensive ways to inspect and understand key bindings within your Neovim environment.

沒有留言: