Live data from Hacker News

Efficient Editing With vim

jmcpherson.org

11–20 of 125 posts

Re: Efficient Editing With vim

#11
post #6

I feel silly for only recently discovering tabs in vim. :tabnew file Opens up a new tab, :tabn Goes to the next tab, and :tabp Goes to the previous tab. Works great in both gui and non-gui mode.

gt and gT in command mode also do next tab and previous tab

Awesome, I didn't know this shortcut before! Much better than using :tabn :tabp !

Re: Efficient Editing With vim

#12
post #6

I feel silly for only recently discovering tabs in vim. :tabnew file Opens up a new tab, :tabn Goes to the next tab, and :tabp Goes to the previous tab. Works great in both gui and non-gui mode.

gt and gT in command mode also do next tab and previous tab

[deleted]

Re: Efficient Editing With vim

#13
post #6

I feel silly for only recently discovering tabs in vim. :tabnew file Opens up a new tab, :tabn Goes to the next tab, and :tabp Goes to the previous tab. Works great in both gui and non-gui mode.

gt and gT in command mode also do next tab and previous tab

also #gt will go that tab number. I've changed my tab text to show the number in parenthesis before the name.

Re: Efficient Editing With vim

#15
post #6

I feel silly for only recently discovering tabs in vim. :tabnew file Opens up a new tab, :tabn Goes to the next tab, and :tabp Goes to the previous tab. Works great in both gui and non-gui mode.

Similar to this, you can open up multiple files at the same time without saving.

    set bufhidden
    nmap  :bp
    nmap  :bn
If you put this in your .vimrc file, you'll need to put a '^M' at the end of the nmap lines. You do this by doing and it puts in a special character that means newline. Then you can switch between open buffers with ctrl+l and ctrl+h even if you have unsaved changes. it will end up looking like this:

    set bufhidden
    nmap  :bp^M
    nmap  :bn^M
Unfortunately if you have many files open and don't touch them all it prevents you from quitting with a message 'E173: 17 more files to edit'. I haven't worked out how to obliterate this without damaging features I want (e.g. not quitting when there's unsaved data in those other files).

The default vim that ships with linux distributions is often a pile of junk that has been hacked by the distribution, is missing features like these. You want to get vim-extended under redhat-like distributions (they've significantly improved the quality if their junk vim in recent releases), and vim-nox or vim-full in debian-like distributions.

Re: Efficient Editing With vim

#16
post #7

Amazingly, this is the first I've heard of fx/tx/Fx. How ridiculously awesome.

This is especially powerful when trying to move small chunks of code around. Say you have something like

document.getElementById('asweetid')

and you want to grab just the id for use elsewhere. In command mode pressing f' will move your cursor to the quote, yf' will put 'asweetid' into your yank register and a p anywhere else will paste it. I also make heavy use of ctx where x is a character on a line that I want to replace up to. The best part about vim, I think, is how I think about the commands in my head and they just kind of flow out of my fingers.

"Hmm I want to change (press c) to (press t) that closing paren (press shift 0)."

Even just typing that my left hand instinctively moved toward the caps lock to go to command mode.

Re: Efficient Editing With vim

#17
post #5

I think it's the first time that I want to install vim to try it. As a Windows user, I always found NotePad++ and other text editor an easier choice but I can now see some powerfull utilities to vim now. Very clear article.

(I'm just throwing tips in comments where I see opportunities to help people who find any of the same niggles I've had over the years.)

Users who want to run Windows vim with no titlebar, create a file _vimrc in your base vim directory (on my windows desktop it's C:\Program Files\Vim). In this, put this line:

    set guioptions-=T

Re: Efficient Editing With vim

#18
post #7

Amazingly, this is the first I've heard of fx/tx/Fx. How ridiculously awesome.

I have this printed out and taped up right next to my monitor: http://wint1.kaist.ac.kr/files/attach/images/59/450/vi-vim-c...

It's helped me polish off those last few vim commands that I never got used to. I recommend looking at it daily.

Re: Efficient Editing With vim

#19
post #14

Warning: learning Vim makes you look for Vim like commands in any program you interact with using the keyboard. Everything else will be frustrating.

By force of habit, when I wanted to close an IM window, I have typed

  :q
Instead of switching to the mouse and hitting the "x". Then I had to explain to the person that I wasn't sticking my tongue out at them.
Post reply on HN