ELUG Meetup: 23 November 2023

Topic: bash ‘vim mode’ and general discussion
Presenter: Rajiv
Physical location: Strathcona County Public Library, Maple Room; 401 Festival Lane Sherwood Park

ELUG Meetup: 22 September 2022

Topic: SSH; Or, as Rajiv put it: “Holy SSH!!t”
Presenter: Rajiv (and yes, there was some vim as well.)

Rajiv showed us some of the more advances options and uses of SSH, including how to connect through multiple layers of networked machines… FOR EDUCATIONAL PURPOSES ONLY, of course. 😉

If you want to follow along on this educational journey follow this link and watch the video

ELUG Meetup: January 27, 2022

A new year and the ELUG is still strong on their VIM journey. This month, Rajiv presented some of the really, really advance features that VIM offers. If you want to see for yourself, there is a video about that available here.

ELUG Meetup: March 25, 2021

In our last meeting on March 25, Rajiv presented advanced concepts of VIM. He walked the participants through how and when using the mouse, search, replace, open documents in tabs, vertically split the screen an a lot more. Fortunately, Rajiv also recorded the session as it would be too much to document everything in a post.

If you want to take a look at how great vim can be head over to our Nextcloud instance and check out the video here:

https://nextcloud.elug.rocks/index.php/s/DSzoWfeN5e5NEQG

ELUG Meetup: January 28, 2021

In our last meeting Rajiv was kind enough to give a fantastic overview of all the functionality that vi/vim offers. With it’s advanced features vim offers a lot of options to read but more importantly to manipulate text documents, such as log files, scripts, programs and more. Here are some useful commands

The different modes of vim

Normal /command mode - (press <ESC> to get to this mode)
Ex/last line Mode  - (press :)
Input mode - (press, i,I,a,A,o,O,s)

Input modes explained

:q  - quit
:w  - write (save)
:saveas - save as
:q! - quit without saving
:w! - write a read only file
:wq - Save and quit
:wq!     - save a read only file and quit
ZZ  - save and quit
o    - opens a new line below the current cursor line
O    - opens/inserts a new line above the current cursor line

vim can be intimidating at first. Once you get used to the tool Using vim is fairly simple and straight forward. In the normal mode you can enter certain syntax

[optional number] verb + noun
d – delete
w - word
combine them (dw) to delete word
commands are repeat-able (.) and undo-able (u)

This syntax executes a command, in the above example deleting a word. If you put a number in front, for example 2, the command will delete 2 words.

How do you know what verbs to use? Here they come.

d   - delete
c   - change
v   - visual select
y   - yank (copy)
p   - paste
>>  - right indent
<<  - left indent

Once you know how you can change a document it is time to look at how to get to the position that you want to got to. There are a few commands to move around in the document.

h   - left
j   - down 
k   - up
l    - right
ctrl+u  - Page up (80x24)
ctrl+d  - Page dn (80x24)
ctrl+f  - screen up
ctrl+b  - Screen dn
^,0 - beginning of line
$    - end of line
gg  - beginning of the file
G   - end of the file

Lets look at an example how to use these movements. By entering 5j in the normal mode you will now move 5 lines down. Entering 10k moves your cursor 10 lines up.

Combining commands

Verbs can be combined. Lets take a look at some examples:

d$  - delete to end of line
y$  - yank/copy to end of line
#dd - delete # number of lines
#yy - yank # number of lines

Nouns

Where there are verbs there are nouns. vim offers the whole set of language. Let’s take a look at what nouns can be used in vim.

d   - word
p   - paragraph
b   - back
iw  - inner word (defines a region)
i   - inner (can be used with pretty much anything)
ip  - inner paragraph
a   - around
as  - around sentence

Parameterized Objects

f,F<phrase>   - find (next character, capitals for backwards)
t,T<phrase>   - find (up to but not including the next character)
/,?<phrase>   - Search (up to next match)
/,?<phrase>\c - search but ignore case
n        - next search item
N        - previous search item   

Examples:

Parameterized objects can be combined with other items.

the quick brown fox jumped over the lazy sleeping dog

Assuming the cursor is at the beginning of the line the command ctc will take cursor to the 1st c in the statement.

Advanced commands

:set number      - absolute line number
:set relativenumber - set relative line number
ctrl+v           - visual block
:set mouse+=a       - enable mouse 
:s/find/replace/g   - find and replace string in a file
:s/find/replace/gc  - same as above but interactive
:#,#s/find/replace/g   - same as above within those lines
:set incsearch       - incremental search
:set hlsearch        - highlighted search
:noh             - removes highlights
:sp          - split windows (horizontally) 
:vsp             - split vertically
ctrl+w w         - move cursor to next vim window
ctrl+w r         - move the current window to vertically
ctrl+w x         - move the current window to horizontally
:tabedit         - open new vim tab
gt           - move between tabs
:!<commmands>      - run bash commands
:%!<commands>      - run bash commands on current file
                         and return results back to vim buffer
~            - change case
q<character>       - records macro
q            - stops macro
@<character>      - plays macro
q<character>q      - clears a macro
|topic|, *topic*     - create tags in a text file
:helptags ./         - create tags file 
%            - follow the parantheses, brackets
                         or quotes    
J            - join two lines
"           - multiple clipboards
/pl[abc]ce       - search for place, plbce, plcce
ctrl+p           - in insert mode - complete the word   
*            - search for the current word
                         under the cursor
ctrl+o,ctrl+i       - jump back and forward between open
                      files with e
:set ignorecase      - ignore case
:'a,'bs/find/replace/g - find and replace between two mark
                         points marked 'a' and 'b' (mark with m)
"ay             - copy to register 'a' (paste with "ap)