rogerxu / rogerxu.github.io

Roger Xu's Blog
3 stars 2 forks source link

Vim #19

Open rogerxu opened 7 years ago

rogerxu commented 7 years ago

Vim: help.txt

Vim documentation | Vim Tips Wiki | Fandom powered by Wikia

Nvim documentation: help (neovim.io)

rogerxu commented 7 years ago

Undo and Redo

rogerxu commented 7 years ago

Exit

rogerxu commented 7 years ago

Hyperlink

Vim for a hyperlink is tag. Like *help.txt*. The notation with "*" characters is used to define a tag.

rogerxu commented 7 years ago

Move

position

Word

Line

Character

Sentence

Paragraph

Section

Matching a parenthesis

Moving to a specific line

Scrolling around

rogerxu commented 7 years ago

Seach

Search

Move Occurrence

rogerxu commented 7 years ago

Marks

Jump

Named Marks

rogerxu commented 7 years ago

Edit

Operator

operator, the true power of Vim

Linewise operator

Repeating

Add and subtract

rogerxu commented 7 years ago

Visual Mode

Visual Mode

Visual Line Mode

Visual Block Mode

Multiple modification

Select Mode

Use the mouse to select text

rogerxu commented 7 years ago

Paste

Indentation

Vim中复制粘贴缩进错乱问题的解决方案 - 小一的专栏 - CSDN博客

:set paste
rogerxu commented 7 years ago

Copy

5. Copying and moving text - Change - Neovim docs

Registers

Registers

Clipboard

CLIPBOARD 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

rogerxu commented 7 years ago

Text Objects

Word

Sentence

Paragraph

Block

Quote

rogerxu commented 7 years ago

File

File path

Save

rogerxu commented 7 years ago

Split Window

Open

Close

Jump to Window

Move Window

Window Size

rogerxu commented 7 years ago

Diff

Vim: diff.txt

Jump to Changes

Resolve Changes

rogerxu commented 7 years ago

Tabs

Switch Tabs

Move Tabs

rogerxu commented 7 years ago

GUI

Mouse Behavior

XTerm

Windows

Clipboard

"current selection", you can paste in another application without any further action.

rogerxu commented 7 years ago

Record and Playback

Record a macro in a register

Append a macro to a register

rogerxu commented 7 years ago

Replace

Substitution

Example

Range

rogerxu commented 7 years ago

Global

rogerxu commented 7 years ago

Write to File

rogerxu commented 7 years ago

Formatting Text

Change for whole line

rogerxu commented 7 years ago

External Program

Replace

! is a filter operation

!! filters current line

Read

Write

rogerxu commented 7 years ago

Command Line

History

Command Line Window

The <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.

rogerxu commented 7 years ago

Session

Vim uses sessions to save projects.

View

Vim uses views to save window settings

rogerxu commented 7 years ago

File Browser

Open a file in split window

Jump to a file

#include "inits.h"

Move the cursor on the name of the file and type:

gf
rogerxu commented 7 years ago

Buffer

rogerxu commented 7 years ago

EOF

:set fileformat=unix
:write
rogerxu commented 7 years ago

Insert Mode

Autocomplete

^X mode

Copy from another line

Copy from register

rogerxu commented 7 years ago

Indents

Set options

:set autoindent
:set shiftwidth=4
:set softtabstop=4

Normal Mode

Insert Mode

Visual Mode

Convert tabstop from 2 to 4 spaces

:set tabstop=2
:retab 4
rogerxu commented 7 years ago

Edit Table

:set virtualedit=all

TBD

rogerxu commented 7 years ago

Shell Script

Read from standard input

$ ls | vim -
rogerxu commented 7 years ago

Ignore Case

Set options

:set ignorecase
:set smartcase
rogerxu commented 7 years ago

Search Pattern

Character Ranges

Character Classes

Line Break

rogerxu commented 7 years ago

Folding

Vim: usr_28.txt

rogerxu commented 7 years ago

Digraph

:help digraph-table

Example:

rogerxu commented 5 years ago

Settings

Vim: usr_05.txt

Reload settings

Updating your vimrc file on the fly

Settings

~/.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
rogerxu commented 5 years ago

Encoding

Vim: mbyte.txt

rogerxu commented 2 years ago

NeoVim

nshen/learn-neovim-lua: Neovim 配置实战:从 0 到 1 打造自己的 IDE (github.com)

ayamir/nvimdots: A well configured and structured Neovim. (github.com)

Install

Installing Neovim · neovim/neovim Wiki (github.com)

Ubuntu 20.04 apt-get 安装 Neovim v0.6.1 - SegmentFault 思否

Lua

Lua - Neovim docs

nanotee/nvim-lua-guide: A guide to using Lua in Neovim (github.com)

LUA-VIMSCRIPT BRIDGE - Lua - Neovim docs

vim.o.listchars = 'space:_,tab:>~'
vim.opt.listchars = { space = '_', tab = '>~' }

Configuration

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'

Theme

nvim/lua/colorscheme.lua

local opt = vim.opt
local cmd = vim.api.nvim_command

opt.background = 'dark'
cmd('colorscheme tokyonight')

Plugin

Package Manager

lewis6991/pckr.nvim: Spiritual successor of https://github.com/wbthomason/packer.nvim

wbthomason/packer.nvim: A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config (github.com)

$ 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

nvim-tree

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

bufferline

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

nvim-lualine/lualine.nvim: A blazing fast and easy to configure neovim statusline plugin written in pure lua. (github.com)

-- 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: 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

telescope

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

git

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

comment

tpope/vim-commentary: commentary.vim: comment stuff out (github.com)

-- comment
use 'tpope/vim-commentary'

Key mappings

Autocomplete

auto pairs
use 'windwp/nvim-autopairs'
require('nvim-autopairs').setup {}

Visual

start screen
use 'mhinz/vim-startify'
indent line

Yggdroot/indentLine: A vim plugin to display the indention levels with thin vertical lines (github.com)

use 'Yggdroot/indentLine'

Toggle to show indent lines

:set shiftwidth=2
:IndentLinesToggle
cursor

DanilaMihailov/beacon.nvim: Whenever cursor jumps some distance or moves between windows, it will flash so you can see where it is (github.com)

use 'DanilaMihailov/beacon.nvim'
smooth scroll
use 'karb94/neoscroll.nvim'
require('neoscroll').setup()
rogerxu commented 1 year ago

Cheatsheet

Vim cheatsheet (devhints.io)

Vim Cheat Sheet - Kapeli

Vim Cheat Sheet (rtorr.com)

Vim Cheat Sheet & Quick Reference

rogerxu commented 2 weeks ago

Helix

Helix (helix-editor.com)

Install

macOS

brew install helix

Arch Linux

yay helix

Alpine Linux

apk add helix

Winget

winget install Helix.Helix

Scoop

scoop install helix

Usage

Migrating from Vim · helix-editor/helix Wiki (github.com)

Movement

Changes

Selection manipulation

Multi cursors

Syntax motions

Syntax aware motions (helix-editor.com)

Search

Registers

Default registers

Special registers

Textobjects

Textobjects (helix-editor.com)

View mode

Type z in normal mode.

Goto mode

Type g in normal mode.

Match mode

Type m in normal mode.

Window mode

Type Ctrl-w in normal mode.

Space mode

Type Space in normal mode.

Unimpaired

Insert mode

Type i in normal mode.

Select mode

Type v in normal mode.

Select mode echoes Normal mode, but changes any movements to extend selections rather than replace them.

Picker