nimgrep.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. =========================
  2. nimgrep User's manual
  3. =========================
  4. :Author: Andreas Rumpf
  5. :Version: 1.6.0
  6. .. default-role:: option
  7. .. contents::
  8. Nimgrep is a command line tool for search and replace tasks. It can search for
  9. regex or peg patterns and can search whole directories at once. User
  10. confirmation for every single replace operation can be requested.
  11. Nimgrep has particularly good support for Nim's
  12. eccentric *style insensitivity* (see option `-y` below).
  13. Apart from that it is a generic text manipulation tool.
  14. Installation
  15. ============
  16. Compile nimgrep with the command:
  17. .. code:: cmd
  18. nim c -d:release tools/nimgrep.nim
  19. And copy the executable somewhere in your ``$PATH``.
  20. Command line switches
  21. =====================
  22. .. include:: nimgrep_cmdline.txt
  23. Examples
  24. ========
  25. All examples below use default PCRE Regex patterns:
  26. + To search recursively in Nim files using style-insensitive identifiers:
  27. .. code:: cmd
  28. nimgrep --recursive --ext:'nim|nims' --ignoreStyle
  29. # short: -r --ext:'nim|nims' -y
  30. .. Note:: we used `'` quotes to avoid special treatment of `|` symbol
  31. for shells like Bash
  32. + To exclude version control directories (Git, Mercurial=hg, Subversion=svn)
  33. from the search:
  34. .. code:: cmd
  35. nimgrep --excludeDir:'^\.git$' --excludeDir:'^\.hg$' --excludeDir:'^\.svn$'
  36. # short: --ed:'^\.git$' --ed:'^\.hg$' --ed:'^\.svn$'
  37. + To search only in paths containing the `tests` sub-directory recursively::
  38. .. code:: cmd
  39. nimgrep --recursive --includeDir:'(^|/)tests($|/)'
  40. # short: -r --id:'(^|/)tests($|/)'
  41. .. Attention:: note the subtle difference between `--excludeDir`:option: and
  42. `--includeDir`:option:\: the former is applied to relative directory entries
  43. and the latter is applied to the whole paths
  44. + Nimgrep can search multi-line, e.g. to find files containing `import`
  45. and then `strutils` use pattern `'import(.|\n)*?strutils'`:option:.