Saving Read-only Files in Vim – The sudo tee trick

How many times you had the following situation: You open a file with Vim and make some changes. When you try to save the file, you realize that you didn’t run Vim with sudo?!

There is a solution for this. The next time when you get into this situation, you can use the following command in order to save the changes you made:

:w !sudo tee % >/dev/null

There’s just one problem – it’s a bit hard to remember it. That’s why, if you’re going to need it often, add the following line to your .vimrc:

cmap w!! w !sudo tee % >/dev/null

This way, when you get to the same situation again, you can just type :w!! to save the file, even if you did not run Vim with sudo.

Over the years, Vim got a reputation that it’s really difficult to learn it. I’ve heard many times from guys who are convinced it will take them months to reach proficiency. That’s simply wrong.

That’s why I’ve started to write a book: Mastering Vim Quickly (from WTF to OMG in no time) which will teach you Vim the way I learned it – easily and quickly.

If you want to get updates and sample content from the book, leave me your email below, and I’ll make sure to keep you updated. You could also go to Mastering Vim Quickly page and check it out.

If you liked the post, we should get connected - follow me on Twitter

Why Vim – 21 Reasons to Learn Vim


After writing about the history of Vim, I wrote a post where I told you what you can expect from my upcoming book Mastering Vim Quickly.

Today, I will try to mention as many as possible reasons to learn Vim. So, if you’re a beginner with Vim and you’re not sure should you keep learning it, or if you only think about learning Vim, this post if for you.

This post is not going to cover awesome Vim features as reasons to learn Vim, so if this is what you expect, don’t lose your time on reading.

So, here is the list of reasons why to learn Vim:

  1. Vi is guaranteed to exist on all Unix systems and exists on most Linux ones as well. That kind of broad coverage makes learning it worth it – because, if you know Vim then you know Vi as well.

  2. Vim is free and has a vibrant community

  3. Vim works over telnet & SSH connections. There’s no better way to edit files remotely via terminal than using Vim. Sysadmins know this.

  4. Vim’s configuration is portable. You just need to copy a few directories and files, and that’s all.

  5. Vim compiles/has precompiled binaries for almost every OS out there. You will never have to post “I need a [some text editor] alternative for [some OS]” anymore. You’ll have Vim instead!

  6. It’s also usually very fast and lightweight even when editing huge files of source code. Seriously huge.

  7. If you’re a programmer who edits a lot of text, then it’s important to learn an serious text editor like Vim. Serious text editors are highly optimized to perform the kinds of tasks that you will be doing a lot. For example, adding the same bit of text to the end of every line is trivial in Vim, but ridiculously tiresome otherwise.

  8. If you plan to configure anything in a Unix based system likelihood is you going to be editing a fair few config files, therefore you’ll want to learn a terminal based editor, of which Vim is one of the best.

  9. Vim allows you to easily code without taking your hands off the keyboard.

  10. Your fingers very rarely have to leave the home row, which means you’ll be able to edit text very, very quickly.

  11. It starts up faster than any IDE or text editor I’ve used, and it has many powerful features.

  12. It helps you focus on the coding process itself, you won’t be using the mouse at all to deal with it, that’ll save you a lot of time when you’re just writing code.

  13. It’s fun! Editing text is like a game to me now. I sincerely enjoy it – which is pretty ridiculous, when you think about it.

  14. If you’re working remotely, there is no choice to use Eclipse or similar GTK based IDE. You can do everything with Vim: source control, SQL, debug, compile, browsing – really fast browsing even over 1 GB source code. Visual Studio or Eclipse couldn’t handle all of this.

  15. There are a lot of good plugins out there which add a lot of functionality.

  16. Vim is a really good tool once you familiarize yourself with it.

  17. It has a reputation for the quality and the completeness of its docs. That’s true. Vim is thoroughly documented. You will find most of the  answers to your questions in its help system as soon as you will manage to stick the proper keywords in your help queries.

  18. You might want to learn Vim because many people think it is cool.

  19. You don’t have to press Ctrl or Alt all the time in order to run commands or shortcuts.

  20. It’s much quicker to use vi for a sudo edit: $ sudo vi. For example, if you run text editor 100 times a day, with typing sudo emacs, you’ll have to make 300 keypresses more! Okay, this is a joke :) chill out emacs guys (and yes, I know that there’s something like alias :) )

  21. Vim is addictive. You will find yourself wishing you could use Vim commands in all your computing, and cursing whenever you can’t. For example, I use Google Chrome with Vimium extension, so I surf the Internet without a mouse or touchpad. How cool is that!

On the end, have have to add that Vim’s usefulness depends on what you’re working with. If you’re an Java/C#/etc developer, you’ll most probably be more comfortable with an IDE.

But if you work with Python, Perl, Ruby, C, web, etc. or you’re a system admin/devops, Vim is the way to go. Vim is fast, powerful and does everything you need.

Over the years, Vim got a reputation that it’s really difficult to learn it. I’ve heard many times from guys who are convinced it will take them months to reach proficiency. That’s simply wrong.

That’s why I’ve started to write a book: Mastering Vim Quickly (from WTF to OMG in no time) which will teach you Vim the way I learned it – easily and quickly.

If you want to get updates and sample content from the book, leave me your email below, and I’ll make sure to keep you updated. You could also go to Mastering Vim Quickly page and check it out.


If you liked the post, we should get connected - follow me on Twitter

What to Expect from Mastering Vim Quickly book


This is a post which should give you some basic info about my upcoming book, Mastering Vim Quickly The purpose of the Mastering Vim Quickly is to help you get from beginner to master of Vim in short time. That’s why the subtitle of my book is: from WTF to OMG in no time :)


The Reputation of Vim

There’s so much you want to do in life, and so little time. The story of our modern lives.
Take a moment to consider how many things you want to learn.

Seriously, don’t read further, but take a moment and think  :)


Okay. Since you’re reading this, I guess that Vim is in your to-learn list.
Now think, what’s holding you back from getting started? It’s hard? It takes time? Something else?

I can guess. You’ve heard about the reputation Vim has.

You’ve probably heard that Vim has a reputation for being difficult to learn. Or that Vim has the steep learning curve.  Or that it takes months, even years to get good at it.



Learning curves


Truth to be told, Vim has a deserved reputation for being difficult to learn. But, this can be avoided. There is a way to learn Vim faster that you ever imagined. Read further, and you’ll find out how.


The Art of Learning

Before I say anything about learning Vim, let’s just cover some general basics of learning.

Here is one uncomfortable truth: skills take time and effort to master.
There’s another one: many things aren’t fun until you’re good at them.

While learning any new skill, there is a period of time in which you’re horribly unskilled, and you’re totally aware of that fact. The same goes when learning Vim.

Mastering Vim Quickly will present my successful personal quest to quickly learn Vim, and as such, it will help you to acquire new Vim skills in record time.

One of the beautiful things about learning any subject is the fact that you don’t need to know everything.
What’s important is that you only need to understand a few critically important concepts that provide the most of the value. The same goes for Vim. Even only this kind of approach to learning Vim will help you learn it much faster that everyone else.

Mastering Vim Quickly represents a set of fundamental Vim concepts you can use to get things done.
Once you master the fundamentals, you can accomplish even the most challenging Vim magic with surprising ease.
And you will love it! I can tell you that. You’ll enjoy even more while writing your code. You will enjoy even while editing a simple text.

Over the past few years, I’ve picked up several books on Vim, passed through hundreds of tutorials and tips, used Vim from few to 10+ hours a day while coding, writing documentation, writing blog posts, tweeting, etc. Yes, I do all of that from Vim. Along the way, I’ve collected, distilled and refined my findings into concepts and best tips. They will be presented in this book.

If you invest the time and energy necessary to learn these concepts, I believe that you will easily be in top 10% of the the human population when it comes to productivity in coding, programming and text editing.

Think of this book as a filter. Instead of trying to absorb all of the Vim knowledge – and there’s really a lot out there, you will use this book to help you to get what matters the most. This way you can focus on what’s actually important: getting stuff done.


Why another book on Vim?

You might be thinking, if there are already books on Vim, why would I write one more?

Well, what I don’t like about books on Vim is that they are too long. One of them: ~300 pages. Second: 500 pages. Third:  900 pages! That’s just way too much. I understand, Vim is really complex and powerful text editor, and has really a lot of features, but anyway, this is too much. They take too much time.

That’s just one of the reasons why I started with writing my own book on learning Vim.
Yes, I am aware that there’s big possibility that my book will become larger then I want, so that’s why I’ve decided to give myself limit right away. I think it would be ideal to have 100 pages book. But I’m not strict – I even if I reach ~120 pages, I think that’s acceptable.

So, for all of you interested in my upcoming book – now you know. It’s going to be short and really effective.



No Experience Necessary

Don’t worry if you’re a complete beginner. I don’t assume that you’re already good in Vim (but this book will still be very useful if you are!).

You’ll find the information in Mastering Vim Quickly more valuable and practical than anything you learned from other Vim resources.

I want to save you from all the difficulties that I faced, and help you understand how Vim really works.


The Importance of Strategy

In order to learn Vim quickly, I have created few different strategies which helped me do it. Of course, I will present those strategies in the book.

You’ve most likely heard of the 80/20 rule, or Pareto Principle. It suggests that in any endeavor, 80% of the results come from 20% of the input. For example, for a company, 80% of revenue usually comes from around 20% of its customers.  The ratios won’t always be 20% and 80%, but the point is that in anything you do, there are a few things that matter far more than everything else.

My goal is that you get that knowledge that matter the most. My book, Mastering Vim Quickly, will provide you the most important 20% of Vim knowledge.

You will learn the most important 20% things about Vim. That will get you 80% of the power of Vim and working productively with it. Simple as that.

I have to admit, I’m a learning addict. I love to read, and learn new stuff. I read 80-100 books a year in average. This helped me to actually learn how to learn effectively. I found a way to learn Vim effectively, so if I could do it – you can do it as well.

For example: when learning a new skill, what you learn and the order in which you learn it makes a big difference. In his book The 4-Hour Chef, Tim Ferriss shares his methodology for rapid skill acquisition. He says that you must first deconstruct the skill into manageable blocks, select the most important blocks (the 20%), and then learn those blocks in a logical sequence. This is exactly what I am doing.

Or another example: When you learn something new, and you have all the material you need, what else can you do to speed up learning? In his book The First 20 Hours, Josh Kaufman discusses the keys to achieving rapid progress during the early stages of acquiring a new skill.


“The major barrier to skill acquisition isn’t intellectual… it’s emotional” – Josh Kaufman


The biggest obstacle you will face in your quest to learn Vim is yourself. The fact is, like any new skill, learning Vim is tough. What makes it tough, though, is not the content, but rather the fact that you will get frustrated and feel stupid at times. Trust me, you will feel like this when you start with Vim. The road will seem too long, and it would be much easier to just give up and get back to your old text editor instead.

But I’ve passed through all of this. I’ve been there, I’ve done that. And I’ll help you to overcome this, just the way I did. Note that this is just one of the few strategies which will be presented in my book, in order to help you learn Vim quickly.


Work in Progress

Since there’s so much to learn about Vim, it’s not an easy task to filter all of it and keep only the best. It takes time. Also, this is going to be the first book I’ve ever published. So, I’m really trying hard to make it a good one. That’s why, book will not be ready in the next month or two – just in case you were wondering.

One more thing. You should also know that each chapter of my book will be packed with examples that support detailed explanations of all the important concepts, and they will be presented in a way that helps you avoid the confusion that I faced when I was learning. Like I said – I’ve been there, I’ve done that. I know how it feels when shit’s being weird.

With this book and plenty of practice, I truly believe that you will be amazed at how quickly you can go from complete beginner to super productive pro. From WTF (is this) to OMG (I can’t believe how awesome things I can do with Vim).

Mastering Vim Quickly is for anyone who wants to learn Vim, but either doesn’t know where to start, has tried to learn but struggled to make progress, or is intimidated by how difficult Vim appears to be.

This book is designed to give you the head start I didn’t have. Wherever you are, if you want to learn Vim, the book will help you learn smarter, faster and easier.


If you want to get updates and sample content from the book, leave me your email below (if you did not already) , and I’ll make sure to keep you updated. You could also go to Mastering Vim Quickly page and check it out.



If you liked the post, we should get connected - follow me on Twitter