r/vim • • Nov 05 '19

:w

Post image
755 Upvotes

97 comments sorted by

97

u/bash_ghost Nov 05 '19

It feels like I do a :w without thinking every time I exit insert mode. :D

55

u/deus_mortuus_est Nov 05 '19

Yeah, but have you ever posted :w in slack? Hilarity ensues, I assure you.

34

u/tandrewnichols Nov 05 '19 edited Nov 05 '19

Yes, and also done git status and discovered untracked files called :w or :wq

15

u/[deleted] Nov 05 '19

Wouldn't escape unfocus the input field?

7

u/[deleted] Nov 05 '19

I solved this by getting a UPS and... wait no I still do it all the time...

7

u/[deleted] Nov 05 '19

You'd think, being on a laptop, one would not worry about power loss.

Now only do I :w often, everytime I come to the command line I git push to a holding area to save my work.

I think there's a limit to hardware-failure-paranoia. And I have not only reached, but crossed it!

6

u/tobeportable Nov 05 '19

I double tap esc to exit insert & save with : noremap <Esc> :w<CR>

1

u/schwerpunk qq Jan 24 '20

Brilliant. I've been looking for some binding that made sense just lately. I was thinking maybe jk from normal mode, but I also do that absentmindedly while I'm thinking.

I never would have thought of using ESC while already in normal mode.

30

u/carracall Nov 05 '19 edited Nov 05 '19

I tried using vim for the meme loads of times over the last few year, convincing myself that doing things like "ciw" was making me way quicker but it was actually slow and unnatural (using $` was also slow for me) and became really apparent when I used an ide again. But after I learned to touch type, everything fell into place, the "don't use arrows" goes well with the attitude of keeping to the home row and keeping each finger above its assigned keys (i. e. 8 i k , for right middle finger). After using a key combination enough, you remember the key strokes instead of say "change inner word". In particular, :w is now very fast to do as it doesn't require fingers moving that far. To better illustrate the idea to those who don't touch type: I use ctrl+[ to escape insert mode instead of esc because even though it involves more hands, more fingers and more keys (I move left pinky to L-ctrl & right pinky to [ ) they don't move far from where they already are and fall right back in place ready for the next thing straight after, but to reach esc I need to move my wrist and occasionally when I bring my hand back to home row it doesn't fall back quite in the right place.

Tldr: vim only became a better alternative for me after learning to touch type

29

u/standard_error Nov 05 '19

Completely agree - if you don't touch type, you should learn that immediately.

By the way, have you tried remapping caps lock to send ctrl? After learning touch typing, this is easily the best improvement to typing ergonomics I've done.

6

u/carracall Nov 05 '19

I saw an article that suggesting that, I thought about it but decided I use caps enough (all caps is the convention for certain things in the code bases I work on)

5

u/sempiternalecho Nov 05 '19

I have ESC mapped to caps lock. I then have it mapped so pressing both shift keys simultaneously toggles caps lock.

6

u/carracall Nov 05 '19

Ooo pressing both shifts for caps sounds like the most attractive option rn

3

u/[deleted] Nov 05 '19

Just used <C-[> Why don't people know about this? Esc is like an antipattern in vim. You have to lift your hands.

3

u/sempiternalecho Nov 05 '19

I used to use that bind, but I use escape outside of vim quite a bit as well

2

u/carracall Nov 06 '19

For the question part, I think the reason is that the escape used to be somewhere different on the keyboards vi was intended for (maybe in place of tab or something similar)

4

u/standard_error Nov 05 '19

I'd still recommend you to try it. In Vim, making a line all caps is a simple matter of V + gU.

2

u/[deleted] Nov 05 '19

which you can always make a new command for, because vim.

often enough I had to uppercase a single letter, so I made a remap for U:vgU; You can try to do something like this, using vwgU to uppercase the whole word, for example.

2

u/IrishPrime g? Nov 06 '19

If you need to toggle case for a single character, use ~. For capitalizing a whole word, gUiw is probably more convenient.

2

u/[deleted] Nov 06 '19

Wait, that's a thing? I didn't find that when I looked for it!! Thank you

0

u/[deleted] Nov 05 '19

[deleted]

2

u/[deleted] Nov 05 '19

More people need to use <C-[> I'm not sure why it's not more known.

6

u/[deleted] Nov 05 '19

^ and $ are way hard to reach for how often they used.

8

u/jnicklas Nov 05 '19

I never use ^ and hardly ever use $.

If you want to go to insert mode anyway (which for me is 99% of the time) then just use I instead of ^ and A instead of $.

0w is far more comfortable for moving to the beginning of the line if you need to, so no reason to use ^ ever.

But there are just very few cases where this is necessary to do anyway, for me it's mostly when using macros.

The one that does come up sometimes is deleting the last character (e.g. getting rid of a trailing comma), which could be done via $x but I honestly quite often do this via A backspace ESC, which isn't very vim-y but does the job.

2

u/JonnyHaystack Nov 05 '19

I use _ a lot

2

u/jnicklas Nov 05 '19

Huh. TIL that this exists. Interesting that it takes a number of lines to move downward. Not sure that’s super useful though. Do you ever use it in that way?

2

u/JonnyHaystack Nov 05 '19

Nah I never use it that way, I just use it instead of ^ and because I use US Dvorak layout it's right next to my right hand pinky

3

u/[deleted] Nov 05 '19

I remapped them like this

nnoremap L $
nnoremap H ^

6

u/piggahbear Nov 05 '19

You don’t use H M L to go high mid point and low point in the page ? I use those a lot

1

u/[deleted] Nov 05 '19

I've been thinking about doing

nnoremap gh L
nnoremap gH H

instead because I usually go into select mode by mistake.

0

u/MAFBick Nov 05 '19

This is smart, and almost seems like it should be the default.

1

u/wakela Nov 05 '19

How did you learn to touch type?

2

u/carracall Nov 05 '19

Just like the other commenter I used some website typing tutor and forced myself not to look and reach with the correct finger (before covering all the keys I had to look of course but made sure I always use the right finger) . The first couple of weeks typing slowly was painful but as soon as you match your original speed it's smooth sailing. There was a period when I used an offline program called "klavaro" that I used when I was on a trip.

Highly recommend touch typing, as well as more efficient finger movement, a great perk is being able to type on a laptop in the dark with no kb back light.

2

u/Adk9p Nov 13 '19

Again, not op. Just wanted to share keybr because it really helped me. I tried the other sites like u/BeardedBearserker but they never stuck / I was to lazy. I think whats cool about keybr is that it slowly introduces the letters when it thinks you got the other down pat so you aint just sitting there typing g's and h's in weird combos and then moving on to a lessen where you just use y's and u's etc, you gradually get introduced till you have the whole keyboard

If you do try it out I would recommend turning on capital and punctuation on in the settings, and logging in with google doesn't hurt so you can see your progress ;)

1

u/lrvideckis Nov 05 '19

Ctrl-c also exits insert mode, and is way easier than ctrl-[

2

u/carracall Nov 05 '19

For me reaching the left ctrl is is a lot easier than the right ctrl (which I would use for ctrl-c), at least on full sized keyboards which I usually work on, I like the laptop keyboards where its further to the left.

2

u/haldad Nov 06 '19

It doesn't run auto commands though. I also find that c-[ is actually easier because you can use two hands and barely have to move your hands

1

u/lrvideckis Nov 07 '19

Gotcha, I'm just really used to ctrl-c from killing programs in the terminal

1

u/haldad Nov 07 '19

You can remap C-c to C-[ and then it'll run autocommands, I think.

1

u/mdrjevois Nov 05 '19

/u/-romainl- anecdotal evidence here that some people really do find touch typing helpful for learning. If you're doing fine, no need to get side tracked with typing practice. But this somewhat confirms that it's worth a try for newer users if they're struggling to get into their flow.

1

u/EuanB Nov 06 '19

Any time you find yourself us in hill, there is usually a better way to get to where you want to be. Worth paying attention to.

0

u/[deleted] Nov 05 '19

[deleted]

1

u/carracall Nov 05 '19

Ah nice, I was vaguely aware of such a mode because some of the old unix machines that we run tests at work had it, but wasn't aware that my own shell could be configured that way (which I assume you're hinting at). I'm bit by bit shifting to a keyboard oriented work flow, my most recent step is using i3-gaps on my personal pc&laptop.

30

u/[deleted] Nov 05 '19

As a dirty gvim user and Ctrl+S addict... (please don't downvote, have mercy on an irredeemable sinner and Vrapper user)

noremap <C-S> :update<CR>

vnoremap <C-S> <C-C>:update<CR>

inoremap <C-S> <C-O>:update<CR>

24

u/yymirr Nov 05 '19

leader w

10

u/KetzerMX Nov 05 '19

I just use leader leader, it's faster

4

u/philmi Nov 05 '19

For me this opens fuzzy FZF to quickly jump into another file. I think I'll use it more often than saving a file.

2

u/skotchpine Nov 05 '19

Leader leader ftw

1

u/timvisee vim on Gentoo Nov 05 '19

Leader leader is goto alst file for me <C->, the king in efficiency.

1

u/[deleted] Nov 05 '19

In insert mode?

5

u/[deleted] Nov 05 '19

Who saves in insert mode?

5

u/Xanza The New Guy Nov 05 '19

Only didn't downvote because you're :update master race.

13

u/compteNumero9 Nov 05 '19
" Auto save changes before switching buffer
set autowrite

2

u/[deleted] Nov 05 '19

this is amazing! I'm writting it down RIGHT NOW!

6

u/crashorbit Nov 05 '19

It's not so much the w: as it is the :w<enter>:w<enter>

1

u/[deleted] Nov 05 '19

It's even worse if you're used to :up since it doesn't do or print anything if the file was not modified.

1

u/[deleted] Nov 06 '19

lol.

5

u/petdance Nov 05 '19

These :w jokes are a waste of time and space.

1

u/[deleted] Nov 05 '19

:smile

4

u/[deleted] Nov 05 '19

inoremap <CR> <CR><C-o>:w<CR>

4

u/[deleted] Nov 05 '19 edited Nov 13 '19

I have it mapped use 907th/vim-auto-save to write on exit to normal mode. No time wasted. :)

edit: more acurate ^information

2

u/Chased1k Nov 05 '19

Came here to say this

0

u/[deleted] Nov 13 '19

[deleted]

1

u/[deleted] Nov 13 '19

Sorry, I was at work when I wrote this and I thought I did. Now that I checked my .vimrc I actually use a plugin for that. https://github.com/907th/vim-auto-save

3

u/Xanza The New Guy Nov 05 '19

:up master race.

3

u/Cork__Screw Nov 05 '19

Anyone else use :up instead?

2

u/dmitry_krasilnikov Nov 05 '19

Working on a laptop, using :up when needed (through leader u mapping)

1

u/heppen1 Nov 05 '19

So, how can I reduce the time uesed to :w, lol

1

u/THICC_DICC_PRICC Nov 06 '19

I just map shift+w to it, it’s like the ole ctrl+s

2

u/haldad Nov 06 '19

W is a pretty important movement command in normal mode...might I recommend <space>w instead

0

u/[deleted] Nov 06 '19

[deleted]

2

u/haldad Nov 07 '19

Use vim any way you'd like, but your understanding of W is simply incorrect.

It goes to the next WORD which is different than the next word and has nothing to do with capitalization. It allows skipping over the symbols in the string a+b+c, for example. The exact definition is based on :help 'iskeyword', but you can read more at :help word and :help WORD.

-1

u/[deleted] Nov 05 '19

The first thing I used was remapping ; to :, so I didn't end up typing :W by accident.

After that, half of my quick use macros/commands include a ;w as the first part, so vim does the heavy lifting for me

3

u/mdrjevois Nov 05 '19

I've seen this said a lot. You do you, but I use ; for its intended purpose all the time.

1

u/[deleted] Nov 05 '19

what is it's intended purpose? from what I knew, it didn't use to do anything

1

u/mdrjevois Nov 05 '19

Companion to f, t, F and T which search current line by character. , jumps another forward and ; jumps another in reverse. So I basically use these like w and b on steroids. It's mostly analogous to what to N does for regex searches.

0

u/[deleted] Nov 05 '19

Oh, I never knew that. But I'd probably not use it that often, so I'm not sad to let it go

1

u/sayoojsamuel Nov 05 '19

Whooh, thats totally relatable. (:w

1

u/GustapheOfficial Nov 05 '19

Swedish keyboard, I have nnoremap å :up<cr> in my vimrc and nnoremap å :up<bar>make something.pdf<bar>cw<cr> in most of my localrc's

1

u/philmi Nov 05 '19

You should really checkout the (unlimited) persistent undo feature, it saves you the trouble and you'll have (as I'd call it) "microversioning"

Have look e.g. here https://jovicailic.org/2017/04/vim-persistent-undo/

1

u/myrisingstocks Nov 05 '19

Autosave on FocusLost.

1

u/noonearya Nov 05 '19

I have a shortcut to search for instances of :w I might have written by accident.

1

u/[deleted] Nov 05 '19

I save like nobody's business. I refuse to be one of those pinheads, like a few people I work with, who lose their data because they stupidly didn't save their work frequently.

1

u/hgiesel Nov 05 '19

Double space in normal mode saves for me.

1

u/mixedCase_ Nov 05 '19

Am I the only one that opens many buffers and uses the Waluigi method?

:wa

1

u/treuss Nov 05 '19

When people ask you, what it's about all these :w in your documents....

1

u/hawkprime Nov 06 '19

I'll just leave this here:

autocmd CursorHold,CursorHoldI * update

0

u/ivster666 Nov 05 '19

Can't relate to this. Why would you constantly save stuff? I have coworkers with plugins for their IDE to save after every keypress but I just don't understand what that's for. Compilers that are watching for filechanges just go crazy if you do this...

0

u/fourjay Nov 05 '19

I get this is a meme, but there is a serious point here. vim encourages a "write and think" approach, not just in regards to explicit writing out of files, but in it's encouragement to be in normal mode.

FWIW, I have a meta key mapped to <esc>:x<cr> . This maps my thought/work flow pretty well, create a coherent statement, then think on the next one.

0

u/[deleted] Nov 05 '19

[deleted]

3

u/contradicting_you Nov 05 '19

In case you're serious, this is what happens to every subreddit that gets popular and doesn't have firm rules against low-effort memes and enough mods to enforce those rules.

7

u/[deleted] Nov 05 '19

[removed] — view removed comment

4

u/Botteknotten Nov 05 '19

Me neither. Swap files are the best!

:h crash-recovery

2

u/compteNumero9 Nov 05 '19

I guess the problem arises when you deal with several buffers and don't have vi configured to save when you switch buffers.