forked from rrrgh/exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim-rfrnc
205 lines (162 loc) · 7.76 KB
/
vim-rfrnc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
~/.vimrc
" tabstop: Width of tab character
" softtabstop: Fine tunes the amount of white space to be added
" shiftwidth Determines the amount of whitespace to add in normal mode
" expandtab: When on uses space instead of tabs
set tabstop =4
set softtabstop =4
set shiftwidth =4
set expandtab
#tab -> space
:%s/^\s\{2,}/ /
#move { to function signature line
:%s/)\s*\(.*\)\s*\r*\n\s*{\s*/) { \1/
.,$s/\n/\rgit pull\r/
:%g/^.\{-,5}$/d
#read range of lines from a file into current buffer
:r !sed -n 24,410p ~/Downloads/Ex_files_Creating_a_website_using__Bootstrap/wiredwiki.html
#oros(Русский) --> oros\(Русский\)
:%s/\([(|)]\)/\\\1/g
:sort u (Uniq - Removing duplicate lines, sort all lines and remove duplicates (keeping unique lines))
#replace space with new line
Use Control-v and then Enter key instead of \n. Control-v is the special character escape key.
#insert timestamp in Vim
:r! date "+\%Y-\%m-\%d \%H:\%M:\%S"
:r !date +%F
The above commands insert the output of the date program after the current line. If wanted, the !! command can be used to filter the current line, replacing it with the output of date.
W: Move forward a WORD (any non-whitespace characters).
#system clipboard
copying/pasting from the system clipboard will not work if :echo has('clipboard') returns 0.
#Make Vim use the system clipboard as the default register
If your version of Vim supports both the +clipboard and +xterm_clipboard features, then you might prefer to use this setting instead:
if has('unnamedplus')
set clipboard=unnamed,unnamedplus
endif
Vim has extended vi to allow use of the * register as a reference to the system clipboard. So we can use normal mode commands like: "*dd or 1G"*yG to copy things into the * register and "*p to paste text from it. We can also use this * register with the ex yank command, so :%y * will accomplish the same goal as gg"*yG (copy all text into the system clipboard so it can be pasted into an X or MS Windows application).
e.g.
nnoremap <C-Tab> :bn<CR> #buffer next
nnoremap <C-S-Tab> :bp<CR> #buffer previous
vim ~/.zshrc ~/.zsh-func
X11-clipboard support in terminal
Getting Vim to work with the X11 clipboard can be a struggle, at least when you like to run Vim in a terminal. The GUI version of Vim always has clipboard support, however, if you like to use Vim from a terminal, you will have to check for X11-clipboard support.
From the console, type:
% vim --version
If you see "+xterm_clipboard", you are good to go. If it's "-xterm_clipboard", you will need to look for a version of Vim that was compiled with clipboard support.
u: undo last change (can be repeated to undo preceding commands)
Ctrl-R: Redo changes which were undone (undo the undos). Compare to '.' to repeat a previous change, at the current cursor position. Ctrl-R will redo a previously undone change, wherever the change occurred.
A related command is:
U: return the last line which was modified to its original state (reverse all changes in last modified line)
U is not actually a true "undo" command as it does not actually navigate undo history like u and CTRL-R. This means that (somewhat confusingly) U is itself undo-able with u; it creates a new change to reverse previous changes.
U is seldom useful in practice, but is often accidentally pressed instead of u, so it is good to know about.
#delete non-contiguous duplicate lines without sort
$ awk '!a[$0]++' file
#vim uniq preserve order
:%!awk '\!a[$0]++'
#vim global command :g
:[range]g/pattern/cmd
:g/ll\|pwd\|src\|ss/d
#Vim Uppercase & Lowercase
Convert a visual selection to all uppercase letters.
gU
Convert to lowercase letters
gu
uppercase until end of word:
gUw
Or, two words:
gU2w
Or, end of the line:
gU$
Or, next 10 characters:
gU10l
to change all UPPERCASE letters to lowercase letters in a file:
ggguGG
or
:%s/[A-Z]/\L&/g
:[range]s/\s*\[\|\]//g
[[ "$1" =~ *error* ]] :failed to compile regex: Invalid preceding regular expression
:%s/\($?\)/'&':&/gc (& : the whole matched pattern)
vim Repeat last colon command (The last command entered with ':' can be repeated with @: and further repeats can be done with @@)
#Replacement part of the S&R
& the whole matched pattern
~ the previous substitute string
\r split line in two at this point
\l next character made lowercase
\u next character made uppercase
:%s/-exec\(.*{}\) +/-execdir\1 \\;/gc #should NOT use with ls variants!
#http://vim.wikia.com/wiki/Moving_to_matching_braces
% key can be used for the following:
To jump to a matching opening or closing parenthesis, square bracket or a curly brace: ([{}])
To jump to start or end of a C-style comment: /* */.
To jump to a matching C/C++ preprocessor conditional: #if, #ifdef, #else, #elif, #endif.
To jump between appropriate keywords, if supported by the ftplugin file, for example, between begin and end in a Pascal program.
A nice keymap is:
noremap % v%
This way, whenever you type % you jump to the matching object, and you visually select all the text in between. It's useful for indenting a C/C++ method/class: go to opening/closing brace, and type =%
«end of % »
#delete from current position until <x>
dtx deletes from current position till just before x. Just tx moves the cursor to just before character x in current line.
To delete up to and including the space, use df<space>.
#vim \r \n
From http://vim.wikia.com/wiki/Search_and_replace :
When Searching
...
\n is newline, \r is CR (carriage return = Ctrl-M = ^M)
When Replacing
...
\r is newline, \n is a null byte (0x00).
for more information, :h :s%, especially the last paragraph. (via :h :s)
#vim delete multiline comment
:%s/\/\*\_.\{-}\*\///gc
\{-} non-greedy Quantifier
\_s : \s + \n
\_. : . + \n
non-greedy quantifiers: use \{-} in place of *
Quantifier Description
\{-} matches 0 or more of the preceding atom, as few as possible
\{-n,m} matches 1 or more of the preceding characters...
\{-n,} matches at lease or more of the preceding characters...
\{-,m} matches 1 or more of the preceding characters...
where n and m are positive integers (>0)
# \=
:%s/System\.out\.print\(ln\)\=/LOGGER.debug/gc
#remove contiguous duplicate lines
:%!uniq
#Capitalize first letter of each word in a selection
http://stackoverflow.com/questions/17440659/capitalize-first-letter-of-each-word-in-a-selection-using-vim
s/\<./\u&/g
delete word around cursor in VIM:
To delete all characters between two whitespaces, in normal mode: daW
To delete just one word:
daw : delete the word under the cursor
caw : delete the word under the cursor and put you in insert mode
'a' specifies that the deletion is to include a delimiter
To delete the entire word your cursor is on and to put you in insert mode use ciw
If the cursor is inside the word:
diw to delete in the word (doesn't include spaces)
daw to delete around the word (includes spaces before the next word).
#mapping
nnoremap ; :
nnoremap : ;
#abbrev
iabbrev py# #!/usr/bin/python -tt
iabbrev utf# # -*- coding: utf-8 -*-
:s/\('[- a-zA-Zа-яА-ЯёЁөӨүҮ]\+'\):\(\d\+\)/\2:[\1,,]/gc
Search for Russian letter range `[а-яА-Я ]` misses the letters `ё` and `Ё`
https://github.com/vim/vim/issues/1751
edit multiple files in Vim:
vim file1, :e file2, :bn, :bn, :bw
Commands to switch between buffers:
:bf # Go to first file.
:bl # Go to last file
:bn # Go to next file.
:bp # Go to previous file.
:bw # Close file.
:help buffer to find more information
To know filename use Ctrl+G,:file or :f
#https://stackoverflow.com/questions/1305853/how-can-i-make-my-match-non-greedy-in-vim
:%s/\(eval\)[ \t\v\u3000]*\$\=[{(]\(.\{-}\)[})]/\1 " \$\2"/gc
#find ... -exec ... {} \; -> {} +
:%s/{}\s*\\\=;/{} +/gc
https://stackoverflow.com/questions/12010308/how-can-i-replace-a-pattern-only-on-lines-that-do-or-do-not-contain-another-patt
#find..."" -> find...''
:g/find /s/"/'/g