-
Notifications
You must be signed in to change notification settings - Fork 6
VIM Tips
If there is a filetype plugin distributed with Vim that you want to completely disable, make your own (perhaps empty) settings file in ~/.vim/ftplugin/
directory and add this line to it:
let b:did_ftplugin = 1
Just pretend opening a file:
:e
See more details in this SO thread
Sometimes you just need to quickly move between tabs and spaces:
-
:set expandtab
disables tabs -
:set noexpandtab
enables tabs
Select block of text and enter something like this in command mode (probably by pressing :
):
:'<,'>s/red/green/g
-
Ctrl-v
to switch to Visual Block mode -
Shift-i
to enter Insert mode compatible with Visual Block mode - Type anything and exit insert mode
Warning: check your current working directory first, if it's not the same as your current file's directory path, you will have to provide full/relative path to your current directory. If you add autocmd BufEnter * silent! lcd %:p:h
in your .vimrc though you should be always in the file's directory.
:saveas NEWFILENAME
:!rm -f OLDFILENAME
:w !sudo tee %
Separate them with |
, for example: :set nolist | set nonumber
Assuming you're in NORMAL mode and cursor is currently right before number 5
, you can save it in
the buffer under name a
by typing "ayw
, then after moving cursor, let's say, right before number
3
you can save it in the buffer under name b
with "byw
(or "byt<space>
etc.). Then you can
multiply them and save result in buffer c
by running following command: let @c = @a * @b
and
paste value of buffer c
with "cp
in NORMAL mode or with Ctrl + r
c
in INSERT mode
This command will only run macro m
on lines the begin with _
:
:g/^_/norm @m
Assuming following text:
Foo, Bar, Baz, Qux
Foo, Bar, Baz
Foo, Bar, Baz, Qux
Foo, Bar, Baz, Qux
Foo, Bar, Baz
Foo, Bar, Baz, Qux
and you want to separate lines that have 2 commas from lines that have more than 2 commas. Here is how to do it:
:g/^\([^,]\+,\)\{3,\}/norm "Add
Then go to the end of file or to another file and you can paste the lines with more than 2 commas using:
"Ap
Assuming following text:
Foo; bar;
Foo bar
Foo bar;
and need to remove ;
in the end of each line where it appears, this command will do it:
:g/;$/norm $x