Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
usage of vim
06-11-2018, 12:04 PM (This post was last modified: 06-11-2018 05:02 PM by cchen.)
Post: #1
usage of vim
vim is a text editor with many advanced features that other editors may not have. However, it may not be easy for beginners to use. Here is a guide to use vim:

install vim
Code:
sudo yum install vim-X11 vim-enhanced vim-minimal

it is suggested to configure vim to your likings by adding a ~/.vimrc file.
.vimrc file
Code:
set history=70

set showmode

set autoindent
set smartindent
set backspace=eol,start,indent

set expandtab
set tabstop=4
set shiftwidth=4
set ruler

set number
set ignorecase
set smartcase
set hlsearch
set backup
set backupdir=~/vim/tmp/
set nowrap
set laststatus=2

three modes:
P1). command mode.
When you run vim filename to edit a file, Vim starts out in command mode. This means that all the alphanumeric keys are bound to commands, rather than inserting those characters.

P2). insert mode.
Type i (for "insert") and now the keys will behave as you'd expect. To get out of insert mode, hit the Escape key.

P3). last-line mode.
press : and Vim will switch to last-line mode. Vim is now waiting for you to enter a command like:
Code:
:w to write the file
:w! to write and override the previous versions
:q to exit the editor
:q! to quit no matter changes saved or not

useful commands:

movement commands:
Code:
0 moves the cursor to the beginning of the line.
$ moves the cursor to the end of the line.
w move forward one word.
b move backward one word.
G move to the end of the file.
gg move to the beginning of the file.
prefacing a movement command with a number will execute that movement multiple times.

editing commands:
Code:
x will delete the current character
dw will delete a word.
d0 will delete to the beginning of a line.
d$ will delete to the end of a line.
dgg will delete to the beginning of the file.
dG will delete to the end of the file.
u will undo the last operation.
Ctrl-r will redo the last undo.

searching commands:
Code:
/text search for text in the document, going forward.
?text search for text in the document, going backwards.
:%s/text/replacement text/g search for text and replace it with replacement text.
:%s/text/replacement text/gc search and confirm before replacing text.

copying and pasting:
Code:
v highlight one character at a time.
V highlight one line at a time.
p paste text after the current line.
P paste text on the current line.
y yank text into the copy buffer.

for more info about plugins setting which you may want to take a look: https://github.com/chetui/dotfiles/tree/master/vim

RR rayluk
Find all posts by this user
Quote this message in a reply
06-11-2018, 03:22 PM
Post: #2
RE: usage of vim
I have a private Vim config with some plugins setting which you may want to take a look: https://github.com/chetui/dotfiles/tree/master/vim
Find all posts by this user
Quote this message in a reply
06-11-2018, 05:02 PM
Post: #3
RE: usage of vim
Thanks for your information
Find all posts by this user
Quote this message in a reply
06-11-2018, 05:13 PM
Post: #4
RE: usage of vim
(06-11-2018 12:04 PM)cchen Wrote:  vim is a text editor with many advanced features that other editors may not have. However, it may not be easy for beginners to use. Here is a guide to use vim:

install vim
Code:
sudo yum install vim-X11 vim-enhanced vim-minimal

it is suggested to configure vim to your likings by adding a ~/.vimrc file.
.vimrc file
Code:
set history=70

set showmode

set autoindent
set smartindent
set backspace=eol,start,indent

set expandtab
set tabstop=4
set shiftwidth=4
set ruler

set number
set ignorecase
set smartcase
set hlsearch
set backup
set backupdir=~/vim/tmp/
set nowrap
set laststatus=2

three modes:
P1). command mode.
When you run vim filename to edit a file, Vim starts out in command mode. This means that all the alphanumeric keys are bound to commands, rather than inserting those characters.

P2). insert mode.
Type i (for "insert") and now the keys will behave as you'd expect. To get out of insert mode, hit the Escape key.

P3). last-line mode.
press : and Vim will switch to last-line mode. Vim is now waiting for you to enter a command like:
Code:
:w to write the file
:w! to write and override the previous versions
:q to exit the editor
:q! to quit no matter changes saved or not

useful commands:

movement commands:
Code:
0 moves the cursor to the beginning of the line.
$ moves the cursor to the end of the line.
w move forward one word.
b move backward one word.
G move to the end of the file.
gg move to the beginning of the file.
prefacing a movement command with a number will execute that movement multiple times.

editing commands:
Code:
x will delete the current character
dw will delete a word.
d0 will delete to the beginning of a line.
d$ will delete to the end of a line.
dgg will delete to the beginning of the file.
dG will delete to the end of the file.
u will undo the last operation.
Ctrl-r will redo the last undo.

searching commands:
Code:
/text search for text in the document, going forward.
?text search for text in the document, going backwards.
:%s/text/replacement text/g search for text and replace it with replacement text.
:%s/text/replacement text/gc search and confirm before replacing text.

copying and pasting:
Code:
v highlight one character at a time.
V highlight one line at a time.
p paste text after the current line.
P paste text on the current line.
y yank text into the copy buffer.


RR rayluk
Looks good to me.

Quote:for more info about plugins setting which you may want to take a look: https://github.com/chetui/dotfiles/tree/master/vim

calling this as an example would be better.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: