Skip to content

Instantly share code, notes, and snippets.

@shinokada
Last active February 28, 2024 14:10
Show Gist options
  • Save shinokada/20b6803dd160a3114c40f67d9a5ea14f to your computer and use it in GitHub Desktop.
Save shinokada/20b6803dd160a3114c40f67d9a5ea14f to your computer and use it in GitHub Desktop.
vim notes
# vim
cw change word
dw delete word
d3w delete 3 words
dd delete line
dfa delete forward (including) a
dtu delete til u
d$ delete from the cursor to the end of the line
ctrl-u scrolling upwards
ctrl-d scrolling downwards
ctrl-g display a status line
:set number display line numbers
:set nonumber turn of line numbers
gg move to the first line
1G move to the first line
3G move to the third line
G move to the last line
fx find character ‘x’ forward, e.g. fc find character ‘c’
Fx find ….............. backward
3fa find the third ‘a’
tx move til (in front of) charactor ‘x’
; repeat f,F,t or T
, repeat f,F,t or T backward
#w # words forward
#W # WORDS forward
#+ # lines downward
#- # lines upward
#e forward to the end of word
#E forward to the end of WORD
#b # words backward
#B # WORDS backward
$ move to the end of line
#$ move to the end of # lines
0 to the first character of the line
^ to the first non-blank character of the line
u undo changes
ctrl-r redo changes
U undo all changes on one line
. repeat last delete or change
J join two lines
3J join three lines
ra replace to character a
5ra replace 5 characters with a
R replace letters until esc is pressed
#s delete letters and insert. substitute # number of letters
#S lines
~ change a case, from small to capital, capital to small letter. Need to hit it twice in my keyboard
>> indent one line
>5> indent 5 lines
>G indent til the end of file
< unindent (use same methods as above)
== indent one text line
=3= indent 3 text lines
macro
http://vim.wikia.com/wiki/Macros
qa start and end macro and register it in ‘a’. then recode the key stroke to record
#@a repeat a macro ‘a’ # of times
Digraph: Special characters
i ctrl-k insert mode, this starts ? ready to enter a special character
:digraph This will show all the special charcters
e.g.
i ctrl-k 12 a halp
i ctrl-k cO copy right mark
i ctrl-k GF trade mark
Chapter 3 Search
/(word) search
#n search # number next
#N search # number before
/(page up/page down) this will show the history of search
:set hlsearch add highlight to searched words
:set nohlsearch no highlight to searched words
:set incsearch set incremental search. Each additional character further refines the search.
:set noincsearch take off incremental search
? search backward, ‘n’ continue to search backward, N search forward
/(word) n ? n search a word, n: next word, ?: search backward, n: search backward
page 32 Regular expression
/^(word) search the word where only if it is the beginning of the line
/(word)$ search the word where only if it is the end of the line
^(word)$ search a line consisting of just the word
^$ search empty lines
. match any single character e.g c.m search , com, computer, cam, become etc
\. matching a special character ‘.’ Escape special character with \
Chapter 4
#p put deleted line/word # of times after the cursor
#P same as above except before the cursor
dd p delete a line and put it after the cursor
dw p delete a word and put it after the cursor
ma mark the position as a, mb marks the position as b etc
‘a move to the position where you marked as ‘a’
ma (move cursor) d’a mark the position as ‘a’ and move the cursor then delete upto there
yy copy a line
#yy copy # of lines
ma (move) y’a (move) p mark the position as a and move the cursor then yank upto there, then move a position and put it there.
yw yank a word, if it is a middle of a word, then yank from there to the end of the word
#yw yank # of words
(!motion command) ! is followed by a motion command like followings.
!10Gsort(enter) sort from a cursor’s position to line 10
!!(man command) !!date will outputs the date, !!ls will outputs the directory list
:set spell set spell check
:set nospell take off spell check
:help spell
]s — move to the next mispelled word
[s — move to the previous mispelled word
Chapter 6 Basic visual mode
v enter to visual mode
V enter to visual line mode
:help v_d shows help of d in visual mode
ctrl-v enter to visual block mode
d delete the highlighted text
D delete the highlighted lines (even the cursor is highlighting a part of line)
y yank the highlighted text
Y yank the highlighted lines (even the cursor is highlighting a part of line)
c change highlighted texts (delete texts and insert)
C change hightlighted lines (delete line and insert)
J join highlighted lines (even partially) with a space between
gJ join highlighted lines without a space
ctrl v then j to go down, shift i to insert at the beginning of the block.
insert a word, escape/esc then the word will be inserted to all the lines.
ctrl v, then j to go down, x to delete a one column, then ‘.’ to repeat the delete
gv select the same area as previously seletcted (recall the selected area)
working with many files 1
:ls list the buffers
:h ls show help on ls
adding alias through terminal
alias g=’vim --remote-silent’
cd /home/shin/.vim/plugin
g m* opens all the files start with m,
:b mar(tab) will display for example :b mark.vim
:b# shows a buffer with # in the ls, or the recent buffer
:bd delete the current buffer
:bd 3 4 will delete #3 and 4 buffer in ls
:bd name_of_buffer another_name
will delete both buffer
20, 26bd will delete buffer number 20 - 26
%bd will delete all buffers
Using vim plugin Surround
http://www.youtube.com/watch?v=5HF4jSyPpvs&feature=player_embedded
Hello world
Vs <strong> ‘V’ to enter visual mode, ‘s’ to enter surround and enter <strong>
VS<strong> same as above except indent a line
viws’ vim: visual inner word to select a word s:surround with ‘’’(single ‘)
viws<em> surround with <em></em>
cst <strong> change surrounding tag to <strong></strong>
dst delete surrounding tag
cs’” change surround from ‘ to “
ds” delete surrounding “
http://www.thegeekstuff.com/2009/01/vi-and-vim-editor-5-awesome-examples-for-automatic-word-completion-using-ctrl-x-magic/#more-328
1. Word/pattern completion using ctrl-x ctrl-n
If there are already words and you want to use it.
CTRL-x CTRL-n : Word completion – forward
CTRL-x CTRL-p : Word completion – backward
Complete an existing word in the file, without retyping it.
Complete a variable name or a function name on your program or shell-scripts.
2. Line completion using ctrl-x ctrl-l
This insert an EXISTING line in the same file.
Repeat an existing line quickly in your file.
Automatically fill first line of the function definition, when the function is already declared elsewhere in the same file.
3. File Name completion using ctrl-x ctrl-f
Typical usage: When you give the path of the file name as a reference INSIDE a document.
4. Thesaurus word completion using ctrl-x ctrl-t
5. Dictionary word completion using ctrl-x ctrl-k
Add the following to .vimrc
$ cat ~/.vimrc
set dictionary+=/usr/share/dict/words
http://www.thegeekstuff.com/2009/08/vim-editor-how-to-setup-most-recently-used-documents-features-using-mru-plugin/#more-1274
:MRU shows most recently used
increase the number of list
$ cat ~/.vimrc
let MRU_Max_Entries = 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment