Open rogerxu opened 7 years ago
u
- UndoU
- Undo all the changes on a lineCtrl-r
- Redo:q
- quitZZ
- save and exit:e!
- reload the original fileVim for a hyperlink is tag. Like *help.txt*
. The notation with "*" characters is used to define a tag.
Ctrl-]
- jump to tagCtrl-t
- pop tag, back to the preceding positionCtrl-g
- show a message for the current positionCtrl-o
- jump to older positionCtrl-i
- jump to newer position{char}
- find the character{char}
- find the character in backward{char}
- to the character{char}
- to the character in backward(
- sentence backward)
- sentence forward{
- paragraph backward}
- paragraph forward]]
- forward to next {
][
- forward to the next }
[[
- backward to the previous {
[]
- backward to the previous }
{num}
⇧g - go to line {num}
{num}
% - go to {num}
% of the fileCtrl-f
- scroll down a screenCtrl-b
- scroll up a screenCtrl-d
- scroll down half a screenCtrl-u
- scroll up half a screenCtrl-y
- scroll down a lineCtrl-e
- scroll up a linezz
- scroll current line at center of windowzt
- scroll current line at the topzb
- scroll current line at the bottom/string
- search for a string?string
- backward search for a string/string\>
- search for end with string
/\<string\>
- search for whole word string
?string
- search for a string in backward:grep error_string *.c
- search in filesn
- move to next search result, like F3
in AtomN
- move to previous search result*
- move to next occurrence under cursor, like Ctrl-F3
in Atom{num}*
- move to {num}
th occurrence#
- move to previous occurrenceCtrl
- O
- jump to older positionCtrl
- I
- jump to newer positionma
- mark as mark amb
- mark as mark b`a
- move to mark a'a
- move to the beginning of the line for mark a`0
- move to last exit positionoperator, the true power of Vim
i
- <object>
- insertI
- <object>
- start Insert mode and move the cursor to the first of the linea
- <object>
- append A
- <object>
- start Insert mode and move the cursor to the end of the linec
- <object>
- changed
- <object>
- delete~
- <object>
- change case of the character under the cursorv
- <object>
- visual selectcc
- change a linedd
- delete a linectrl
- a
- Add 1ctrl
- x
- Subtract 1o
- go to the other end of the selectionO
- go to the other corner in the same linegv
- select previous selectionv
- start Visual modev
- {motion}
-{command}
- select and operate. e.g., v-ip-d
- select inner paragraph and deleteV
- start Visual Line modeCtrl-v
- start Visual Block modeo
- move to the other end of the selectionO
- move to the other corder in the same lineI{string}
- <Esc>
- insert textA{string}
- <Esc>
- append textc{string}
- <Esc>
- change selected textC{string}
- <Esc>
- change selected text to end of the line~{string}
- <Esc>
- swap caseU{string}
- <Esc>
- to uppercaseu{string}
- <Esc>
- to lowercase>
- add one shift amount<
- remove one shift amountUse the mouse to select text
p
- put after the cursorP
- put before the cursorVim中复制粘贴缩进错乱问题的解决方案 - 小一的专栏 - CSDN博客
:set paste
5. Copying and moving text - Change - Neovim docs
y
- yankyy
- yank a lineY
- same as yy
"{register}
- Use {register}
for next delete, yank or put.:reg[isters]
or :di[splay]
- Display registersRegisters
"_
- Blackhole register"-
- Small delete register - text from commands that delete less than one line".
- Last insert register - the last inserted text with the insert mode commands CTRL-A
and CTRL-@
":
- Last command register - the most recent executed command-line"%
- Current file register - the name of the current file"#
- Alternate file register - the name of the alternate file for the current window"/
- Last search pattern register - the most recent search-patternCLIPBOARD is typically used in X11 applications for copy/paste operations (CTRL-c
/CTRL-v
), while PRIMARY is used for the last selected text, which is generally inserted with the middle mouse button.
Nvim's X11 clipboard providers only use the PRIMARY and CLIPBOARD selections, for the "*" and "+" registers, respectively.
"*
- PRIMARY register
"+
- CLIPBOARD register
"+
+ yy
- copy a line to the clipboard"+
+ p
- paste text from the clipboardaw
- a wordiw
- inner wordaW
- a WORDiW
- inner WORDas
- a sentenceis
- inner sentenceap
- a paragraphip
- inner paragrapha]
- a [] blocki]
- inner [] blockab
- a () blockib
- inner () blocka>
- a <> blocki>
- inner <> blockat
- a tag blockit
- inner tag blockaB
- a {} BlockiB
- inner {} Blocka"
- a double quoted stringi"
- inner double quoted stringa'
- a single quoted stringi'
- inner single quoted stringa`
- a backtick quoted stringi`
- inner backtick quoted string:echo @%
- print file name:echo expand('%:p:h')
- print full file path:e file.txt
- open a file in a new buffer:saveas filename.txt
- save as new file name:file new.txt
- rename file:split
- split a window:split two.txt
- split a window on another file:splitbelow
- split a window below:splitright
- split a window on the right:new
- open a new window:vsplit
- split a window in vertical:vsplit two.txt
- split a window on another file in vertical:vnew
- open a new window in verticalvim -o one.txt two.txt three.txt
- open files in split windowsvim -O one.txt two.txt three.txt
- open files in vertical split windows:only
- close other windows:qall
- quit all:wall
- write allCtrl-w
+ w
- move cursor between windowsCtrl-w
+ h
- move cursor to window on the leftCtrl-w
+ j
- move cursor to window belowCtrl-w
+ k
- move cursor to window aboveCtrl-w
+ l
- move cursor to window on the rightCtrl-w
+ t
- move cursor to the top windowCtrl-w
+ b
- move cursor to the bottom windowCtrl-w
+ H
- move window to the far leftCtrl-w
+ J
- move window to the bottomCtrl-w
+ K
- move window to the topCtrl-w
+ L
- move window to the the far rightCtrl-w
+ +
- increase size by 1 lineCtrl-w
+ -
- decrease size by 1 lineCtrl-w
+ _
- as height as possible<n>
+ Ctrl-w
+ _
- set a specified number of linesvimdiff a.txt b.txt
- diff filesvim -d a.txt b.txt
:vert diffsplit b.txt
- open file in diff split window:vert diffpatch /tmp/diff
:diffupdate
- refresh diff]c
- next change[c
- previous changedp
- diff put, use thisdo
- diff obtain, use the other:tab split
- open a new tab with current file:tabe file.txt
- open a file in new tab:tabc
- close current tab:tabo
- close other tabs:tabs
- show tabs listgt
or :tabn
- Go to the next tab1gt
or :tabr
- Go to the first tab$gt
or :tabl
- Go to the last tabgT
or :tabp
- Go to the previous tabg
+Tab - Go to the last accessed tab:tabm
- move current tab to the last:tabm 0
- move current tab to the first:tabm +1
- move current tab to the right:tabm -1
- move current tab to the leftXTerm
Windows
"current selection", you can paste in another application without any further action.
"*
- {command}
- current selection, register"+
- {command}
- real clipboard.
- repeat a changeq{register}
- start record named {register}
q
- finish record@{register}
- execute the macroq{REGISTER}
- start record named {register}
in uppercaseq
- finish record@{register}
- execute the macro:[range]substitution/from/to/[flags]
:[range]s/from/to/[flags]
- Abbreviation substitution
is s
:s/from/to/
- change current line:%s/from/to/
- %
means all lines:s/from/to/g
- g
means "global", change all occurrences:s/from/to/c
- c
means "confirm", ask you for confirmation:%s/\<from\>/to/gc
- replace word "from":%s/\([^,]*\), \(.*\)/\2 \1/
- replace "Bond, James" to "James Bond":%s/\s\+$//
- trim trailing spaces.
- current line%
- all lines1,5
- line 1 to 554
- line 54$
- last line.,$
- from current line to the last line?^Chapter?,/^Chapter/
- pattern, from previous "Chapter" to next "Chapter".+3
- offset, 3 lines after current line't,'b
- marks, from mark "t" to mark "b"'<,'>
- visual mode selection{num}:
- get :.,.+{num}
:[range]global/{pattern}/{command}
- find a match for a pattern and execute a command:[range]write filename.txt
- write range to a file:[range]write >>filename.txt
- write range append to a filegq
+ {motion}
- format with text width 72, wrap linesg~
+ {motion}
- swap casegU
+ {motion}
- to uppercasegu
+ {motion}
- to lowercaseg~g~
- swap case for this linegUgU
- to uppercase for this linegugu
- to lowercase for this line:!{program}
- execute program[range]!{program}
- filter text through program:r !{program}
- execute program and read its output:w !{program}
- execute program and send text to its input!
is a filter operation
!5G
+ sort
+ <Enter>
- from line 1, go to line5, execute sort
program!!
filters current line
!!
+ date
+ <Enter>
- replace current line with output of date
:read !ls
- read output of ls
:0read !date -u
- read output of date
in first line:write !wc
- execute wc
with current fileCtrl
- b
- to the begin of command lineCtrl
- e
- to the end of command lineCtrl
- w
- backspace a wordCtrl
- u
- delete to the beginning of the command<Tab>
- autocompletion, next matchCtrl
- p
- previous matchCtrl
- d
- list matchesCtrl
- l
- longest match:history
- show history of :
commands:history /
- show history of search commandsq:
- open command line windowThe <Enter>
command will execute the line under the cursor. It doesn't matter whether Vim is in Insert mode or in Normal mode.
Changes in the command line window are lost. They do not result in the history to be changed. Except that the command you execute will be added to the end of the history, like with all executed commands.
Vim uses sessions to save projects.
Vim uses views to save window settings
:edit .
- directory listing:cd {directory}
- set the current directory:pwd
- display current directory:lcd {directory}
- set local current directory to current window only:browse edit
- open file browser and then edit:browse split
- open file browser and then split in a new window:browse split ../
- open file browser in parent directory and then split in a new window#include "inits.h"
Move the cursor on the name of the file and type:
gf
:ls
or :buffers
- list buffers:b[uffer] 2
- edit buffer 2:sbuffer 2
- edit buffer 2 in a new window:bn[ext]
- go to next buffer:bp[revious]
- go to previous buffer:bfirst
- go to the first buffer:blast
- go to the last buffer:bd[elete] 3
- remove buffer 3 from the list:tab ba[ll]
- edit all buffers as tabs:set fileformat=unix
:write
Ctrl
- w
- backspace delete a wordCtrl
- u
- delete to beginning of the lineCtrl
- p
- previous matchCtrl
- n
- next match^X
modeCtrl
- x
- start ^x
mode to insert specific items
Ctrl
- f
- file namesCtrl
- o
- Omni completionCtrl
- i
- current and included filesCtrl
- k
- words from a dictionaryCtrl
- ]
- tagsCtrl
- v
- Vim command lineCtrl
- e
- insert a character from the line belowCtrl
- r
+ {register}
- insert from {register}
Set options
:set autoindent
:set shiftwidth=4
:set softtabstop=4
{n}>>
- increase the indent of {n}
lines{n}<<
- decrease the indent of {n}
lines==
- auto-indent current lineCtrl
- t
- increase the indent of current lineCtrl
- d
- decrease the indent of current line{n}>
- increase the indent of current line in {n}
tabs{n}<
- decrease the indent of current line in {n}
tabsConvert tabstop from 2 to 4 spaces
:set tabstop=2
:retab 4
:set virtualedit=all
TBD
Read from standard input
$ ls | vim -
Set options
:set ignorecase
:set smartcase
\cword
- ignore case for pattern word
\Cword
- match case for pattern word
\d
- digit\D
- non-digit\s
- whitespace\S
- non-white characters\l
- lowercase alpha\L
- non-lowercase alpha\u
- uppercase alpha\U
- non-uppercase alpha\f
- filename characters\s
- a whitespace\_s
- a whitespace or a line break\_.
- any character or a line breakzf
- ap
- create a fold for a paragraphzo
- open the foldzc
- close the foldzr
- reduce the folding - less foldingzR
- open allzm
- more folding - more foldingzM
- close allCtrl
- k
+ {digraph}
- insert digraph:help digraph-table
Example:
Ctrl
- k
+ Rg
- registered sign - ®
Ctrl
- k
+ PI
- pilcrow sign - ¶
Ctrl
- k
+ .M
- middle dot - ·
Ctrl
- k
+ >>
- right-position double angle quotation mark - »
:options
- opens a new window with a list of optionsUpdating your vimrc file on the fly
~/.vimrc
source $VIMRUNTIME/defaults.vim
" set encoding=utf-8
colorscheme elflord
function! GetStatusLine()
return '%<%F %m' . '%='
\. ' | Ln %l, Col %c'
\. ' | %{GetIndent()}'
\. ' | %{GetEncoding()}'
\. ' | %{GetLineEnding()}'
\. ' | %Y '
endfunction
function! GetIndent()
if &softtabstop
return printf('Spaces: %d', &softtabstop)
else
return printf('Tab Size: %d', &tabstop)
endif
endfunction
function! GetEncoding()
let encoding = &fileencoding
if empty(encoding)
let encoding = &encoding
endif
if &bomb
let encoding .= ' BOM'
endif
return encoding
endfunction
function! GetLineEnding()
let mapping = {
\ 'unix': 'LF',
\ 'mac': 'CR',
\ 'dos': 'CRLF'
\ }
let fileformat = &fileformat
return mapping[fileformat]
endfunction
function! GetWhitespaceChars()
let charMapping = {
\ 'tab': '» ',
\ 'trail': '␣',
\ 'eol': '¬'
\}
let items = []
for [key, value] in items(charMapping)
call add(items, key . ':' . value)
endfor
return join(items, ',')
endfunction
" 2 searching
" set wrapscan
" set incsearch
" set magic
set ignorecase
set smartcase
" 4 displaying text
" set wrap
set list
set listchars=tab:»\ ,trail:␣,eol:¬
set number
" 5 syntax
set hlsearch
set cursorline
set spell
" 6 multiple windows
set laststatus=2
set statusline=%!GetStatusLine()
" 11 messages and info
" set showcmd
" set showmode
" set ruler
" 14 tabs and indenting
set tabstop=4
set shiftwidth=2
set smarttab
set softtabstop=2
set expandtab
set autoindent
set smartindent
" 18 reading and writing files
" set endofline
" 20 command line editing
" set wildmenu
" 24 multi-byte characters
" set fileencoding=utf-8
set termencoding=utf-8
nshen/learn-neovim-lua: Neovim 配置实战:从 0 到 1 打造自己的 IDE (github.com)
ayamir/nvimdots: A well configured and structured Neovim. (github.com)
Installing Neovim · neovim/neovim Wiki (github.com)
Ubuntu 20.04 apt-get 安装 Neovim v0.6.1 - SegmentFault 思否
nanotee/nvim-lua-guide: A guide to using Lua in Neovim (github.com)
LUA-VIMSCRIPT BRIDGE - Lua - Neovim docs
vim.g
- Global editor variablesvim.b
- Buffer-scoped editor variablesvim.w
- Window-scoped editor variablesvim.o
- Vim optionsvim.go
- Global optionsvim.bo
- Buffer-scoped optionsvim.wo
- Window-scoped optionsvim.opt
- list- and map-style option from Lua: It allows accessing them as Lua tables.vim.o.listchars = 'space:_,tab:>~'
vim.opt.listchars = { space = '_', tab = '>~' }
nvim/init.lua
require('options')
require('plugins')
require('colorscheme')
nvim/lua/options.lua
local opt = vim.opt
opt.ignorecase = true
opt.smartcase = true
opt.cmdheight = 2
vim.wo.list = true
opt.listchars = { tab = '»·', trail = '·', nbsp = '+' }
vim.wo.number = true
vim.wo.cursorline = true
vim.wo.colorcolumn = '80'
vim.wo.spell = true
opt.showmode = false
opt.tabstop = 4
opt.shiftwidth = 4
opt.softtabstop = 2
vim.bo.expandtab = true
opt.smartindent = true
vim.bo.fileencoding = 'utf-8'
nvim/lua/colorscheme.lua
local opt = vim.opt
local cmd = vim.api.nvim_command
opt.background = 'dark'
cmd('colorscheme tokyonight')
lewis6991/pckr.nvim: Spiritual successor of https://github.com/wbthomason/packer.nvim
$ git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim
nvim/lua/plugins.lua
return require('packer').startup(function ()
use 'wbthomason/packer.nvim'
use 'folke/tokyonight.nvim'
end)
:PackerSync
:PackerInstall
kyazdani42/nvim-tree.lua: A file explorer tree for neovim written in lua (github.com)
-- nvim-tree
use {
'kyazdani42/nvim-tree.lua',
requires = 'kyazdani42/nvim-web-devicons',
}
nvim/lua/plugin-config/nvim-tree.lua
require('nvim-tree').setup {}
Key mappings
:help nvim-tree-default-mappings
:NvimTreeFocus
:NvimTreeToggle
akinsho/bufferline.nvim: A snazzy bufferline for Neovim (github.com)
-- bufferline
use {
'akinsho/bufferline.nvim',
-- tag = 'v3.*',
requires = 'kyazdani42/nvim-web-devicons',
}
nvim/lua/plugin-config/bufferline.lua
vim.opt.termguicolors = true
require('bufferline').setup {
options = {
mode = 'buffers',
diagnostics = 'nvim_lsp',
offsets = {
{
filetype = 'NvimTree',
text = 'File Explorer',
highlight = 'Directory',
text_align = 'left'
}
}
}
}
:ls
-- lualine
use {
'nvim-lualine/lualine.nvim',
requires = 'kyazdani42/nvim-web-devicons',
}
nvim/lua/plugin-config/lualine.lua
require('lualine').setup {
options = {
theme = 'tokyonight',
},
extensions = {
'nvim-tree'
}
}
nvim-treesitter/nvim-treesitter: Nvim Treesitter configurations and abstraction layer (github.com)
-- nvim-treesitter
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate'
}
nvim/lua/plugin-config/nvim-treesitter.lua
require('nvim-treesitter.configs').setup {
ensure_installed = { 'html', 'css', 'json', 'javascript', 'typescript', 'yaml', 'vim', 'lua' },
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
indent = {
enable = true,
}
}
Update parsers
:TSUpdate
Show parsers install information
:TSInstallInfo
nvim-telescope/telescope.nvim: Find, Filter, Preview, Pick. All lua, all the time. (github.com)
-- telescope
use {
'nvim-telescope/telescope.nvim',
requires = 'nvim-lua/plenary.nvim'
}
Show find files
:Telescope find_files
junegunn/gv.vim: A git commit browser in Vim (github.com)
-- git
use 'tpope/vim-fugitive'
use 'junegunn/gv.vim'
use 'lewis6991/gitsigns.nvim'
require('gitsigns').setup()
Show Git log view
:GV
tpope/vim-commentary: commentary.vim: comment stuff out (github.com)
-- comment
use 'tpope/vim-commentary'
Key mappings
gcc
- Toggle commentuse 'windwp/nvim-autopairs'
require('nvim-autopairs').setup {}
use 'mhinz/vim-startify'
use 'Yggdroot/indentLine'
Toggle to show indent lines
:set shiftwidth=2
:IndentLinesToggle
use 'DanilaMihailov/beacon.nvim'
use 'karb94/neoscroll.nvim'
require('neoscroll').setup()
macOS
brew install helix
Arch Linux
yay helix
Alpine Linux
apk add helix
Winget
winget install Helix.Helix
Scoop
scoop install helix
Migrating from Vim · helix-editor/helix Wiki (github.com)
f
, t
, m
, [
, ]
)Syntax aware motions (helix-editor.com)
/
, setting the search term to the selection.a
y - copy current selection to register a
/
- Last search:
- Last executed command"
- Last yanked text@
- Last recorded macro_
- empty#
- selection indices.
- selection contents%
- Name of the current file+
- system clipboard*
- primary clipboardTextobjects (helix-editor.com)
w
- wordW
- WORDp
- Paragrapht
- Type definitionf
- Functiona
- Argument/parameterc
- CommentT
- Teste
- Data structure entrym
- Closest surrounding pairg
- ChangeType z in normal mode.
Type g in normal mode.
Type m in normal mode.
<char>
- surround add<from><to>
- surround replace<char>
- surround delete<object>
- select textobject around<object>
- select textobject innerType Ctrl-w in normal mode.
Type Space in normal mode.
Type i in normal mode.
Type v in normal mode.
Select mode echoes Normal mode, but changes any movements to extend selections rather than replace them.
Vim: help.txt
Vim documentation | Vim Tips Wiki | Fandom powered by Wikia
Nvim documentation: help (neovim.io)