Neovim, my favourite editor!

Some hotkey to operate vim

Use vim-plug in neovim

  • The neovim config file is in ~/.config/nvim/init.vim
    w
    we should create two directory

  • ~/.config/nvim/autoload

  • ~/.config/nvim/plugged

1
mkdir -p ~/.config/nvim/autoload ~/.config/nvim/plugged
1
2
# Download vim-plug
curl -fLo ~/.config/nvim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Append new lines in vim config file(Neovim is in ~/.config/nvim/init.vim)

1
2
3
call plug#begin('~/.config/nvim/plugged')
Plug 'vim-airline/vim-airline'
call plug#end()

Then,reload the config file,change vim to the command mode, tap these

1
:PlugInstall

And you have completely installed the vim-plug

Single option to edit

  • Command a could get into the insert mode after the current character.
  • Command Shift + a could get into the insert mode at the last of the current line.
  • The command i could get into the insert mode before the current character.
  • Command Shift+ i could get into the insert mode at the begin of the current line.
  • Command o could get into the insert mode at the next line beginning.
  • Command Shift+o could get into the insert mode at the previous line beginning.
  • Command u could undo the previous actoin.
  • We can use " to comment the vimrc
  • In the command mode,keyword % means the current file itself.
  • We can use $ to move the cursor to the end of a line
1
<operation> <motion> # The command format is Kind of this mode

d command is the delete key
When we use d+Right+3,means delete 3 letters on the right side

  • Tap: set spell,the incorrect syntax will be found.

choose a incorrect word,tapz=,then,you will find lots of words advice from vim.

  • When you jump to another place,you want to go back to the previous code block,you could use

Ctrl + o,also,you could use Ctrl + i to go back again

  • When your cursor is on a filepath,tap gf to open it within the current window(then you can also tap Ctrl + o to go back to the previous file)

⭐️Tip one
If you are editing a /etcfile but don’t have the root privilege,and exit will lose the contents forever.
Then you can tap these commands to save your data

1
: w !sudo tee %

then you input some enter will be right
Attention: this command is perfect to run in vim,but not neovim

⭐️Tip two
we can append a rule in vimrc,like

1
map \<LEADER>\<LEADER> \<Esc>/<++>\<CR>: nohlsearch\<CR>c4l

From now on,if we write <++> in a file,then we tap double spaces we can change new characters replacing the previous one.

⭐️Tip three
a combo with figlet

  • install the figlet(brew install figlet)
  • tap these commands to insert a figlet words into the file
1
: r !figlet NICE

then we’ll get this one

⭐️Tip four
print the vim file into the HTML format (will open another vim window)

1
%TOhtml

when we tap wq in the new genarete file,we can open it with the browser

Edit the vimrc

Use map to custom the keybind

Custom setting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# increase the line number
set number

# syntax highlighting
syntax on

# add a underline on current editing line
set cursorline

# use Tab to complete the command
set wildmenu

# make text auto fit current window
set wrap

# make your vim adapted with the elder version
set nocompatible

# custom the indent(when you use python or other language),There must be no spaces around the "="
set tabstop=2
set shiftwidth=2
set softtabstop=2

# make your editing line always keep the medium of your screen
set scrolloff=5

# use the option,we could restore the editing position latest edited when we open the file again next time
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

map

1
2
3
4
5
6
7
8
9
# tap j,means k
map j k

# tap Ctrl+s,means :wq+enter
map <C-s> :wq<CR>

# deny the recursive query
noremap j k

Special keys

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
notation        meaning             equivalent  decimal value(s)
-----------------------------------------------------------------------
<Nul> zero CTRL-@ 0 (stored as 10) <Nul>
<BS> backspace CTRL-H 8 backspace
<Tab> tab CTRL-I 9 tab Tab
linefeed
<NL> linefeed CTRL-J 10 (used for <Nul>)
<FF> formfeed CTRL-L 12 formfeed
<CR> carriage return CTRL-M 13 carriage-return
<Return> same as <CR> <Return>
<Enter> same as <CR> <Enter>
<Esc> escape CTRL-[ 27 escape <Esc>
<Space> space 32 space
<lt> less-than < 60 <lt>
<Bslash> backslash \ 92 backslash <Bslash>
<Bar> vertical bar | 124 <Bar>
<Del> delete 127
<CSI> command sequence intro ALT-Esc 155 <CSI>
<xCSI> CSI when typed in the GUI <xCSI>

<EOL> end-of-line (can be <CR>, <LF> or <CR><LF>,
depends on system and 'fileformat') <EOL>

<Up> cursor-up cursor-up cursor_up
<Down> cursor-down cursor-down cursor_down
<Left> cursor-left cursor-left cursor_left
<Right> cursor-right cursor-right cursor_right
<S-Up> shift-cursor-up
<S-Down> shift-cursor-down
<S-Left> shift-cursor-left
<S-Right> shift-cursor-right
<C-Left> control-cursor-left
<C-Right> control-cursor-right
<F1> - <F12> function keys 1 to 12 function_key function-key
<S-F1> - <S-F12> shift-function keys 1 to 12 <S-F1>
<Help> help key
<Undo> undo key
<Insert> insert key
<Home> home home
<End> end end
<PageUp> page-up page_up page-up
<PageDown> page-down page_down page-down
<kHome> keypad home (upper left) keypad-home
<kEnd> keypad end (lower left) keypad-end
<kPageUp> keypad page-up (upper right) keypad-page-up
<kPageDown> keypad page-down (lower right) keypad-page-down
<kPlus> keypad + keypad-plus
<kMinus> keypad - keypad-minus
<kMultiply> keypad * keypad-multiply
<kDivide> keypad / keypad-divide
<kEnter> keypad Enter keypad-enter
<kPoint> keypad Decimal point keypad-point
<k0> - <k9> keypad 0 to 9 keypad-0 keypad-9
<S-...> shift-key shift <S-
<C-...> control-key control ctrl <C-
<M-...> alt-key or meta-key meta alt <M-
<A-...> same as <M-...> <A-
<D-...> command-key (Macintosh only) <D-
<t_xx> key with "xx" entry in termcap

Split your vim workspace

Edit the vim config file~/.config/nvim/init.vim,then append these configurations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# set a mapleader key
let mapleader = " "

# horizontal split your vim workspace
map `h :set nosplitright<CR>:vsplit<CR>
map `l :set splitright<CR>:vsplit<CR>

# vertical split your vim workspace
map `j :set nosplitbelow<CR>:split<CR>
map `k :set splitbelow<CR>:split<CR>

# move your cursor to the other workspace
map <LEADER>h <C-w>h
map <LEADER>j <C-w>j
map <LEADER>k <C-w>k
map <LEADER>l <C-w>l

open another file,we can tap: e ~/try/2.txtto open another file in your vim

Vim Tab Manager

1
2
3
4
5
6
7
8
# create a new tab
map tn :tabe<CR>

# previous tab
map th :-tabnext<CR>

# next tab
map tl :+tabnext<CR>

Recoding a macro

  • Tap q ,then Tap a Character you want,such as a

Vim will recode a macro marked with a

  • Do anything you want.
  • Tap @ + a will execute the macro

VISUAL LINE

V-LINE mode

Tap the Shift+v could get into the V-LINE mode,and we could batch operate these lines.

then,Tap the : ,we could input the batch operate the lines

1
2
3
# Append 2022- to the beginning of these lines
:normal I2022-
# Tap the Enter key will see the changing

V-BLOCK mode

Tap the Ctrl+v could get into the V-BLOCK mode,and we could batch operate the selected blocks
then,Tap the : ,we could input the batch operate the lines

1
2
3
4
5
6
7
8
# Append 2022- to the beginning of these selected blocks,and Tap the Enter key will see the changing
:normal I2022-

# delete All the selected blocks
d

# edit an area in one line,and take effect to all the lines(Tap Esc to make it effective when you have edited)
Shift + i

Vim-Plugs

preservim/nerdcommenter

  • Use space(My <LEADER>) + cc to add a comment

  • User space(My <LEADER>) + cu to cancel a comment

tpope/vim-surround

  • Use cs"' can change the word surrounding become to ' from "

  • Use cs"<q> can change the word surrounding become to <q> from "

  • Use ds"can cancel the word surrounding

tmhedberg/SimpylFold

  • Use zo to open a folded code block

  • Use zc to close a fold

CoC

  • Use space + r + n to rename a variable

mbbill/undotree

Add a configuration to the init.vim

1
nnoremap <C-h> :UndotreeToggle<CR>
  • Use Ctrl + H to open the undotree toggle

FzF

Add a configuration to the init.vim

1
2
3
4
5
6
7
8
nnoremap  <Leader>C        :Colors<CR>
nnoremap <Leader>b :Buffers<CR>
nnoremap <Leader>f :Files<CR>
nnoremap <Leader>l :Lines<CR>
nnoremap <Leader>ag :Ag <C-R><C-W><CR>
nnoremap <Leader>AG :Ag <C-R><C-A><CR>
xnoremap <Leader>ag y:Ag <C-R>"<CR>
nnoremap <Leader>` :Marks<CR>
  • Use \<LEADER> + f to search files

NerdTree

Add a configuration to the init.vim

1
nnoremap <C-f> :NERDTreeFind<CR>

Use Ctrl + f to open the NerdTree

mhinz/vim-startify

Just install the pluggin is well

mg979/vim-visual-multi

  • When you cursor a word,tap Ctrl + n to select a word and get into the visual-multi mode

Then you can change them batching

Neovim, my favourite editor!

https://resek4.github.io/2022/06/23/Vim/

Author

Resek4

Posted on

2022-06-23

Updated on

2023-02-26

Licensed under

Comments