-O split -o tabs +linenumber +/match
Outside vim, we can do some cool magic to open vim in a way we want to use it.
I’m not talking about fancy flags to alter how
init.lua will be loaded, more about how to open vim at the right spot.
We can open multiple files, all specified files will be loaded as a buffer. No magic and a lot of people don’t even know they opened multiple files.
# Open vim with two files. ❯ vim afile bfile # Now if we list buffers we can see both of them. :ls 1 %a "afile" line 1 2 "bfile" line 0
While I’m working on something and I don’t have a vim already open, the best way to start vim for me is to open the file and the corresponding test file in a nice even split.
❯ vim -O afile bfile
With this, we end up with a 50-50 vertical split, left side
afile and right
-o we get the same but horizontal.
Some people like opening tabs and switch between tabs. I did not meet a case
when it was useful for me, but it does not mean it’s useless. With
-p we can
open specified files as tab pages.
Maybe one of the lesser known options is the
-) which executes a
command on start-up. We can specify more than one.
+: Executes after configuration and the first file is loaded.
-: Executes before any configuration.
Why is it good? We can do a lot of things with it, but maybe the most useful would be to specify a line number, or open the file at the fist match for an expression.
# Open file and place the cursor at line 33. ❯ vim file +33 # Open file and place the cursor to the first match on errro to fix this typo. ❯ vim file +/errro
We can go to the extremes with using substitution and quit vim.
❯ vim afile +"%s/old/new/g" +wq
But please use
sed -i for that instead.
2021-12-14 00:00 +0000