How to see logs with out Esc and other gibberish stuff in logs ?

 So when you are trying to read logs, sometimes they look like this, using vim is okay at-least some readability, but less will show awful results. 

ESC[34m2023-04-15 04:33:57ESC[0m ESC[33m  TRACEESC[0m [ESC[36mApplicationESC[0m] ESC[37mpid: 562425ESC[0m

ESC[34m2023-04-15 04:33:57ESC[0m ESC[35m  DEBUGESC[0m [ESC[36mApplicationESC[0m] ESC[37minteractive: falseESC[0m

ESC[34m2023-04-15 04:33:57ESC[0m ESC[35m  DEBUGESC[0m [ESC[36mFileResolverESC[0m] ESC[37mSearching: /server/files ESC[0m

if you want to read logs clearly, then you can still use less command with -R flag.

less -R <log_file_name>


Hope it helps.

Thanks.

Raja

VIM: Binding a shortcut

 All this time, I do not know how to create my own VIM Bindings. And yes, trying yourself is the only way you learn anything.

I want to explain what I have learnt on creating a vim shortcut, so you might get a good headstart.

The command I am going to explain is as below


map <C-b> :w\|!ruby spec/example_spec.rb <cr>

so

  • map: is like you are mapping <custome_key> <series of actions>
  • <C-b>: this stands for CTRL+b 

If you want to use Shift, Alt, Cmd(Mac), yes VIM have options for all of that.

```

S-...>		shift-key			*shift* *<S-*

<C-...>		control-key			*control* *ctrl* *<C-*

<M-...>		alt-key or meta-key		*meta* *alt* *<M-*

<A-...>		same as <M-...>			*<A-*

<D-...>		command-key (Macintosh only)	*<D-*
```
Vim documentation: intro (sourceforge.net)
  • Then :w\|!ruby spec/example_spec.rb<cr>
    • :w is save
    • \|: is like you are joining this command with with another action.
    • !ruby spec/example_spec.rb
      • ! is for invoking shell commands, for example give :!uptime, you will see what I am saying.
      • ruby spec/example_spec.rb, you know its ruby command executing the file.
      • <cr>: This carriage return equal to <Enter> key, with out this, your command will be loaded but to execute you have to press enter again. so adding <cr> at the end, will help executing your command.

Based on above understanding, lets say you have a python file like service.py, you want to execute it with a VIM binding, you can use below command
map <C-r> :w\|!python service.py <cr>
so on CTRL+r, I will be running my python program.

Hope it helps.
Thanks
Raja