首页 > 其他分享 >vim配置及基本用法

vim配置及基本用法

时间:2024-04-02 21:00:57浏览次数:15  
标签:配置 word move character 用法 current line vim delete

capslock -> ctrl // system key change
inoremap jk <Esc> // esc config to jk
let mapleader = "'" // leader to '

Verbs
d: delete
c: change
y: yank (copy)
v: visually select (V for line vs. character)

Modifiers
i: inside
a: around
NUM: number (e.g.: 1, 2, 10)
t: searches for something and stops before it
f: searches for that thing and lands on it
/: find a string (literal or regex)

Nouns
w: word
s: sentence
): sentence (another way of doing it)
p: paragraph
}: paragraph (another way of doing it)
t: tag (think HTML/XML)
b: block (think programming)

Nouns as motion
# Delete two words
d2w

# Change inside sentence (delete the current one and enter insert mode)
cis

# Yank inside paragraph (copy the paragraph you’re in)
yip

# Change to open bracket (change the text from where you are to the next open bracket)
ct<

vi file: open your file in vim
:w: write your changes to the file
:q!: get out of vim (quit), but without saving your changes (!)
:wq: write your changes and exit vim
:saveas ~/some/path/: save your file to that locationvim

nmap zz :wq<cr> // a faster way to do :wq

replace
:{作用范围}s/{目标字符}/{替换的字符}/{替换标志}
:%s/first/second/g

A search reference
/{string}: search for string
t: jump up to a character
f: jump onto a character
*: search for other instances of the word under your cursor
n: go to the next instance when you’ve searched for a string
N: go to the previous instance when you’ve searched for a string
;: go to the next instance when you’ve jumped to a character
,: go to the previous instance when you’ve jumped to a character

Basic motions
j: move down one line
k: move up one line
h: move left one character
l: move right one character

Moving within the line
0: move to the beginning of the line
$: move to the end of the line
^: move to the first non-blank character in the line
t": jump to right before the next quotes
f": jump and land on the next quotes
, and ; will repeat the previous t and f jumps.

Moving within the line
0: move to the beginning of the line
$: move to the end of the line
^: move to the first non-blank character in the line
t": jump to right before the next quotes
f": jump and land on the next quotes
, and ; will repeat the previous t and f jumps.

Moving by word
w: move forward one word
b: move back one word
e: move to the end of your wor
W: move forward one big word
B: move back one big word

Moving by sentence or paragraph
): move forward one sentence
}: move forward one paragraph
Moving within the screen
H: move to the top of the screen
M: move to the middle of the screen
L: move to the bottom of the screen
gg: go to the top of the file
G: go to the bottom of the file
^U: move up half a screen
^D: move down half a screen
^F: page down
^B: page up

Jumping back and forth
Ctrl-i: jump to your previous navigation location
Ctrl-o: jump back to where you were

Other motions
:line_number: move to a given line number
^E: scroll up one line
^Y: scroll down one line

在vim中有3中方法可以跳转到指定行(首先按esc进入命令行模式):
1、ngg/nG (跳转到文件第n行,无需回车)
2、:n (跳转到文件第n行,需要回车)
3、vim +n filename (在打开文件后,跳转到文件的第n行

Basic change/insert options
i: insert before the cursor
a: append after the cursor
I: insert at the beginning of the line
A: append at the end of the line
o: open a new line below the current one
O: open a new line above the current one
r: replace the one character under your cursor
R: replace the character under your cursor, but just keep typing afterwards
cm: change whatever you define as a movement, e.g. a word, or a sentence, or a paragraph.
C: change the current line from where you’re at
ct?: change change up to the question mark
s: substitute from where you are to the next command (noun)
S: substitute the entire current line

# Change inside sentence
cis

# Go to the beginning of the line and enter insert mode
I

# Start typing right after the cursor
a

# Delete the line from where you’re at, and enter insert mode
C

# Delete the entire line you’re on, and enter insert mode
S

Basic deletion options
x: exterminate (delete) the character under the cursor
X: exterminate (delete) the character before the cursor
dm: delete whatever you define as a movement, e.g. a word, or a sentence, or a paragraph.
dd: delete the current line
dt.: delete delete from where you are to the period
D: delete to the end of the line
J: join the current line with the next one (delete what’s between)

Undo and Redo
u: undo your last action.
Ctrl-r: redo the last action

Using the “.” to repeat your last action
# delete a word
dw
# delete five more words
5.

Copying text
y: yank (copy) whatever’s selected
yy: yank the current line

A copy and paste reference
y: yank (copy) from where you are to the next command (noun)
yy: a shortcut for copying the current line
p: paste the copied (or deleted) text after the current cursor position
P: paste the copied (or deleted) text before the current cursor position

# Change “foo” to “bar” on every line
:%s /foo/bar/g

# Change “foo” to “bar” on just the current line
:s /foo/bar/g

# Search for the string
/delinquent

# Append some text to the end of the line
A[DO NOT PAY] [Esc]

# Go to the next instance and append the text to the line
n.

Word Text Objects
iw: inside word
aw: around word

# Delete around a word
daw

Sentence Text Objects
is: inside sentence
as: around sentence

# Change inside a sentence
cis

words: iw and aw
sentences: is and as
paragraphs: ip and ap
single quotes: i' and a'
double quotes: i" and a"
back ticks: i` and a`
parenthesis: i( and a(
brackets: i[ and a[
braces: i{ and a{
tags: it and at

Selecting items with visual mode
character-based: v
line-based: V
paragraphs: Ctrl-v

# Select inside of parenthesis
vi(

# Select inside of brackets
vi[

# Select everything inside the second tier braces
v2i{

# Enter visual mode, select two more words of text, and copy them
vwwy

# Enter line-based visual mode and delete a couple of lines below
Vjjd

# Visually select an entire paragraph
vip

# Visually select an entire paragraph then paste it down below
vipyjjp

Using Macros
qa: start recording a macro named “a”
q: stop recording
@a: play back the macro

Wrapping Content
Using the Surround Plugin you can do some seriously epic stuff in terms of wrapping text with markup.
cs"': for the word you’re on, change the surrounding quotes from double to single
cs'<q></q>: do the same, but change the single quotes to <q></q>
ds": delete the double quotes around something
ysiw[: surround the current word with brackets
ysiw<em></em>: emphasize the current word (it works with text objects!) Want to know what’s crazier about that? It’s dot repeatable!.
Visual Mode: select anything, and then type S. You’ll be brought to the bottom of the window. Now type in what you want to wrap that with, such as <a href="/images">, and then press enter.</a>

标签:配置,word,move,character,用法,current,line,vim,delete
From: https://www.cnblogs.com/liubenben/p/18111488

相关文章

  • Cmake的安装和配置
    进入Indexof/files/v3.20(cmake.org)下载想要的版本 将安装包解压到想要的文件夹下,复制文件夹下bin目录的路径打开系统变量,将刚刚复制的路径添加进去 最后用Windows+R快捷键打开cmd命令窗口输入cmake-version出现如下的版本号则配置成功 ......
  • 个性化定义多个 Git 托管平台配置
    一、背景说明本人使用了多个Git托管平台,包括Github、Gitlab和Gitee。为了避免提交信息(主要是用户名和邮箱地址)错乱,我希望在向不同的托管平台提交内容时,能够自动设置相应的用户名和邮箱地址。二、解决方案1.常规做法为每个repo单独设置用户名和邮箱地址。操作步骤如下......
  • 配置Linux上的MySQL
    MySQL数据库环境搭建和编程MySQL环境安装设置ubuntu环境安装mysql-server和mysql开发包,包括mysql头文件和动态库文件,命令如下:sudoapt-getinstallmysql-server=》安装最新版MySQL服务器sudoapt-getinstalllibmysqlclient-dev=》安装开发包ubuntu默认安装最新的mysq......
  • redis特殊数据类型-Geospatial(地理位置)用法
    一 Geospatial(地理位置)介绍使用经纬度定位地理坐标并用一个有序集合zset保存,所以zset命令也可以使用有效的经度从-180度到180度。有效的纬度从-85.05112878度到85.05112878度。二 Geospatial应用场景        通过georadius就可以完成附近的人功能withcoo......
  • mysql配置文件解析
     mysql服务启动默认使用的配置文件路径mysqld--verbose--help|grepcnfmy.cnf配置文件字段解析[client]port=3306socket=/tmp/mysql.sock[mysqld]port=3306socket=/tmp/mysql.sockbasedir=/usr/local/mysqldatadir=/data/mysqlpid-file=/data/mys......
  • envoy&istio 对接ratelimit 实现限流之envoy配置
    envoy与ratelimit对接需要完成两步,1启用ratelimit过滤器,2配置触发条件。一、启用ratelimit过滤器envoy要与ratelimit服务对接,需要在lds的http_filter配置上启用ratelimitfilter,启用方式如下1http_filters:2-name:envoy.filters.http.ratelimit......
  • VIM
    vim的三种模式命令模式i insert,在光标所在处输入I 在当前光标所在行的行首输入a append,在光标所在处后面输入A 在当前光标所在行的行尾输入o 在当前光标所在行的下方打开一个新行O 在当前光标所在行的上方打开一个新行当前页跳转:H:页首  M:页中间行  L:页底zt:......
  • 米尔MYD-LHI3093开发板配置网络连接
    米尔MYD-LHI3093配置网络连接1前言最近用米尔MYD-LHI3093做实验,开发板预装openEulerEmbedded22.03LTS-SP2支线(qemu-aarch64),默认缺少如下命令(commandnotfound):缺少nmcli,无法通过该指令连接到网络;缺少sudo,虽然系统默认root账户;缺少yum,无法用yum源安装依赖及应用。......
  • vue3+ts项目配置别名
    说明在项目开发中,需要通过配置别名来方便开发读取文件目录。配置文件vite.config.jsimport{defineConfig}from'vite'importvuefrom'@vitejs/plugin-vue'import{resolve}from"path";constpathSrc=resolve(__dirname,"src");exportdefault......
  • vim 使用记录
    记录vim使用和学习中用到的一些命令1.设置vim行号echo"setnumber">>~/.vimrcsource~/.vimrc2.vim跳到最后一行 在Vim中跳转到文件的最后一行,你可以按下Shift+G快捷键。这会将光标移动到文件的最后一行。如果你在正常模式下,也可以使用:命令加上行号:......