Vim: Difference between revisions

From DWIKI
Tony (talk | contribs)
Tag: wikieditor
Tony (talk | contribs)
Tag: wikieditor
 
(6 intermediate revisions by the same user not shown)
Line 25: Line 25:
Is not entirely correct, you need to
Is not entirely correct, you need to
  ln -s ~/.vim/autoload/vim-pathogen/autoload/pathogen.vim ~/.vim/autoload/
  ln -s ~/.vim/autoload/vim-pathogen/autoload/pathogen.vim ~/.vim/autoload/
==Macros==
See
*[https://vim.fandom.com/wiki/Macros Vim Macros]


=Cheatsheet=
=Cheatsheet=
==Moving==
===Move to next word===
w
===Move to previous word===
b
==Select==
==Select==
===Select and copy part of line===
At start hit '''ctrl-v''', use arrow keys to select and then '''y'''
then '''p''' to paste elsewhere
===Line ===
===Line ===
  y
  y
Line 51: Line 70:
  dt,
  dt,


===Delete from beginning of file to cursor===
dgg


=== Execute the script you're editing ===
 
== Execute the script you're editing ==
  :!%
  :!%
==folding==
==folding==
=== open fold ===
=== open fold ===
Line 59: Line 82:
=== unfold all ===
=== unfold all ===
  zR
  zR
==Replace with newline==
s:/foo/^V^M/g


= FAQ =
= FAQ =
==Found a swap file==
== What is this $VIMRUNTIME ==
== What is this $VIMRUNTIME ==


Line 66: Line 95:


Commands are entered by hitting the Esc button then ":" and the setting, function, command etc.
Commands are entered by hitting the Esc button then ":" and the setting, function, command etc.
==Match non-empty lines only==
s/[^^]$/ append this/





Latest revision as of 10:37, 2 April 2026

Links

Documentation

Cheatsheets

Editing xml files

Create tag pairs

Plugins

HOWTO

Pathogen

Is not entirely correct, you need to

ln -s ~/.vim/autoload/vim-pathogen/autoload/pathogen.vim ~/.vim/autoload/


Macros

See

Cheatsheet

Moving

Move to next word

w

Move to previous word

b

Select

Select and copy part of line

At start hit ctrl-v, use arrow keys to select and then y

then p to paste elsewhere


Line

y

Select until end of line

y$

Delete

Delete empty lines

:g/^$/d

Delete rest of line

D

Delete up to word

d/<word>

Delete until end of file

dG


Delete up to character

Including ,

df,

or up to ,

dt,

Delete from beginning of file to cursor

dgg


Execute the script you're editing

:!%

folding

open fold

zo, zO

unfold all

zR


Replace with newline

s:/foo/^V^M/g

FAQ

Found a swap file

What is this $VIMRUNTIME

:echo $VIMRUNTIME

Commands are entered by hitting the Esc button then ":" and the setting, function, command etc.

Match non-empty lines only

s/[^^]$/ append this/


Undo undo

ctrl-r

 



Indentation

:set filetype=xml

Enable/Disable line numbering

 set nu!

Save as root

:w !sudo tee %

Importing the output of ls -l into the current buffer

 r !ls -l

syntax highlighting on dark background

:set background=dark

Sort lines 50 to 76 ussing the unix sort command

 50,76 !sort

Change syntax colours

find syncolor.vim

Searching in Vim

End highlighting search results

<f9> <esc>:nohlsearch<cr>
:/\cfoo

show tabs

:set list and :set nolist

modelines in code

http://vim.wikia.com/wiki/Modeline_magic

In ~/.vimrc you need

set modeline

En then near top or bottom of your code something like

# vim: ts=4:sw=4:sts=0

Mind the spaces!

 


replace tabs with spaces

:%s/^\t\+/ g

disable mouse

set mouse=

disable visual

When mouse/copy is acting up, showing 'visual'

set mouse-=a