vim
Configuration
Install vim-plug
by running the following command.
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
MacVim can share the same settings with vim, and also can use .gvimrc to set addtional GUI features.
Basic usage
C-w
means CTRL-W
C-ww
means CTRL-W_CTRL-W
C-w_c
means CTRL-W_c
Open vim
vi -m <file>
vi -d <file1> <file2>
<cmd> | vi -
Normal mode
insert
i I a A o O c{motion} {num}{insert}
motion
h j k l
w b e ge f F t T ; ,
0 ^ $ %
{ }
gg G
:{num} {num}gg
C-o C-i C-oo
[[ ]] [] ][
m{a-zA-Z} '{a-zA-Z0-9} g; g, '. '' '^
iw is ip i] i[ i) i( i> i< it i} i{ i" i' i`
aw as ap a] a[ a) a( a> a< at a} a{ a" a' a`
[c ]c
pattern
gd gD
/ ? n N gn gN
scrolling
C-e C-y C-d C-u C-f C-b
zz zt zb
undo
u U C-r
:earlier 4m :later 55s
:ea 1f
fold
zf zd zD zE
za zA zo zO zc zC zR
[z ]z zj zk
change
y yy Y p P
:reg "{a-zA-Z0-9.%#:-"*+}
x X {num}x
d dd D {num}d d{motion}
<< >> :ce :le :ri
J gq{motion} gw{motion}
g~{motion} gu{motion} gU{motion}
C-a C-x g<space>C-a g<space>C-x
:%s/old/new/g :%s/old/new/gc :10,20 s/^/ /g
:%s/pattern//gn
:ret :%ret!
:sort
r R
v V v{motion}
do dp
spell
:setl spell!
]s [s zg zug zG zuG zw zuw zW zuW z=
windows
:e :bn :bp :bd :b {bufname}
:w :wq :x ZZ :q! :e!
:vs C-w_v :sv C-w_s
C-w_w C-w_{hjkl} C-w_{HJKLrx} :clo C-w_c :only C-w_o
C-w_{+-<>=} C-w_{_|}
:tabe :tabc :tabo gt gT :tabs :tabm
:Lex
options
:set <option>! :set <option> :set no<option>
:set ic!
:set ma!
:set nu!
:set paste!
:set wrap!
vim -x filename :X :set key=
:h 42
Insert mode
<Esc> C-[ C-c C-o
C-{npye}
Visual mode
u U
> {num}> < {num}<
:'<,'>s/old/new/g
gC-g
gC-a
Troubleshooting
Onivim
- Holding down a key doesn’t repeat it (on 0.3.9 with osx)
Run the following command in terminal.
defaults write com.extropy.oni ApplePressAndHoldEnabled -bool false
Neovim
-
Install with Homebrew
brew install python brew install neovim /opt/homebrew/bin/pip3 install -U pynvim --break-system-packages
-
Migrate from vim
Runing the following commands to share the same configuration with vim.
mkdir -p ~/.config/nvim ln -s ~/.vimrc ~/.config/nvim/init.vim ln -s ~/.gvimrc ~/.config/nvim/ginit.vim mkdir -p ~/.local/share/nvim ln -s ~/.vim ~/.local/share/nvim/site echo "let g:python3_host_prog='<brew-path>/bin/python3'" >> ~/.vimrc
vim 8
-
mac
brew install vim --with-override-system-vi --with-lua
-
Build vim on Centos
solarized dark
-
Terminal.app
Just use this configuration: solarized-dark.terminal
Add
export TERM=xterm-256color
to.bashrc
or.bash_profile
-
Putty
Import solarized_dark.reg
Connection -> Data -> Terminal-type string: xterm-256color
Window -> Colours -> Allow terminal to use xterm 256-color
Window -> Appearance -> Font: Menlo, 11 point
Plugins
coc.vim
Prerequisites:
brew install node
brew install yarn
npm install -g neovim
For vim-plug users:
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Install extensions with :CocInstall coc-json coc-python
.
coc extensions I’m using:
coc-clangd
coc-cmake
coc-css
coc-git
coc-html
coc-imselect
coc-json
coc-python (deprecated)
coc-pyright
coc-sh
coc-tsserver
coc-vimlsp
coc-vimtex
YouCompleteMe
One may confront this error: NoExtraConfDetected: No .ycm_extra_conf.py file detected, so no compile flags are available. Thus no semantic support for C/C++/ObjC/ObjC++.
when install YCM with clang support. Here are some tips for install YCM with python2 or python3.
- Do not use python of conda, confirming by
which python
.- For python2, use
/usr/bin/python
. - For python3, use
/usr/local/bin/python3
.
- For python2, use
- Compile YCM.
cd ~/.vim/plugged/YouCompleteMe
- For python2,
python install.py --clang-completer
- For python3,
python3 install.py --clang-completer
- For python2,
- Use the example config file.
cp ~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm
vimtex
different engines
%! TEX program = pdflatex
%! TEX program = xelatex
One may manually reload vimtex in order to reset the program by <localleader>lx
root files
%! TEX root = /path/to/main.tex
backward search
Skim Perference => PDF-TeX Sync Support
- neovim
- Install the python modules pynvim and neovim-remote with brew’s pip3 (e.g.,
pip3 install pynvim neovim-remote
). - Set
let g:vimtex_compiler_progname='nvr'
in yourinit.vim
. -
Set Skim sync options to:
Preset Custom Command nvr
Arguments --remote +"%line" "%file"
Then backward search should work from both terminal neovim or the vimr GUI (or any other GUI).
IMPORTANT: Skim must be started by vimtex (either through compiler callback or explicitly via
<leader>lv
) for backward sync to work! (This is how Skim “knows” which neovim instance – terminal or GUI – to sync to.)- Hold down the
shift
andcommand
key and click on a point in the PDF document.
- Install the python modules pynvim and neovim-remote with brew’s pip3 (e.g.,
-
MacVim
Preset Custom Command mvim
Arguments --remote-silent +"%line" "%file"
LeaderF
If leaderF doesn’t respond, you can run :checkhealth
in neovim to see whether pynvim
has been properly installed.
:LeaderFunction
needs brew install ctags
.
:LeaderfRgInteractive
needs brew install rg
.
vim-grammarous
This plugin relies on LanguageTool which needs java to be excatuable.
To do so, a Mac user can install java
with brew
and add /usr/local/opt/openjdk/bin
to the PATH
.
markdown-preview.nvim
~/.vim/plugged/markdown-preview.nvim/app/install.sh
Advanced Topics
Open Neovim from Finder of Mac
Automator => New Document => Application => Run AppleScript =>
on run {input, parameters}
try
set filename to POSIX path of input
on error
set filename to "Desktop/" & (do shell script "date -u +%m%d%H%M%S") & ".txt"
end try
set myEditor to "/usr/local/bin/nvim"
set myCmd to myEditor & " " & quote & filename & quote & " &&exit"
tell application "iTerm"
create window with default profile
tell current session of current window
write text myCmd
end tell
end tell
return input
end run