kyapwc profile picture

kyapwc

Visit Website

Vim onoremap option

Alright guys, back to another feature that vim has to offer! Recently, I’ve been using :vert term <command> for some short commands to run instead of using :sh command and found that they have a mapping known as tnoremap which basically stands for Terminal Normal Remap.

I dived into the help for tnoremap and found a much more awesome option vim had which was onoremap!

It basically allows vimmers to define their own test objects, as an example: instead of doing:

nnoremap ciq ci'

we can do:

onoremap iq i'

The onoremap automatically makes it so that you can run diq, ciq, yiq and so on! Super fluent way of having a shortcut for the quote/'! It basically allows you to self-define your text objects which is kind of sweet!

In my .vimrc right now, I have:

onoremap iq i'
onoremap iQ i"
onoremap aq a'
onoremap aQ a"
onoremap , t,

This brings a whole lot of new functionalities that I never knew before this! so, d, gives the command of dt, or y, gives yt,

It is a little bit useful but overall the quote onoremap is the best use I have of it so far!

Try it out and let me know your onoremaps!

Tags: vim

Breakindent Option in Vim

So, another vim post! Vim has a new option to set now that very little people talk about and it is the set breakindent option.

You know how we use set wrap? And the code just wraps into multiple lines? There’s a slight visual problem(for some people) there, whereby the 2nd line of wrapped at the 0 position of that line.

With set breakindent, the wrap will auto indent itself! The examples don’t make much sense as I can’t think of a code snippet to write at the moment, so, as ridiculous as it is, please ignore it.

Example without breakindent:

if (imagine_a_super_long_text........
....still_continuing....)

Example with breakindent:

if (imagine_a_super_long_text.....
    ....still_continuing...)

This is just a small visual issue most people can just turn a blind eye to, but if you’re interested, try it out!

Tags: vim

Opening URLs in vim

So, today I got curious as there was a file with multiple urls for me to choose from and I was thinking that using cmd+click on iTerm seems like a hassle..

I then learned of the gx keybinding which opens the URL under the current cursor! It is such a useful keybinding.

It uses the open shell command

An example inside example.html file:

<a href="www.google.com">Click Me!</a>

By having your cursor on the www.google.com, just press gx and it’ll use your default browser to open the URL! As simple as it can get!

Tags: vim

Vi Mode in any shell (Zsh, Fish and even Bash!)

VI Mode in any shell

Assuming that you love using VIM and the terminal, here’s a cool mode that can be activated on Zsh or any shell rather. (I am using Zsh, so, I will talk about it)

Enable vim mode on Zsh by adding this line into your .zshrc.
bindkey -v
Basically this means to enable vim mode

When this is enabled, refresh your shell and you can insert texts after pressing i and if you want to run any text-object related moves, just press Esc and the normal hjkl, b, w, ciw, diw, ^, 0, $ will work! Exactly like in vim!