How does the vim “write with sudo” trick work?

In :w !sudo tee %… % means “the current file” As eugene y pointed out, % does indeed mean “the current file name”, which is passed to tee so that it knows which file to overwrite. (In substitution commands, it’s slightly different; as :help :% shows, it’s equal to 1,$ (the entire file) (thanks to … Read more

How do I exit Vim?

VIM has basically two modes: Command Mode (called also “Normal Mode” below) and Insert Mode. Most likely you are in “insert mode” which does (not surprisingly) insert what you type, while in “command mode” it would try to execute the commands you give (such as :quit). However VIM indicates when it is in insert mode … Read more

Why do Vim experts prefer buffers over tabs? [closed]

As ZyX said on #vim, this question sounds like “Why do Vim experts prefer tasty over warm?”. “Vim experts” don’t prefer buffers over tabs: they use buffers as the file proxies they are and tab pages as the workspaces they are. Buffers and tab pages have different purposes so preferring one to the other makes … Read more

Vim and Ctags tips and tricks [closed]

Ctrl+] – go to definition Ctrl+T – Jump back from the definition. Ctrl+W Ctrl+] – Open the definition in a horizontal split Add these lines in vimrc map <C-\> :tab split<CR>:exec(“tag “.expand(“<cword>”))<CR> map <A-]> :vsp <CR>:exec(“tag “.expand(“<cword>”))<CR> Ctrl+\ – Open the definition in a new tab Alt+] – Open the definition in a vertical split … Read more

Using Vim’s tabs like buffers

Stop, stop, stop. This is not how Vim’s tabs are designed to be used. In fact, they’re misnamed. A better name would be “viewport” or “layout”, because that’s what a tab is—it’s a different layout of windows of all of your existing buffers. Trying to beat Vim into 1 tab == 1 buffer is an … Read more