Tools Index

Vim

<leader> with default configuration is key \, so when you see <leader>-W means pressing \W

1. Vim RC

Read "A good vimrc" for more information.

/usr/share/vim/vimrc
System wide Vim initializations.
~/.vimrc
Your personal Vim initializations.

Copy /etc/skel/.vimrc skeleton example, so that each user have a base to start personalizing it;

        $ sudo cp ~/doc/conf/etc/skel/.vimrc /etc/skel/
        $ sudo mkdir /etc/skel/.vim
        $ sudo mkdir /etc/skel/.vim/swap
        $ sudo mkdir /etc/skel/.vim/views
        $ sudo mkdir /etc/skel/.vim/undodir
        $ sudo mkdir /etc/skel/.vim/backup
        $ wget -O wombat2mod.vim  http://www.vim.org/scripts/download_script.php?src_id=40
        $ mv wombat2mod.vim /usr/share/vim/colors/
        

2. Color schemes

Default vimrc skeleton is configured to use wombat2mod, which is installed by adduser skeleton.

3. Split and Tab

Horizontal split;

        :sp
        

Vertical split;

        :vsp
        

Change horizontal to vertical

        ctrl+w H
        

Change vertical to horizontal

        ctrl+w J
        

Move between window splits;

        ctrl+w (k,j,l,h)
        

4. File browser

Use built in netrw to see directories and files;

:Explore
Opens window with file browser.
:Sex
Open horizontal split with file browser.
:Vex
Open vertical split with file browser.

To find files, run vim at top level of project and then use find auto completion or *;

        :find nameofdirectory + Tab
        :find nameofdir* + Tab
        

For file browsing there is also a option to use edit;

        :edit nameofdirectory/
        

5. Editing files

Come from background;

        $ fg
        

Moving in vim

Moving page up and page down;

[Control][b]
Move back one full screen
[Control][f]
Move forward one full screen
[Control][d]
Move forward 1/2 screen
[Control][u]
Move back (up) 1/2 screen

How to use vim

In vim you can apply predefined number of times to a operator, selection or object. For example to delete the next two words press: d + 2 + w. List of important operators objects, selections;

        operator + count + object
        

Operator;

d
Delete
c
Change (d + i)
y
Copy
v
Visual Select

Objects;

w
Word
s
Sentences
p
Paragraphs
t
Tags

Selections are like objects, for example d + i + w will delete "inner" word, c + a + w do the same plus the space;

a
All
i
in
t
Until
f
Find forward
F
Find backward

Selection of useful combinations;

vat
Select whole tag block.
cit
Change inside tag.
yat
Copy whole tag.
vip$A,
Select a paragraph (vip), switch to visual block mode (CTRL V), append to all lines ($A) a comma (,), press esc to confirm.
vip<C-V>I,<Esc>
Select a paragraph (vip), switch to visual block mode (CTRL V), insert to all lines (I) a comma (,), press esc to confirm.

6. Tags

Tags, at top level of project;

        $ ctags -R .
        $ vim src/hello_world.c
        

To follow a tag;

        Ctrl-]
        

To get back;

        Ctrl-t
        

Autocomplete, press to see all options;

        Ctrl-n
        

To move forward and backward in options;

        Ctrl-n Ctrl-p
        

Show auto completion with references to only this file;

        Ctrl-x Ctrl-n
        

Show auto completion with filenames, * Tab can be used;

        Ctrl-x Ctrl-f
        

Show auto completion with only tags;

        Ctrl-x Ctrl-]
        

7. Spellcheck

Press z= over the bad written word and select desired one.

8. Plugins

9. Vimdiff

If two files are open in split type :diffthis in both windows to get vimdiff of the files. To close type :diffoff.

do
Get changes from other window into the current window.
dp
Put the changes from current window into the other window.
]c
Jump to the next change.
[c
Jump to the previous change.
Ctrl W + Ctrl W
Switch to the other split window.
Tools Index

This is part of the Hive System Documentation. Copyright (C) 2019 Hive Team. See the file Gnu Free Documentation License for copying conditions.