[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
VIM tricks
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 46
Thread images: 2
File: vim.jpg (30 KB, 651x371) Image search: [Google]
vim.jpg
30 KB, 651x371
post VIM tricks and shortcuts that you use all the time
>>
After using VIM for years I would just say explore. I've learned a whole lot a tricks about VIM by accident and it's mostly because I still don't know how to exit the program.
>>
these require caps:
H(ome)
M(iddle)
L(ast)
>>
>>53594900
shift+z shift+q to exit without saving also nice trips
>>
>>53594937
well i'm clearly going blind/mad
>>
>>53594876
gd
{ } for top tier lazy navigation

go to definition
>>
For a superior editor:
:q!
emacs
>>
>>53595166
make sure you don't cut yourself on that edge anon!!
>>
>using vim
>doesnt even have a gui
>1992
>>
Press i to insert.
>>
>>53596134
I press the insert key.
Fight me.
I also navigate with the cursor keys.
>>
>>53595166
this desu
>>
I just found out yesterday that G jumps you to end of file.
>>
>>53594900
I see most people exit with colon command :wq!

Personally, I like to use ZZ
>>
>>53597210
You can also go to a specific line with G. For example, to go to line 100, type 100G, to go to top of file type 1G, to go to end of file type $G
>>
au BufEnter *.c set makeprg=gcc\ -lm\ -Wall\ -Wextra\ -pedantic\ -o\ %:r\ %
>>
>>53595490
>gvim
also
>being a cuck
>>
>>53597655
you can also do
:100
to go to line 100
>>
The period character '.' repeats last command. This can be very handy. Probably overlooked by new users.
>>
>>53597750
v - visual select
V - visual line select
^v - visual block select
>>
>>53597655
To go to the top you can just press 'gg'

I feel I'm still learning basics after two years but it's real cool how much you can do in a few key presses. Like with using the above, 'gg=GG' to reindent the whole file you're working on
>>
>>53597837
Yes, I love the V command. I think that was new with vim. Don't think vi had it.
>>
>>53597882
wew thanks for this
>>
:set nu
to see line numbers, then you can do something like save lines 100 to 150 with
:100,150 w! filename
>>
'0' character to goto beginning of line and '$' to go to end of line.

dfx (delete forward to and including next x character)
cfx (delete/change forward to and including next x character and switch to insert mode)
>>
Put the cursor on brace { and find the matching brace with '%' character.
>>
>>53594876
>2016
>nao ter todos os programas em ingles
>>
>>53597630
>using ZZ
:wq just rolls off the fingers anon. Try it sometime
>>
>>53599801
this tbqh my monkey friend
>>
Is there an easy built in way to make vim have automatic syntax indentation, or am I going to have to get down and dirty here?
>>
:q!
emacs
>>
>>53599801
>>53599855
esto para ser completamente honesto mi amigo mono.
>>
>>53599860
what like putting a space between parens and parameters?
>>
All the magical shit you can do with registers.
:help registers
>>
>>53594876
^C - closes the shitty editor ;^)
>>
>>53600116
No, like indenting after a {
>>
>>53600163
like 4 spaces or a tab character after you press { ???
>>
cit deletes everything inside an XML/HTML tag and goes into insert mode
dit does the same without going into insert mode
<shit>niggers</shit>
<shit></shit>
>>
>>53600177
Tab character after { + EOL
>>
>>53600215
yes.
>>
>>53600190
ci is god-tier. Can do with parens, quotes, brackets too.
>>
>>53600350
can do words and WORDS too
>>
:%s/old/new to search and replace
:%s/old/new/c for confirmation
:%s/old/new/gc for every line with confirmation
>>
>>53595166
>using an operating system as a text editor
>>
I always forget what things I need to escape and which I don't need to escape when typing out regex so here's a neat little trick:
:set hlsearch
:set incsearch
/get whatever search pattern right\. for example here I want to delete all lines matching this
:%g/<C-r>//d

The last thing you do on / is saved in the / register which you can pull up with <C-r>/
>>
No real tips.

IMO, the most underrated and underappreciated source for Vim tips is the Vim User Manual. Like, seriously, 90% of the things I do come from what I learned there.

:help usr_01.txt

If you're serious about learning vim, dedicate a night or two to going through the manual. Open up the vimtutor (or any complete file: prose text is preferable for the manual, but code works, too, if you do your research), since you can't normally edit the manual while reading it.

The manual isn't just a good learning tool: it also gives you a sense for how Vim is organized and what things are called. That way, if you need to know how to do something, it's easy to look it up with ":help [thing]".
Thread replies: 46
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.