Forking off the vimrc thread.
< and >: Decrease and increase indentation levels. Works with several lines and levels at once.
asemisldkfj
the law is no protection
whoa, that is neat.
v: visual selection
ctrl+v: vertical visual selection
V: Visual selection by lines.
^V: Visual selection by block (you can go horizontally too).
Block selection is evil. Windows' cmd window block selection makes me foam at the mouth and want to kill random people.
gg=G: Indent all lines in the buffer the way Vim wants them.
> Windows' cmd window block selection makes me foam at the mouth and want to kill random people.
haha yes!
gf - opens the file under the cursor
gq - word wrap (use v to select the lines and then gq. useful when typing a mail)
* - search the word under cursor
^Wgf: Open the file under the cursor in a new tab.
gu: Make stuff lowercase.
gU: Make stuff uppercase.
maple
i like large datasets
"these will delete inside the corresponding characters. you can use 'y' or 'c' instead of 'd' to yank or change.
di<
di{
di(
di"
"save with sudo (used so many times)
:w !sudo tee %
"better movments
nnoremap k gk
nnoremap j gj
nnoremap gk k
nnoremap gj j
]p: Paste and autoindent.
asemisldkfj
the law is no protection
:retab to convert existing tabs into spaces
you can guess why I know this now :)
Welcome to the right side! :D
asemisldkfj
the law is no protection
> Windows' cmd window block selection makes me foam at the mouth and want to kill random people.
I just realized what you meant by this, and yes, it does the same thing to me.
haha, that's great
How do you "clear" search?
For example, I typed:
/hello
And I want to clear the pattern?
I now use:
/asdflijwer
And that works ... sort of :-/
:noh
you should be on vim golf :)
Super, two methods to choose!
was wondering how to evoke the save-as dialog for gvim, and i thought this was cute:
:bro sav
source
I'm using vim as a productivity tool these days. As such I found out how awesome abbreviations can be, and macros, and commands. Pretty much vi is amazing as an editor.
Often at work I'll have to type out acronyms and their expanded definition. In this case I'd use several abbreviations for insert mode, I have a bunch more than this but it's pretty great for templating and block-completion:
:ia h Hello
:ia dp Daniel Peterson (projectdp@gmail.com)
:ia nc - dp <C-R>=strftime("%c")<CR>
:ia cc Thank you,<CR><CR>Daniel Peterson<CR>PO Box 1744<CR>San Jose, CA 95109
:ia s- ___________________________________________________________________________
To aid in speed-typing I utilize omnicomplete (type word+CTRL-N) and I want to start including a custom definitions file for custom word completion.
Commonly there's addresses I need to look up. The case may be dirty, so I clean up and enter the data. What I do in vi is:
1. paste dirty:
daniel PETERSON
po Box 1744
San jose, ca 95109
2. move to start: kk0
3. change all lines to lower case: gu3u
4. capitalize first characters of each word: 8@u
5. clean up any changes: (move to location i.e. "Po", "Ca") g~w
before you try, you need to record a macro:
to record the macro for this cleanup action:
quw~q
or you can just set it on cmd line:
:let @u='w~'
all together now:
<CTRL+V>kk0gu3u8@ug~wk0e~k0Vjj<CTRL+C>
it may not seem intuitive but if you have the motions down it's not difficult to parse out :D so awesome!
dp is lovin'! :D
Vim 7.3 has persistent undo, so I do this:
if v:version >= 703
set undodir=~/.vim/undo
set undofile
set undolevels=10000
set undoreload=100000
endif
This saves an undo file for every file I edit in ~/.vim/undo that persists when closing and opening files again.
so good
asemisldkfj
the law is no protection
excellent posts by dp and bluet.
some tips on use:
:ia cc Thank you,<CR><CR>Daniel Peterson<CR>PO Box 1744<CR>San Jose, CA 95109
if you notice the result (of typing cc[space]) indenting like this:
Thank you,
Daniel Peterson
PO Box 1744
San Jose, CA 95109
you'll want to do ":set nocindent". I thought this was an autoindent issue, but I could only resolve it with nocindent.
todo: incorporate backup feature, come up with a faster way to restore swap files and clean things up after a crash, define and find more useful macros for vim bot work, do more tips!
:ia
I am loving the command already!
Good tip!
Persistent undo! *drool*
...and persistent redo? I didn't see anything in the help. Don't forget about the redo hotkey: (CTRL+R)!
Ok so I have sets of rooms that I regularly need to clean up, similar to addresses. Today I found it so useful to use macros -- I'm getting better!
input:
XAI0-2-DANNYP MASTER KEY (Offline) (4) DCP1
BOH-7-BECKONING SHADOW (Online) (1) OXG2
LKM1-58-WAN CHAI (Online) (1) RTS4
DGM-0-LAKE SHUDDER (Online) (5) MAM3
RCDP3-0-EMERALDS (Online) (9) GTS1
BLDG04-6-ROOT (Offline) (5) TSP4
MRXAN-1-LOTUS LEAF (Online) (9) GTA1
SKGE1-21-TERRIBLE THINGS (Online) (6) ADP3
HKKG-41-TREBUCHET (Online) (2) RMA1
MRBRO-1-UNGULATE TIPS (Online) (6) CNK5
magic:
@r<CTRL+C>
output:
Dannyp Master Key
Beckoning Shadow
Wan Chai
Lake Shudder
Emeralds
Root
Lotus Leaf
Terrible Things
Trebuchet
Ungulate Tips
behind the magic:
stripping room names:
let @s='0d4w$7bhd$j'
change case, next word (used in addresses too):
let @u='~w'
set a mark, strip 10 lines of room junk
...jump to mark, lowercase 10 lines, capitalize 18 words
...jump to mark, visual select 9 lines down:
let @r='ms10@s`sgu10u18@u`sV9j'
input:
b is
a this
c awesome
magic:
Vjj!sort
output...
Shave off some keypresses:
3:sort
or
:%sort
for the whole buffer.
I just found out that
@:
repeats the last :command.
You can also use @@ to repeat the last macro (Didn't know about the @: though).
> Vjj!sort
That calls the /usr/bin/sort. Vim also includes a built-in sort :sort
Learning stuff every day, thanks guys. Turning clay to terracotta. Can you guys just write an awesome new vi guide or is this a rite of passage?
vimtutor (command) is the best vi guide!
Thanks to db:
This is obvious but I couldn't do this properly without this tip:
In Windows, to make Windows and DOS find gvim / vim, just add the path to the PATH environment variable.
Control Panel -> System Properties -> Advanced -> Environment Variables -> System Variables -> PATH
Edit PATH, append:
"; C:\Program Files (x86)\Vim\vim73\"
(or your vim path :P)
If you run the installer there's an option for that (IIRC it doesn't add to the PATH, but places vim.bat in C:/windows/system32/
asemisldkfj
the law is no protection
I really need to write a script that adds every subdirectory of %programfiles% to my PATH. I think I've made this post on ttf before, but it's worth repeating.
This may work:
move %PROGRAMFILES%\*.exe %SYSTEMROOT%\system32\
;-)
-X makes vim start faster in a terminal.
[~]% time vim -c ':q'
0.12 real 0.10 user 0.01 sys
[~]% time vim -X -c ':q'
0.12 real 0.10 user 0.01 sys
[~]% time vim -c ':q' /bin/csh
0.17 real 0.13 user 0.02 sys
[~]% time vim -X -c ':q' /bin/csh
0.17 real 0.13 user 0.02 sys
Ran the tests several times ... Sometimes it varies by .01 second, but it seems fairly consistent.
this post has been archived.
There's a vi StackExhange site now :-)
https://vi.stackexchange.com/
I've learned a lot more about Vim in the last month.
I recently added:
map <silent> <leader>x :silent exe "!chmod +x %" \| w<CR>:e<CR><C-L>
I started using syntastic recently. It's really cool:
https://github.com/scrooloose/syntastic
Yeah, syntastic is cool, although the Ruby validations whine a bit too much for my liking; especially the "assigned but unused variable" and "statement not reached" errors are more annoying than useful... I need to see if I can configure that...
I stopped using syntastic recently. It would lock up Vim for seconds at a time. Now I run entr in a second terminal instead.
http://entrproject.org/
I finally fix one of the most annoying things in my Vim.
set nrformats-=octal
i was playing with entr for a while. pretty fun/handy.
phi_
... and let the Earth be silent after ye.
I set my tab size to 4 and tab everything multiple times so it looks like a normal 8-space tab on my end just so if I ever send the file to someone else it'll be annoying as hell.
I put byte order marks at the end of my files.
phi_
... and let the Earth be silent after ye.
That's vicious.
what's that do? just a latent bomb to cause a mess for non-unicode programs?
asemisldkfj
the law is no protection
this is basic as f, but I somewhat recently learned about the 'w' and 'b' keyboard shortcuts in command mode to kind of "jump" between "words". so many vi/vim things to discover! I'm still using the same vimrc I was using like 10 years ago lol. (I mostly use vs code for actual code/script editing—terraform and python mostly—and just use vi/vim for quick stuff. oh and I use the vi/vim extension with vs code because I don't know how to edit text without at least hjkl cursor motion keys.)
I used Vim for years and didn't know a whole lot of fairly basic stuff; it wasn't until the Vi & Vim Stack Exchange site was launched that I started answering questions and diving deeper; I learned a lot from that.
There have actually been a number of pretty neat additions to Vim in the last year or two, and with LSP things like autocomplete and other IDE-like features work much smoother. I think Vim at this stage really is just the same as an IDE (if you want that, anyway).
LSP is the best thing to happen to Vim in years.
Also, in really new versions you can use "set spelloptions=camel" to spellcheck CamelCase words. as "camel" and "case".