当前位置:网站首页>VIM basic configuration and frequently used commands

VIM basic configuration and frequently used commands

2022-07-06 21:14:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm the king of the whole stack .

vim Advantages and application scenarios

vim The advantages of pure text editing and Linux The perfect fusion provides the command line . It can only be assumed that ssh to server To operate , Then this kind of situation can only use vim 了 .vim It is also one of the most powerful general text editors , For scenarios where different texts need to be edited ,vim It is also quite advantageous . therefore , Master vim The basic use of is still very necessary .

vim Is in vi On the basis of many new features .gvim Is to vim Add the graphic front end . Suppose that Windows Next use vim, Be able to install the latest gvim.

Here is a main vimrc The configuration file . No matter what plug-ins are not configured , Just changed the theme to its own evening Dark theme . The font is changed to Consolas Equal width font . And the line number . Indent , Search and other basic settings . And the key mapping is done <ESC> -> ii,i It was originally to switch to insert mode , High speed double click i, Then switch back to normal The model is easy .

  • Linux In general, users home Create a folder .vimrc File changes . Instead of changing /etc/vim Global configuration under folder , Affect all users .
  • Windows in vimrc be located C:\Program Files (x86)\Vim Under the folder . The name is _vimrc, Suppose it is installed everything , Search directly vimrc One step to locate .

vim Configuration file for vimrc

"-----------------------------------------------------------------------------------  
:imap ii <Esc>                     "  Key mapping   <ESC> -> ii
  
" appearance   
colorscheme evening                "  Configure color theme   
set guifont=Consolas:h12           "  Set font and size   
set number                         "  According to the line Numbers   
set guioptions-=T                  "  Hide the toolbar   
set ruler                          "  Open the status bar ruler   
set cursorline                     "  Highlight current line   
set syntax=on                      "  Syntax highlighting   
set showmatch                      "  Highlight the matching brackets   
set matchtime=3                    "  Match the highlighted time of brackets ( Company :0.1s)  
set scrolloff=10                   "  Keep the cursor at the bottom of the screen  10  That's ok  ( The cursor is at the bottom of the screen and looks very uncomfortable )  
set lines=35 columns=118           "  Size at startup 
:winpos 177 51                     "  Position when starting 
  
" Search for   
set ignorecase smartcase           "  Search ignores uppercase and lowercase , But it is still sensitive to uppercase and lowercase when there are capital letters   
set hlsearch                       "  Highlight search   
set incsearch                      "  Incremental search , Highlight character by character   
  
" operation   
set clipboard+=unnamed             "  Shared clipboard   
set showcmd                        "  The input command is displayed   
set iskeyword+=_,$,@,%,#,-         "  Words with symbols such as the following should not be cut by newline   
set noexpandtab                    "  No space is needed to replace Tab (makefile It is often used Tab Of )  
set tabstop=4                      " Tab  Width of key   
set shiftwidth=4                   "  Row stagger width   
set mouse=a                        "  Mouse available   
set autoindent                     "  Inherit the indent of the previous line . It is especially suitable for multi line staring    
  
" Backup   
set confirm                        "  Not saved or just read , Pop up confirmation   
set nobackup                       "  Do not generate backup files   
setlocal noswapfile                "  No generation  swap  file   
set bufhidden=hide                 "  When  buffer  Hidden when discarded   
set noerrorbells                   "  No warning sound   
  
" decode   
set fenc=utf-8   
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936

vim Frequently used commands

#  efficiency 
.        #  Repeat recent text operations 

#  file 
:q       #  sign out  q->quit
:w       #  preservation  w->write
:q!      #  Force exit without saving 
:wq      #  Exit after saving    
ZZ       #  Exit after saving , Same as  :wq   

#  Cursor movement 
hjkl     #  The most important thing is left, bottom, top and right . Move a character 
zz       #  The cursor moves to the middle of the screen 
w        #  Move a word forward . The cursor stops at the beginning of the word 
b        #  Move a word back ,  The cursor stops at the beginning of the word 
e        #  Same as  w,  The cursor stops at the end of the word 
ge       #  Same as  b,  The cursor stops at the end of the word 
0        #  The first character on the line  ( Same as  <HOME>  key )
^        #  The first non blank character of the line 
$        #  Move to end of line  ( Same as  <END>  key )
gg       #  Move to header 
G        #  Move to end of file 
:n       #  Jump to the first place  n  That's ok 
fx       #  After moving to the cursor, the first one is  x  The characters of  find  
Fx       #  Same as  f, Reverse shift      
Ctrl+d   #  Scroll down half screen 
Ctrl+u   #  Scroll up half screen 
Ctrl+f   #  Scroll down half screen 
Ctrl+b   #  Scroll up half screen 
%        #  Jump to paired parentheses  ( Regular use )
(        #  Move to the beginning of the current sentence 
)        #  Move to the beginning of the next sentence 
H        #  Move the top of the page   H->High
M        #  Move the middle of the page   M->Middle
L        #  Move the bottom of the page   L->Low

#  lookup 
/test           #  lookup  text ,( Remember to use regular expressions ),  then  n  Down . N  Up  n->next
?test           #  lookup  text . reverse 
*               #  Look down for the same word as the cursor 
#               #  Look up for the same word as the cursor 
:nohlsearch     #  Turn off the currently highlighted result  ( Input  :noh  Press down  <Tab>  key   You can take the initiative to complete )

#  Replace 
ra              #  Replace the current character with  a , r->replace
:%s/old/new/g   #  Replace all matches in the full text   g->global
:%s/old/new/    #  Replace all lines with the first match 
:s/old/new/g    #  Replace the current line to match all 
:s/old/new/     #  Replace the first match in the current line 

#  Insert 
a        #  Insert after current position  a->append
A        #  Insert at end of current line  
i        #  Insert... In the current position    i->insert
I        #  Insert at the beginning of the current line 
o        #  Insert one of the rows after the current row 
O        #  Insert a row before the current row 
s        #  Delete cursor character , And enter insertion mode 
S        #  Delete line with cursor , And enter insertion mode 

#  Choose 
v        #  From the current position of the cursor , Where the cursor passes will be selected , Then click on the  v  end   ( be similar  <shift>+ Direction construction ) v->view  Visual Modes 
V        #  Start from the current line of the cursor , The lines that the cursor passes through will be selected , Then click on the  V  end  

#  Delete 
d        #  Delete selected  ( The deleted content can be pasted into the buffer , It's equivalent to cutting ) d->delete
x        #  Delete the current character 
3x       #  Delete the current cursor three characters backward  (vim  After frequent use  < Numbers >+< command >  Combine )
dd       #  Delete current row 
dw       #  Delete the character where the cursor is located to the beginning of the next word  dw -> delete word
d$       #  Delete the current character to the end of the line    %-> Regular is the end of the line 
3d       #  Delete the first three lines of the current line 
J        #  Merge two lines  ( That is, delete the line break at the end of the current line ) J->join

#  revoke 
u        #  revoke   u->undo
U        #  Undo the operation on the positive line 
Ctrl+r   #  Reinstatement revocation 

#  Copy and paste 
y        #  Copy selected 
yy       #  Copy the current row 
p        #  Paste after the current cursor . Suppose you copy one line and paste it to the next line  p-paste
P        #  Paste in front of the current cursor 
ddp      #  Swap the current line and the next line  ( Clever use of cutting and pasting )
xp       #  Swap the current character with the next 

Copyright notice : This article is the original article of the blogger , Blog , Do not reprint without permission .

[http://blog.csdn.net/thisinnocence]

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117090.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061255088420.html

随机推荐