May 24, 2021 Vim
Use
:set number
display the line number.
The absolute line number is displayed by default,
:set relativenumber
Jump
:_行号_
by
_行号_gg
: _gg or line number.
Jumps are recorded in a jump list, for more
:h jump-motions
Vim has spell checking, which is turned on with the following command:
set spell
Vim only has an English dictionary installed by default. O
ther dictionaries can be found by searching for
vim-spell
in the Official Software Warehouse.
Check the available language packs:
# pacman -Ss vim-spell
Additional dictionaries can be obtained from vim's FTP archive.
Put the downloaded dictionary file
~/.vim/spell/
open
:setlocal spell spelllang=_en_us_
_en_us_
with the name of the dictionary you want).
Behavior | Shortcuts |
---|---|
The next spelling mistake |
]s
|
The last spelling mistake |
[
s
|
Spelling correction suggestions |
z=
|
Add the word to the user's correct dictionary |
zg
|
Add the word to the internal correct dictionary |
zG
|
Add words to the user error dictionary |
zw
|
Add the word to the internal correct dictionary |
zW
|
Re-check the spelling |
:spellr
|
Tips:
If you need spelling checking for two languages
~/.vimrc
English and German), addset spelllang=_en,de_
in .vimrc or/etc/vimrc
and restart Vim.With the FileType plug-in and self-built rules for file type detection, you can turn on spell checking for any file type. For example, to turn on
.txt
a file with the extension .txt, create a file/usr/share/vim/vimfiles/ftdetect/plaintext.vim
addautocmd BufRead,BufNewFile *.txt setfiletype plaintext
and then addautocmd FileType plaintext setlocal spell spelllang=en_us
/etc/vimrc
en_us and restart vim.~/.vimrc
- If you want to use spell checking only for LaTeX (or TeX) documents, just restart Vim by adding
autocmd FileType **tex** setlocal spell spelllang=_en_us_
/etc/vimrc
_en_us_.~/.vimrc
For non-English languages, replace the en_usen_us
above as the appropriate language code.
Vim can record the cursor position the last time a file was opened and move the cursor to that location the next time the same file is opened.
To turn this on, add the following to your profile ,
~/.vimrc
augroup resCur
autocmd!
autocmd BufReadPost * call setpos(".", getpos("'\""))
augroup END
See also: the relevant content on the Vim Wiki.
Create an alias, as follows:
alias vi=vim
Or, if you
sudo vi
and get
vim
install
vi-vim-symlink
AUR,
vi
and replace it with a symbolic link
vim
When you open a text file created under MS-DOS or Windows, you often end each line with a
^M
This is because Linux uses Unix-style line breaks to represent the end of a line with a line break (LF), but in Windows, MS-DOS, one carriage return (CR) after another line break (LF), so the carriage return character is displayed
^M
You can use the following command to remove carriage returns from the file:
:%s/^M//g
Note that
^
represented by the .
The way to enter the
^M
is
Ctrl+v,Ctrl+m
Another workaround is
to install dos2unix
and then perform
dos2unix <文件名>
.
If Window Manager is set to ignore window-sized rendering windows, gVim fills the blank space with a GTK theme background color, which can look ugly.
The solution is to resize the space that gVim reserves at the bottom of the window.
Add the following code
~/.vimrc
set guiheadroom=0
Note: If you set it to 0, you won't see the horizontal scroll bar at the bottom.