<commit_before>---
permalink: /vim/
layout: single
title: "Vim Cheatsheet"
---

<hr>

### Add line above or below a certain character  
_For example, add a new line above/below every comment in code_  
:g/key/norm o<em>whatever you want</em>  
(just leave "whatever you want" blank and use a capital O to add the line above!)  
[source](https://stackoverflow.com/questions/9027159/search-for-string-and-add-line-in-vi-vim) also: [all about the normal command](http://learnvimscriptthehardway.stevelosh.com/chapters/29.html)
<commit_msg>updated vim cheatsheet<commit_after>---
permalink: /vim/
layout: single
title: "Vim Cheatsheet"
---

<hr>

### Add line above or below a certain character  
_For example, add a new line above/below every comment in code_  
{% highlight vim %}
:g/key/norm o<em>whatever you want</em>  
{% endhighlight %}
(just leave "whatever you want" blank and use a capital O to add the line above!)  
[source](https://stackoverflow.com/questions/9027159/search-for-string-and-add-line-in-vi-vim) also: [all about the normal command](http://learnvimscriptthehardway.stevelosh.com/chapters/29.html)

### Regex match start of line only
Just add ^ to the start of the search. (Works well with the above normal command!) eg:  
{% highlight vim %}
:g/^echo/norm Oecho.
{% endhighlight %}
(this adds a newline echo above every echo command in the batch file.)
{'fraction_non_alphanumeric': 0.12290909090909091, 'fraction_numerical': 0.01309090909090909, 'mean_word_length': 4.231939163498099, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '172903', 'n_tokens_mistral': 473, 'n_tokens_neox': 437, 'n_words': 155}