Skip to content

Instantly share code, notes, and snippets.

@nhthai2005
Last active June 7, 2022 05:38
Show Gist options
  • Save nhthai2005/7b15f40cd35c14a656f3ae72ba693d8d to your computer and use it in GitHub Desktop.
Save nhthai2005/7b15f40cd35c14a656f3ae72ba693d8d to your computer and use it in GitHub Desktop.
vim: quick column insert

To use ViM(Vi) column mode edit use following commands.

  • Ctrl + v column mode edit command
  • Select the columns, rows (h,j,k,l)
  • Shift + i to go into insert mode in column mode
  • Type in desired text. At the time of typing only ONE row is changed, showed
  • Press the Esc key to apply the changes to the selected column

Reference: http://www.uni-koeln.de/~pbogusze/posts/ViM_column_mode_edit.html

Indent multiple lines quickly in vi:

gg: jump to the top of the file
V : start a visual selection that grabs entire lines at a time
G : go to the end of the file (in this case, selecting everything from start to end)
<<: move selected text left by one indentation
. : repeat last command (in this case, the one that says we should indent everything in the file one left)

:left and :right and :center

>>   Indent line by shiftwidth spaces
<<   De-indent line by shiftwidth spaces
5>>  Indent 5 lines
5==  Re-indent 5 lines

>%   Increase indent of a braced or bracketed block (place cursor on brace first)
=%   Reindent a braced or bracketed block (cursor on brace)
<%   Decrease indent of a braced or bracketed block (cursor on brace)
]p   Paste text, aligning indentation with surroundings

=i{  Re-indent the 'inner block', i.e. the contents of the block
=a{  Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block

>i{  Increase inner block indent
<i{  Decrease inner block indent

In insert mode, Ctrl-T indents the current line, and Ctrl-D unindents.

Indentation without hard tabs

set expandtab       "Use softtabstop spaces instead of tab characters for indentation
set shiftwidth=4    "Indent by 4 spaces when using >>, <<, == etc.
set softtabstop=4   "Indent by 4 spaces when pressing <TAB>

set autoindent      "Keep indentation from previous line
set smartindent     "Automatically inserts indentation in some cases
set cindent         "Like smartindent, but stricter and more customisable

set shiftwidth=2
set tabstop=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment