Vim: Difference between revisions

From wikinotes
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
A fast, customizable, cross platform mode based text editor that usually runs in a console.
A fast, customizable, cross platform editor that generally runs in a console.


Vim is uniqe in that it is modal:
Vim is uniqe in that it is modal:
Line 14: Line 14:
<blockquote>
<blockquote>
{| class="wikitable"  
{| class="wikitable"  
|-
| home || https://www.vim.org/
|-
| <code>:help</code> || https://vimhelp.org/
| <code>:help</code> || https://vimhelp.org/
|-
|}
|}


Line 21: Line 25:
= Locations =
= Locations =
<blockquote>
<blockquote>
 
{| class="wikitable"
{| class="wikitable"  
|-
!colspan=2| Unix
|-
| <code>~/.vimrc</code> || user config
|-
| <code>~/.vim</code> || user libraries, syntax, help, plugins, ...
|-
| <code>${PREFIX}/share/vim/vim82</code> || official config
|-
| <code>${PREFIX}/share/vim/vimfiles</code> || distro config
|-
!colspan=2| Windows
|-
|-
| <code>~/.vimrc</code><br>
| <code>%HOMEDRIVE%%HOMEPATH%/_vimrc</code> || user config
<code>%HOMEDRIVE%%HOMEPATH%/_vimrc</code>
|| configuration
|-
|-
| <code>~/.vim</code><br>
| <code>%HOMEDRIVE%%HOMEPATH%/vimfiles</code> || user libraries, syntax, help, plugins, ...
<code>%HOMEDRIVE%%HOMEPATH%/vimfiles</code>
|| plugins, libraries, etc
|-
|-
|}
|}
Line 43: Line 54:
|-
|-
| [[vim install]]
| [[vim install]]
|-
| [[vim troubleshooting]]
|-
|-
|}
|}
</blockquote><!-- Basics -->
</blockquote><!-- Basics -->
= Install =
<blockquote>
<source lang="bash">
# archlinux (packages have most languages preinstalled)
pacman -S vim
pacman -S gvim
# freebsd
# ubuntu (default package minimal, noXorg variant has all)
sudo apt install -y vim-nox
</source>
</blockquote><!-- Install -->


= Usage =
= Usage =
Line 67: Line 64:
{|
{|
|-
|-
| [[vim commandline]]
| [[vim cli]]
|-
|-
| [[vim diff]]
| [[vim diff]]
|-
| [[vim printing]]
|-
|-
|}
|}
Line 77: Line 76:
<blockquote>
<blockquote>
{|
{|
|-
| [[viml]]
|-
| [[vim options]]
|-
| [[vim autocmd]]
|-
|-
| [[vim keybindings]]
| [[vim keybindings]]
|-
|-
| [[viml]]  
| [[vim plugins]]
|-
|-
| [[vim plugins]]
| [[vim indenting]]
|-
| [[vim after-directory]]
|-
|-
|}
|}
</blockquote><!-- Configuration -->
</blockquote><!-- Configuration -->


= Components =
= Features =
<blockquote>
<blockquote>
{|
{|
|-
| [[vim help]]
|-
|-
| [[vim commands]]
| [[vim commands]]
|-
|-
| [[vim filetypes]]
| [[vim folds]]
|-
|-
| [[vim folding]]
| [[vim registers]]
|-
|-
| [[vim buffers]]
| [[vim macros]]
|-
|-
| [[vim registers]]
| [[vim motions]]
|-
|-
| [[vim macros]]
| [[vim cursor stacks]]
|-
|-
| [[vim ctags]]
| [[vim ctags]]
|-
| [[vim digraphs]]
|-
| [[vim profiling]]
|-
| [[vim shell]]
|-
|-
|}
|}
</blockquote><!-- Components -->
</blockquote><!-- Features -->
 
 
[[vim tips/tricks]]
 
 
= Behaviour =
<blockquote>
=== Buffers ===
Buffers are any text that vim stores. It is typically associated with a file
 
=== Registers ===
Registers are places where you can copy text to for processing. There is the system clipboad
register, the standard vim register, named registers, etc. Registers are accessed by using <code>"</code>
followed by a letter(the register), and then the operation you want to perform on it. When yanking,
if you use a capital letter, you will append to your register instead of replacing it.
 
<syntaxhighlight lang="vim">
@                                      ""The yank-text register
"zyy ""Copy Line under text to register 'z'
"Zyy ""Append Line under text to existing register 'z'
"zp ""Paste register 'z'
 
let var = @z ""Save contents of register 'z' to a variable
</syntaxhighlight>
 
You can also record expressions to registers.
<source lang="vim">
let @* = expand('%:p')  " copy current filepath to clipboard
</source>
 
=== Filetypes ===
sometimes you want to use syntax highlighting for files that aren't really programs.
sometimes you want certain programs to be recognized as their proper filetype while using a different extension.
 
<syntaxhighlight lang="vim">
set filetype=python      #sets current filetype to python
set filetype=?            #query current filetype
 
au BufRead,BufNewFile *.cpy set filetype=python  #auto associate filetypes with extensions (in your .vimrc)
</syntaxhighlight>
 
=== Macros ===
<source lang="vim">
q<letter>    # start recording macro bound to <letter>
q            # stop recording
 
@<letter>    # play-back recording
</source>
</blockquote><!--Behaviour-->

Latest revision as of 15:46, 10 February 2024

A fast, customizable, cross platform editor that generally runs in a console.

Vim is uniqe in that it is modal:

  • text is written in insert mode
  • navigation is performed in normal mode
  • selections made in visual mode
  • commands entered in command mode

Each has it's own keybindings.


Documentation

home https://www.vim.org/
:help https://vimhelp.org/

Locations

Unix
~/.vimrc user config
~/.vim user libraries, syntax, help, plugins, ...
${PREFIX}/share/vim/vim82 official config
${PREFIX}/share/vim/vimfiles distro config
Windows
%HOMEDRIVE%%HOMEPATH%/_vimrc user config
%HOMEDRIVE%%HOMEPATH%/vimfiles user libraries, syntax, help, plugins, ...

Basics

vim intro
vim install
vim troubleshooting

Usage

vim cli
vim diff
vim printing

Configuration

viml
vim options
vim autocmd
vim keybindings
vim plugins
vim indenting
vim after-directory

Features

vim help
vim commands
vim folds
vim registers
vim macros
vim motions
vim cursor stacks
vim ctags
vim digraphs
vim profiling
vim shell