my own vim memo

1 minute read

This post just tries to summarize some frequently used vim commands that I can not remember (which is unforuante):

Copy matched search result to a different buffer

qaq " what this does is to clear the content of the register 'a'
:g/pattern/y A " what this does is to copy the search result to register 'a'
:tabnew "create a new tab
"ap "paste the content of register 'a' to the current buffer

Append characters at the end of lines

# assume you just want to append a ',' at the end of each line
:%s /$/,/

Surround each line with double quotes

:%s /.*/"&"/

Swap matched gruops

e.g. you have a string like a -> b, and want to swap it to b -> a

What you need to do is:

:%s /\(\w*\) -> \(\w*\)/\2 -> \1/g

Note: what’s tricky here is that you have to escape ‘(,)’ using ‘'

YouCompleteMe

YouCompleteMe is a fantastic vim plugin that help you write code more easily.

Here is the command I typically use to build the library:

cd ~/.vim/plugged/YouCompleteMe
./install.sh --tern-completer

Spell check

:set spell
:set spell spelllang=en
:set nospell
]s move to next error
[s move to previous error
z= suggest a list of alternatives
zg add the current word to dictionary
zug cancel dictionary update

CtrlP commands

Change the root folder used by CtrlP:

CtrlPDir=~/abc

termguicolors doesn’t work on MacOS’s built-in terminal.app

I ran into this when I tried to use the built-in Terminal.app from MacOS. And I noticed no colors are rendered in it when I open any files in it. And after remove the termguicolors option from vimrc/init.vim, the synthax highlight comes back.

And a related discussion can be found here: https://stackoverflow.com/questions/58674310/nvim-in-macos-terminal-breaks-on-displaying-termguicolors

MacVim settings

There are some special(weird) settings about MacVim, which has made me so confused. e.g. to set the font size or colorscheme, the settings you have in .vimrc don’t work as you expect. The reality is that you have to configure those in .gvimrc instead of .vimrc. Take a look at this .gvimrc for what the settings look like.

Updated:

Comments