Notebook of Vim
Jun-2020
Start Vim Tutorial
$ vimtutor
Start vim with explorer window to navigate among files and folders
$ vim -c Explore
Start vim with an Explorer aside
$ vim -c Lexplore
Get into command mode
[_esc_]
Enter command in Command Mode
:
How to quit without saving
:q!
How to quit with saving (write)
:wq
How to move around in the editor
←:[h], ↓:[j], ↑:[k], →:[l]
How to undo
[u]
How to change a letter
[r]
How to delete a letter
How to copy line
[y][y]
How to cut a line
[d][d]
How to cut multiple lines, like 3 rows
[3][d][d]
How to paste
[p]
How to select letters (Visual Mode)
[v]
How to select line
[V]
How to set line numbers in the editor
:set number
How to start searching
/
How to search string
/string
How to find and replace some_letters to another_letters in the current line
:s/some_letters/another_letters
How to find and replace in the entire document (globally)
:%s/old/new/g
How to select block (Visual Block Mode) from the cursor position
[ctrl-v][hjkl]
How to increase of code line (opposite key for vice versa)
[>>]
How to increase indent of code block / multiple lines (opposite key for vice versa)
[V][jk][>]
How to execute vim commands for a file outside (in CLI) of vim
$ vim -c <"command">
Example:
$ vim ~/.bash_aliases -c ':s/alias lll="ls -lash/alias lll="ls -lashR"/g' -c ':wq'
finds and replaces alias; quit
How to insert date and time
:put =strftime(\"%Y-%m-%d %H:%M:%S\")
How to split window into panes
That command opens a file by splitting the window horizontally to top
:split <filename>
How to resize panes
:res <number to specific size>
How to resize pane 5 chars to right side
[ctrl-w][5][>]
How to resize pane 10 lines down
[ctrl-w][10][+]
How to run pyhton code inside vim
:w !python
Some strftime() format string examples
Format String Example output
------------- --------------
%c Thu 27 Sep 2007 07:37:42 AM EDT (depends on locale)
%a %d %b %Y Thu 27 Sep 2007
%b %d, %Y Sep 27, 2007
%d/%m/%y %H:%M:%S 27/09/07 07:36:32
%H:%M:%S 07:36:44
%T 07:38:09
%m/%d/%y 09/27/07
%y%m%d 070927
%x %X (%Z) 09/27/2007 08:00:59 AM (EDT)
%Y-%m-%d 2016-11-23
%F 2016-11-23 (works on some systems)
RFC822 format:
%a, %d %b %Y %H:%M:%S %z Wed, 29 Aug 2007 02:37:15 -0400
ISO8601/W3C format (http://www.w3.org/TR/NOTE-datetime):
%FT%T%z 2007-08-29T02:37:13-0400
Source: Vim Tips Wiki
Character Sets useful in vim
Use \r instead of \n to enter newlines, for example during a find&replace. Command below with the shortkey set finds null characters (^@) and replace them with newline in the entire document.
:%s/<ctrl-v><ctrl-j>/\r/g
How to install plugin with Plug
Install vim-plug for Linux (Windows requires another command in powershell):
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Download desired plugin
$ git clone https://github.com/tomlion/vim-solidity.git ~/.vim/bundle/vim-solidity
Edit ~/.vimrc
, add begin and end lines for the plugins requested to add.
call plug#begin([plugin_directory])<br>Plug 'tomlion/vim-solidity'<br>call plug#begin([plugin_directory])
Set EOL for dos/unix up
:set ff=<dos/unix>