vi -c "au VimEnter * <command>"
vim-execute-command-after-multiple-files-loaded
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab
tab-key-4-spaces-and-auto-indent-after-curly-braces-in-vim
Go to line #4, use Ctrl-v to blockwise select the first character, go down 4 lines, press Shift i, enter 0 (this is 0, followed by Space) and Esc to exit insert mode.
Now use gv to re-select the previously selected area. Press g Ctrl-a to create a sequence.
I start with a 0 here, so I can re-select by gv. If you start with a 1, you need to re-select by hand while omitting the first 1.
Use 2g Ctrl-a to use a step count of 2.
how-to-generate-a-number-sequence-in-file-using-vi-or-vim
gg=G
auto-indent-format-code-for-vim
https://stackoverflow.com/questions/1005/getting-root-permissions-on-a-file-inside-of-vi
the equivalent to Ctrl+W L is :winc l.
how-can-i-work-with-splits-in-vim-without-ctrl-w
:syn clear Repeat | g/^\(.*\)\n\ze\%(.*\n\)*\1$/exe 'syn match Repeat "^' . escape(getline('.'), '".\^$*[]') . '$"' | nohlsearch
how-can-i-mark-highlight-duplicate-lines-in-vi-editor
:set ft=sql
参考:what-is-the-between-set-ft-and-setfiletype
While in insert mode or command mode (the : prompt at the bottom of the editor), type CTRL + V then TAB.
Using CTRL + V signals Vim that it should take the next character literally. Even in insert mode.
UPDATE:
As noted by Herbert Sitz, if gVim is in Windows mode (default), you must use CRTL + Q in place of CTRL + V.
参考:how-can-i-insert-a-real-tab-character-in-vim
:n1,n2y
例如: `:2,5y` #复制第2行到第5行
:n1,n2d
例如: `:2,5d` #删除第2行到第5行
参考:https://linoxide.com/linux-how-to/how-to-delete-line-vim-linux/
https://stackoverflow.com/questions/15069613/how-to-copy-by-specifying-line-numbers-in-vi
set wrap
set nowrap
参考:https://stackoverflow.com/questions/2280030/how-to-stop-line-breaking-in-vim
ctrl + v
参考:https://superuser.com/questions/208852/how-to-select-a-rectangular-range-in-vim
可以通过调用delete的default register实现
:display #显示delete cycle环的内容
"2P #引用(")display列表中第二条(2)的内容,粘贴到当前位置之前(P)
"2p #引用(")display列表中第二条(2)的内容,粘贴到当前位置之后(p)
参考: https://stackoverflow.com/questions/17013750/vim-pasting-scroll-through-previously-yanked-text
http://vimdoc.sourceforge.net/htmldoc/undo.html#redo-register
:g/^$/d
参考:https://stackoverflow.com/questions/1807570/vim-delete-empty-lines-within-a-visual-selected-area
:g/word/normal 2dd
This finds all instances of word and then executes the command after it. In this case it executes 2dd in normal mode
参考:How to delete all lines matching a pattern and a line after in Vim
:%j
#多变单
参考:https://stackoverflow.com/questions/6577508/how-to-merge-multiple-lines-into-one-line-in-vim
:%s/split character/\r/g
#单变多
参考:https://stackoverflow.com/questions/71323/how-to-replace-a-character-by-a-newline-in-vim
:sort u
参考:https://stackoverflow.com/questions/351161/removing-duplicate-rows-in-vi
用v模式选择以后执行检索是会自动设定检索范围为v模式选择内容
参考:https://stackoverflow.com/questions/773137/find-and-replace-within-selection-in-vi
:%s/\s\+$//
#通过匹配空格进行删除,主要要用$来限定到行尾,同样可以通过^来限定到行首实现删除行首空格
参考: https://stackoverflow.com/questions/3474709/delete-all-spaces-and-tabs-at-the-end-of-my-lines
:bd
#删除当前buffer,在打开多个buffer的情况下比较实用
how-do-i-close-a-single-buffer-out-of-many-in-vim
:reg #查看所有宏
:let @a = '' #删除所有宏,注意等号两边有空格
q #开始记录宏
qa #开始记录宏,并保存到快捷键a上
@a #执行宏,a为上面命令保存的快捷键
qb #开始记录宏,并保存到快捷键b上
@b #执行宏,b为上面命令保存的快捷键
clear-all-currently-defined-vim-macros
:e ++enc=utf-8
set autowriteall
set awa
automatically-save-the-current-buffer-when-is-going-to-edit-a-new-file
:args myfile
:args **/myfile
myfile可以支持正则表达式
how-to-open-files-with-pattern-recursively-in-vim
1.拷贝文本
2.按ctrl+r键
3.然后输入”
how-to-copy-yanked-text-to-vi-command-prompt
find . -iname '*.java' -exec vim -p {} +
上面命令,可以用标签的方式打开当前目录及子目录下所有的java文件
why-is-my-find-not-recursive how-can-i-recursively-find-all-files-in-current-and-subfolders-based-on-wildcard
:w !sudo tee %
:w – write
!sudo – call shell sudo command
tee – the output of write (:w) command is redirected using tee
% – current file name
how can i save a file i opened in vim as the wrong user
j,k,l,h下上右左
:n 跳转到第n行
nG 跳转到第n行
i进入插入模式
a进入插入模式光标定位到当前字符后面
Esc返回命令模式
按冒号进入命令输入窗口
大多数操作前加上数字n都表示重复该操作n次
yy 复制当前行
dd 删除当前行
x 删除光标后字符
p 粘贴,将复制的文本插入到光标所在位置之后
P 粘贴,将复制的文本插入到光标所在位置之前
u 撤销
:set number显示行号
:/word 检索word,然后按n检索一下个匹配项
:?word 向前检索word
:%s/word/newword替换
:n跳转到第n行
dd+p交换行
yy+p复制行
命令模式下按G跳转到页面最后