A buffer is the in-memory text of a file.
A window is a viewport on a buffer.
A tab page is a collection of windows.
A word consists of a "sequence of letters, digits and underscores", or a "sequence of other non-blank characters", separated with white space (spaces, tabs, <EOL>). An empty line is also considered to be a word.
A WORD consists of a "sequence of non-blank characters", separated with white space. An empty line is also considered to be a WORD.
Example: %abc,def%
is considered as 5 words or 1 WORD.
%
, abc
, ,
, def
, %
abc
and def
are the "words" that are a "sequence of letters, digits and underscores"%
and ,
are the "words" that are a "sequence of other non-blank characters"%abc,def%
~/.vimrc
: User config for Vim.
~/vimfile/
, ~/.vim/
: Directory for user-provided vim files such as color
and syntax
~/vimfile/color/
and ~/vimfile/syntax/
because the vim in git for windows does not provide much support in colors and syntax. Those files can be found under the folder of a fully installed Vim.
/path/to/fully/installed/vim/color/elflord.vim
to ~/vimfile/color/
.vimrc
so that Vim in Windows searches for ~/.vim
as well.Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Command y
and d
followed by a cursor movement command will yank / delete a range specified by the movement command. For example
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
There are 3 fundamental modes in Vim:
Enter a number before a command to repeat it, examples:
Commands are case sensitive:
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
vimrc
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
If you use Ctrl-V for paste, you will probably need to unmap CTRL-A first.
Difference between :%!xxd
and :%!xxd '%'
:
:%!xxd
shows the "buffer" in hex mode with the modified content. For example, A byte of 0x80
will be shown as ?
on the screen, and running :%!xxd
will show that byte as 0x3F
, which is the hex value of ?
. To display the original file content in hex mode, use :%!xxd '%'
to instruct the xxd
command to process the "current file" rather than the "current Vim buffer".
%
in the command is to specify the range (where the output of !xxd
will replace); the 2nd %
is the "register %", containing the name of the current file. The 2nd %
needs to be quoted so that Vim can handle the path in both Linux and Windows format.:%!xxd
would work just fine. To change the buffer to the binary mode, execute :e ++bin
or :set binary
.Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
These use external programs – ls
, grep
, date
, sort
(see help|:sort
to learn how to use Vim's built-in sort).
Sorting with external sort
Entering !!
in normal mode is translated to :.!
. Appending a command sends the current line to the command replacing it with command's result
You can also use !
on a visual selection. Select an area with one of the visualmode commands, and then type !command
to pipe the whole selection through command. This is equivalent to :'<,'>!command
. For example, after selecting multiple lines with visualmode:
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
There are a number of options to run applications on the Windows platform.
This causes Windows to launch the program associated with the file extension. It also restores the paste buffer to its original value:
You can also use Windows rundll32.exe
for some options:
Or, for example, you can launch Internet Explorer directly:
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Search using regular expression
Other search commands:
Note:
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Note that some patterns have different meaning in search and in replacement (ref: https://stackoverflow.com/a/3834303)
How to type | In search, means: | In replacement, means: | |
---|---|---|---|
\n | \n | End-of-line | <Nul> 0x0 |
^@ | <C-v><C-j> | <Nul> 0x0 | <Nul> 0x0 |
\r | \r | Carriage return 0xD | "Break the line here" |
^M | <C-v><C-m> | Carriage return 0xD | "Break the line here" |
^M | \ <C-v><C-m> | \ + carriage return 0xD | Carriage return 0xD |
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Between lines with marks a
and b
(inclusive), append each line starting with "Error" to a file:
Delete all lines containing "green" but not "red" or "pink". Command :g/^/
matches every line; the current line is copied into variable x
; if any part of x
matches (case sensitive) "green" and not "red" and not "pink", the line is deleted. Replace #
with ?
for case insensitive.
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
Source: http://vim.wikia.com/wiki/Best_Vim_Tips
The set of special character is determined by the magic
option (see :help magic
). The default value is "\m" ('magic'), and the corresponding set of special character is as follows:
Example of using the "word boundary" special symbol:
All the other characters will be considered as plain character to be searched. For example:
\d+
will match 1+
and 2+
, but not 12
. This is because +
is treated as plain text.\d\+
will match 12
(abc)
will match (abc)
but not abc
. This is because (
is treated as plain text\(abc\)
will match abc
, and it can be backreferenced by \1
[\d]\+
will NOT match 123
. This is because \d
within []
is treated as plain text.[0-9]\+
will match 123
When a DOS file is opened in UNIX format, ^M
appears at the end of every line. To hide that ^M
, switch the file format back to DOS by the following command:
The ++ff
is one of the ++opt
. ++ff
instructs Vim to set fileformat
to user specified value while editing the file.
Note that :e ++ff
only changes how Vim represents the file in the terminal. To convert the line ending in the file, use
Available fileformat values and the corresponding line ending:
fileformat | Line ending |
---|---|
dos | <CR><NL> |
unix | <NL> |
mac | <CR> |
The option -u "NONE" is to skip all the initialization from files and environment variables.
csv.vim
quick-ref