marks.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Mark text on screen
  2. ---------------------
  3. kitty has the ability to mark text on the screen based on regular expressions.
  4. This can be useful to highlight words or phrases when browsing output from long
  5. running programs or similar. Lets start with a few examples:
  6. Examples
  7. ----------
  8. Suppose we want to be able to highlight the word :code:`ERROR` in the current
  9. window. Add the following to :file:`kitty.conf`::
  10. map f1 toggle_marker text 1 ERROR
  11. Now when you press :kbd:`F1`, all instances of the word :code:`ERROR` will be
  12. highlighted. To turn off the highlighting, press :kbd:`F1` again.
  13. If you want to make it case-insensitive, use::
  14. map f1 toggle_marker itext 1 ERROR
  15. To make it match only complete words, use::
  16. map f1 toggle_marker regex 1 \\bERROR\\b
  17. Suppose you want to highlight both :code:`ERROR` and :code:`WARNING`, case
  18. insensitively::
  19. map f1 toggle_marker iregex 1 \\bERROR\\b 2 \\bWARNING\\b
  20. kitty supports up to 3 mark groups (the numbers in the commands above). You
  21. can control the colors used for these groups in :file:`kitty.conf` with::
  22. mark1_foreground red
  23. mark1_background gray
  24. mark2_foreground green
  25. ...
  26. .. note::
  27. For performance reasons, matching is done per line only, and only when that
  28. line is altered in any way. So you cannot match text that stretches across
  29. multiple lines.
  30. Creating markers dynamically
  31. ---------------------------------
  32. If you want to create markers dynamically rather than pre-defining them in
  33. :file:`kitty.conf`, you can do so as follows::
  34. map f1 create_marker
  35. map f2 remove_marker
  36. Then pressing :kbd:`F1` will allow you to enter the marker definition and set it
  37. and pressing :kbd:`F2` will remove the marker. :ac:`create_marker` accepts the
  38. same syntax as :ac:`toggle_marker` above. Note that while creating markers, the
  39. prompt has history so you can easily re-use previous marker expressions.
  40. You can also use the facilities for :doc:`remote-control` to dynamically add or
  41. remove markers.
  42. Scrolling to marks
  43. --------------------
  44. kitty has a :ac:`scroll_to_mark` action to scroll to the next line that contains
  45. a mark. You can use it by mapping it to some shortcut in :file:`kitty.conf`::
  46. map ctrl+p scroll_to_mark prev
  47. map ctrl+n scroll_to_mark next
  48. Then pressing :kbd:`Ctrl+P` will scroll to the first line in the scrollback
  49. buffer above the current top line that contains a mark. Pressing :kbd:`Ctrl+N`
  50. will scroll to show the first line below the current last line that contains
  51. a mark. If you wish to jump to a mark of a specific type, you can add that to
  52. the mapping::
  53. map ctrl+1 scroll_to_mark prev 1
  54. Which will scroll only to marks of type 1.
  55. The full syntax for creating marks
  56. -------------------------------------
  57. The syntax of the :ac:`toggle_marker` action is::
  58. toggle_marker <marker-type> <specification>
  59. Here :code:`marker-type` is one of:
  60. * :code:`text` - Simple substring matching
  61. * :code:`itext` - Case-insensitive substring matching
  62. * :code:`regex` - A Python regular expression
  63. * :code:`iregex` - A case-insensitive Python regular expression
  64. * :code:`function` - An arbitrary function defined in a Python file, see :ref:`marker_funcs`.
  65. .. _marker_funcs:
  66. Arbitrary marker functions
  67. -----------------------------
  68. You can create your own marker functions. Create a Python file named
  69. :file:`mymarker.py` and in it create a :code:`marker` function. This function
  70. receives the text of the line as input and must yield three numbers,
  71. the starting character position, the ending character position and the mark
  72. group (1-3). For example:
  73. .. code-block::
  74. def marker(text):
  75. # Function to highlight the letter X
  76. for i, ch in enumerate(text):
  77. if ch.lower() == 'x':
  78. yield i, i, 3
  79. Save this file somewhere and in :file:`kitty.conf`, use::
  80. map f1 toggle_marker function /path/to/mymarker.py
  81. If you save the file in the :ref:`kitty config directory <confloc>`, you can
  82. use::
  83. map f1 toggle_marker function mymarker.py