0% found this document useful (0 votes)
4 views7 pages

Gvim Commands Notes

Uploaded by

sfaizu664
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Gvim Commands Notes

Uploaded by

sfaizu664
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Why Editors?

Editors were introduced to replace inefficient manual methods of writing programs


and to make software development interactive, efficient, and manageable.

Function
1. Write code: To type source code instead of using
paper/tapes
2. Edit code quickly: To change, add, or delete code without rewriting it
3. Visual feedback: To see code structure and fix mistakes easily
4. Save and reopen files: To work on programs over time
5. Interact with tools: To run compilers, debuggers, etc., from the same interface

What Editors Made Possible?


#Faster development
#Reusability (open, edit, reuse files)
#Team collaboration (share readable code)
#Debugging (jump to error lines)
#Extensibility (syntax highlighting, auto-indent, plugins)

****************************************************************
For debian like OS(i.e Debian, ubuntu)
sudo apt install vim
--------------------
For Redhat like OS(i.e Redhat, fedora, centos, centos stream)
sudo yum install vim

gVim Installation:-
For debian like OS(i.e Debian, ubuntu)
sudo apt install vim-gtk3
----------------------------
For Redhat like OS(i.e Redhat, fedora, centos, centos stream)
sudo yum install gvim
-----------------------
***********************************************************************************
******
GVim (Graphical Vim) is a GUI version of the Vim text editor, providing a graphical
interface and additional features while retaining the powerful command-line
capabilities of Vim. Here is a detailed explanation of various GVim commands and
their functionalities:

:sp ~/.vimrc This command to open .vimrc file its an hidden file.In that file type
below commands by pressing i-insert mode
set hlsearch-->highlight search terms
set incsearch show search matches as you type
set number -->set line number
set showmode--->always show what mode we're currently editing in
set autoindent --->always set autoindenting on
set tabstop=4 --->a tab is four spaces
set syntax=ON -->syntax highlighting
set nocompatible -->set nocompatible is used in GVim (and Vim) to switch from "Vi-
compatible" mode to "Vim-enhanced" mode.
set backspace=indent,eol,start --->allow backspacing over everything in insert mode
set guifont=consolas:h17--->is used in GVim (Graphical Vim) to specify the font and
font
size for the text displayed in the GUI version of Vim.
syntax on --->in GVim (and Vim) is used to enable syntax highlighting. Syntax
highlighting is a feature that displays text—especially source code—
in
different colors and fonts according to the category of terms.

Gvim modes
-----------
Insert mode(i,I,A,a)
escape mode(command mode or normal mode)(Esc)
visual mode(v,V,ctrl+v)
recording mode q

In GVIM, insert mode allows you to insert new text into the document. Here is a
list of some commonly used insert mode commands:
'i'--insert text before the cursor
'I'--insert text at the begininng of the current line
'a'--Append text after the cursor
'A'--Append text at the end of the current line
'o'--insert a new line below the current line and start insert mode
'O'--insert a new line above the current line and start insert mode
'r'--replace one character under the cursor
'R'--replace multiple character,starting at cursor position
's'--Delete the character under the cursor and insert new text.
'S'--Delete the current line and insert new text
'C'--Delete to the end of the line after the cursor and insert new text
'cc'--Delete the entire line and insert new text
'cw'--Delete the word under the cursor and insert new text
'c$'--Delete to the end of the line & insert the new text.
'Crtl+p'--->pool of words only command used in insert mode.

File Management:
________________
create,open,save,close/quit

To open file there are two ways


1.vertical split the window
:vspl <filename.ext>(.txt,.doc,.v,.py)
2.horizatal split the window (default)
:spl <filename.ext>
*create a file outside the gvim and open with gvim
*open gvim and when you are saving the file give a name to that file.

How save a file?


*The commands used to save a file
:w --write one file
:wa --write all files
:w with<filename>
Note:if you find a [+] sign after the filename,this file not saved.

How to close/quit the file


*the commands used to quit a file
:q quit
:wq save and quit
:q! quit without saving
:wqa save and quit all
:qa quit all

Copy and Paste


--------------
yy - Yank (copy) a line.
nyy--> copies 'n' no. of lines
yw - Yank (copy) a word.
nyw--> to copy 'n' number of words
y$ - Yank (copy) to the end of the line.
y0 - Yank (copy) to the beginning of the line.
p - Paste after the cursor.
np--> paste the 'n' number of times
P - Paste before the cursor.

Deleting
---------
x - Delete the character under the cursor.
dw - Delete a word.
dd - Delete an entire line.
d$ - Delete from the cursor to the end of the line.
d0 - Delete from the cursor to the beginning of the line.
dgg - Delete from the cursor to the beginning of the file.
dG - Delete from the cursor to the end of the file.

Navigation
-----------
h - Move left. ex:10h-move 10 character left side
j - Move down. ex:10j-move 10 lines down
k - Move up. ex:10k-move 10 lines up
l - Move right.ex:10l-move 10 characters right side
gg - Go to the beginning of the file.
G - Go to the end of the file.
0 - Move to the beginning of the line.
$ - Move to the end of the line.
w - Move to the next word.
b - Move to the previous word.
Ctrl+o - Move to the previous cursor position.
Ctrl+i - Move to the next cursor position.
Ctrl+f - Move the contents of the file in forward
Ctrl+b - Move the contents of the file in bachward

Window Management
------------------
:split or :sp - Split the window horizontally.
:vsplit or :vsp - Split the window vertically.
Ctrl+w w - Switch between windows.
Ctrl+w q - Quit the current window.
Ctrl+w s - Split the window horizontally and switch to the new window.
Ctrl+w v - Split the window vertically and switch to the new window.
Ctrl+w h - Move to the left window.
Ctrl+w j - Move to the window below.
Ctrl+w k - Move to the window above.
Ctrl+w l - Move to the right window.

Searching
---------
/pattern - Search for pattern.
?pattern - Search backwards for pattern.
n - Repeat the search in the same direction.
N - Repeat the search in the opposite direction.
:%s/old/new/g - Replace all occurrences of old with new in the entire file.
:s/old/new/g - Replace all occurrences of old with new in the current line.
* search the word
/ search the word
:%s/pattern-to_search/pattern to replace/g
:%s/pattern-to_search/pattern to replace/gc
:%s/pattern-to_search/pattern to replace/
:line no.s/pattern-to_search/pattern to replace/
:lower_range,upper_ranges/pattern-to_search/pattern to replace/g
:lower_range,upper_ranges/pattern-to_search/pattern to replace

:%s/pattern-to_search/pattern to replace/gc
Replace with Hi (y/n/a/q/l/^E/^Y)?
____________________________________________
y: Replace this instance and move to the next match.
n: Skip this instance and move to the next match.
a: Replace all remaining matches without further confirmation.
q: Quit the search and replace operation.
l: Replace this instance and then quit.
^E (Ctrl+E): Scroll the screen up.
^Y (Ctrl+Y): Scroll the screen down.

Visual Mode
------------
v - Enter visual mode (select text character-wise).
V - Enter visual line mode (select entire lines).
Ctrl+v - Enter visual block mode (select columns).
'I' inserts to the left of visual block
'A' inserts to the right of visual block
c--> to change the visual block data

y - Yank (copy) the selected text.


d - Delete the selected text.
c - Change (replace) the selected text.

Tabs
-----
:tabnew or :tabe filename - Open a new tab with filename.
:tabclose - Close the current tab.
:tabnext or :tabn - Switch to the next tab.
:tabprevious or :tabp - Switch to the previous tab.
:tabfirst - Go to the first tab.
:tablast - Go to the last tab.

Advanced Commands
Macros
q{register} - Start recording a macro into the specified register.
q - Stop recording the macro.
@{register} - Execute the macro stored in the specified register.
@@ - Repeat the last executed macro.
Vim Macros(vim recording)
In command mode it works
to start recording press 'q' followed by a register name (it can be number or
alphabet)
to stop recording press 'q'
to play recording press '@register name'

********************************************
set number ---> " Show line numbers
set incsearch ---> " Show matches while typing search
set showmode ---> " Show current mode (e.g., -- INSERT --)
set hlsearch ---> " Highlight all search matches
set tabstop=4 ---> " Set tab width to 4 spaces
set tabpagemax=100 ---> " Maximum number of tab pages
set nocompatible ---> " Use Vim settings, not Vi compatibility
set guifont=Consolas:h15 ---> " Set font (GUI only, fixed syntax)
set backspace=indent,eol,start ---> " Make backspace work as expected
set autoindent ---> " Auto-indent new lines
syntax on ---> " Enable syntax highlighting

********************************************

*set tabpagemax=100 ---> Maximum number of tab pages

This setting controls the maximum number of tab pages Vim will open at startup when
you provide multiple files or directories on the command line.

*Think of it like browser tabs, where each tab can have its own layout of split
windows.
*Use :tabnew, :tabnext, :tabclose, etc., to manage tab pages.

# Purpose of tabpagemax
When you open Vim with multiple files or use wildcards (vim *.c), Vim can open each
file in a separate tab page, but only up to the limit set by tabpagemax.

So, this setting tells Vim:


Do not open more than N tab pages at startup, even if more files are given.
Then Vim will open up to 100 tab pages (assuming 100+ files are passed).
Remaining files will still be loaded in the argument list, and you can navigate to
them using:

:next or :n
:args
:first, :last

*This setting only affects startup behavior, not manual opening of new tab pages
later.

*If you want to open all files in buffers instead of tab pages, you can configure
differently (e.g., using a plugin like vim-argwrap or using buffers intentionally).

*****************************************
*set nocompatible:

It tells Vim not to behave like the original Vi editor (from the 1970s), but
instead to use Vim’s enhanced features.

Enables Vim's full feature set.

You get:

Syntax highlighting

Better key mappings


Auto-indenting

Visual mode

More user-friendly backspace behavior

Support for .vimrc

Plugins and customizations

example:
Without nocompatible, in insert mode:

Pressing backspace won’t delete over auto-indents or line breaks.

With nocompatible:

Backspace behaves like you'd expect in a modern editor.

*************************************************

*set guifont=Consolas:h15

This line sets the font used in the GUI version of Vim (like GVim or MacVim), not
the terminal version.

set guifont ----> Vim option to set the GUI font


Consolas ----> The name of the font you want to use (a clean monospaced font)
:h15 ---> The height of the font in points (15pt font size)

***************************************
* set autoindent

It is used to automatically preserve the indentation of the previous line when you
press Enter and start a new line while coding or writing text.

What is indentation?

Indentation is the practice of adding spaces or tabs at the beginning of lines of


code to show structure and hierarchy.

why Indentation?

Readability
Structure Clarity
Debugging Ease
Team Collaboration
Syntax Requirement (in some languages) :In languages like Python, indentation is
mandatory

for the code to work correctly

****************************************************
set backspace=indent,eol,start
The option backspace=indent,eol,start tells Vim to allow the Backspace key to
delete:

indent You can backspace over auto-indented spaces or tabs


eol You can backspace over the end-of-line (i.e., join lines backward)
start You can backspace before where you entered insert mode
*************************************
syntax on

enables syntax highlighting in Vim — a feature that colorizes different parts of


your code or text depending on its syntax (language rules).

Helps With --->Readability, code clarity, debugging


Where to use --->In your .vimrc or at the Vim command line
Works For --->Most languages (Verilog, Tcl, Python, C, etc.)

You might also like