
Efficient Editing With vim - ninjac0der
http://jmcpherson.org/editing.html
======
Tihy
Warning: learning Vim makes you look for Vim like commands in any program you
interact with using the keyboard. Everything else will be frustrating.

~~~
joshuaxls
I would kill for GMail to add vim-like text editing.

~~~
branden
Have you heard of the "It's All Text" Firefox extension? It copies the content
of any textarea to a tempfile and opens it up in an external editor of your
choice. Writes to the tempfile are copied back to the textarea. It's not quite
in-browser vim, but it's pretty close. <https://addons.mozilla.org/en-
US/firefox/addon/4125>

~~~
xtho
There is also ViewSourceWith which allows the use of different editors.

~~~
apotheon
. . . but Vimperator also Vimperates the entire browser, instead of just the
text areas. Unless you're an Emacs zealot, I don't see the downside.

~~~
xtho
I think we got it by now. Unfortunately, vimperator has quite a few quirks and
makes too many changes that cannot easily be undone, which is the reason why I
uninstalled it and moved to VSW.

~~~
apotheon
I moved in the opposite direction, from VSW (which I used heavily for a while)
to Vimperator.

------
mrshoe
Nooooo all of the secrets of our vim cult revealed in one easy-to-read
document! Vim is hard, people! Trust me. You're not smart enough to use it.

:-P

~~~
pyre
Actually, I find that Emacs has a steeper learning curve than Vi/Vim. I had an
easier time learning to switch between command/insert modes than to try and
get comfortable with all of the Meta-/Control- sequences in Emacs.

{edit} not to start a flame war.. to each their own {/edit}

~~~
apotheon
I find that Vim's learning "curve" is almost vertical at first, but Emacs'
gets worse as it goes while Vim's gets better. There's an image here that
illustrates the phenomenon pretty well:

<http://sob.apotheon.org/?p=981>

It's sort of a "ha ha only serious" moment.

------
scott_s
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.

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

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

~~~
solutionyogi
That's a neat idea. How do you change it to show tab number in the tab header?

~~~
bockris
This is for GVIM.

    
    
      set guitablabel=(%N%M)\ %f

------
Prolitheus
A decent intro; I'd add to the movement section these:

g$ - move cursor to last displayed character of line

Tx - move cursor backward and to the right of the first occurrence of x
(reverse of tx)

And get started with split views:

^ws - horizontal split view

^wv - vertical split view

^w{h,j,k,l} - move to window in respective direction

Some decent scripts to get started with:

minibufexpl.vim: <http://www.vim.org/scripts/script.php?script_id=159>

surround.vim: <http://www.vim.org/scripts/script.php?script_id=1697>

More of a full-fledge suite, a frontend to a head{ed,less} Eclipse server:
<http://eclim.sourceforge.net>

~~~
EAMiller
Another nice script I discovered recently is Nerd Tree :
<http://www.vim.org/scripts/script.php?script_id=1658>

~~~
Prolitheus
Nerd Tree is indeed a good one, and I'll add to this vimfs, which isn't a Vim
plugin but rather a CLI file system browser with Vim bindings. I hardly ever
actually browse my file system (zfs, grep, and locate do all of the work for
me), so I'm not sure how much mileage one can get out of this (especially
compared to something like Midnight Commander).

~~~
apotheon
My preference is to use things like cd and ls to browse the filesystem. When
I'm feeling really fancy, I might use tree.

~~~
Prolitheus
Do you sometimes let loose and use tree -C?

~~~
apotheon
I have done so, but not in a long time. Then again, I haven't even used tree
in a long time. Maybe I don't really use it any longer.

Hmm. . . .

------
durdn
This is one of the best articles to speed up vim proficiency. When I read it a
long while ago it really made a difference in my speed and typing joy.

If you guys love these kind of vim related posts, a while ago I had collected
some good articles with brilliant tips:

[http://durdn.com/blog/2008/11/26/vim-mind-share-soaring-
roun...](http://durdn.com/blog/2008/11/26/vim-mind-share-soaring-roundup-
of-10-vim-articles-recent-and-older-gems/)

------
10ren
Cool feature I discovered today, for multi-file project navigation:

    
    
      :tag yourMethodNameHere
    

Tab-completion works, so typing ":tag yourM", and pressing tab repeatedly
cycles through all the tags with that prefix (you need to have created the
tags file with ctags first).

~~~
mustpax
Tag jumping is also cool: Ctrl-] will jump to the tag under the cursor and
pushes the current location on the tag. Ctrl-T pops the tag stack and moves
you back to your previous location. Good for checking the definition of a
function and jumping back.

------
jballanc
See, this is one of the things I love about Vim: there's always something new
to learn! Somehow I had overlooked "K" to go to man pages. The other thing I
love about Vim is the excellent documentation! I wanted to know more about "K"
so I typed ":help K" and learned that, for example, if you're editing Ruby and
would rather use 'ri' in place of 'man', all you have to do is add ":set
keywordprg=ri" to your .vimrc (and if you have the ruby.vim files, it's
already done for you).

~~~
pyre
Just a note, but ':help' doesn't always go to what you want. For example the
option 'smartindent' (set with ':set smartindent') can be abbreviated as ':set
si', but ':help si' takes you to the help for the ':sim[alt]' command.

It's useful to note that when searching through help you type something like:

    
    
      :help 'si'
    

To get help on a variable and:

    
    
      :help :si
    

To get help on a command. The first form would take you to the help entry for
'smartindent' and the second would take you to the entry for :simalt. If you
just use:

    
    
      :help si
    

It will just find the first match for 'si', which in this case is the tag :si
and not the tag 'si'.

Other possible confusions with :help are:

    
    
      :help tab
    

Will take to the help for <Tab> (the tab key/tab character), whereas the help
page for all the things related to Vim tabs is:

    
    
      :help tabpage
    

(though :help tabs will take you to the :tabs command which is part of the
tabpage help doc)

~~~
nfnaaron
:help si<CTL-D> (type :help space s i and control-d after the i) will give you
all available variations in help on si, including 'si' and si among many
others.

CTL-D is a sort of intelli-suggest in context (except it's move 1/2 page down
in command mode)

:help<CTL-D> gives variations of help in your installation.

:help <CTL-D> (help then space then control-D) gives more variations.

:help help<CTL-D> (ask for help on help, with a control-D immediately after
the last p) gives more variations on help.

:help c_CTRL-D (literally typed just like that) is the help entry for using
CTL-D on the command line.

:help CTRL-D<CTL-D> (everything up to the first D literally, then control-D)
lists all the different help subjects for CTRL-D in various contexts.

:<CTL-D> (control-D immediately after typing colon) lists all the things you
can do on the command line, including help.

Help.

------
daok
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.

~~~
cturner
(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

~~~
pyre
You can control _a lot_ of things with guioptions. I would recommend doing a:

    
    
      :help guioptions

------
barrkel
I find it amusing that he asserts "blockwise selection mode. Extremely
powerful and available in very few other editors".

Blockwise selection mode is available in almost every Windows editor I use -
from the Delphi IDE, Visual Studio, even to Notepad2, Shift+Alt does block
selection, or alternatively Alt + mouse selection.

~~~
tetha
plus I still have to see a use for it. Usually I just go linewise or, inside a
line, with movements like f) or $.

~~~
barrkel
It's mostly useful for ASCII diagrams, in conjunction with overwrite mode.

~~~
apotheon
. . . or source code formatting, or adding comment characters to multiple
lines, or in any other way making an identical change to several adjacent
lines at the same time.

------
grosales
Pretty cool, I was learning Vim through "A Byte of Vim" at
<http://www.swaroopch.com/notes/Vim>

------
yurifury
:Ex is a very useful command. And at first I thought that doing 'vim foo'
where foo was a folder was just a quirk of UNIX, but eventually I figured that
it's a folder browse view.

No more feeling around folder structures with ':e'!

------
soundphed
if you are viming on an osx macbook of some sort and are sick of the damn
small-ass control key they left us with, i've found it helpful to remap the
caps lock key to control. you can do this easily in System Prefs > Keyboard >
Modifier Keys. so now you can <esc> insert mode with the ^[, hardly moving
your hands at all.

This works for me personally because I very rarely find myself even thinking
about or noticing the true CAPS key, but if you are stuck on your CAPS bein
CAPS, then this wouldn't be for you :!)

------
malditogeek
TIP for the Vim lovers out there:

Firefox: you can do a quick search hitting '/' Skype [Mac]: you can replace
text in your last sent message with the 's/<old>/<new>/' syntax

I would love to hear about other apps with Vim-ish behavior :)

VIM IS FULL OF WIN!

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

~~~
joshuaxls
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...](http://wint1.kaist.ac.kr/files/attach/images/59/450/vi-vim-cheat-
sheet.gif)

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

~~~
chewbranca
I've got that cheat sheet saved on my computer and I've looked at it several
times before, but today was the first time I realized that you can hit '&' to
repeat the last :s command on the current line. Very slick!!

~~~
joshuaxls
Yep, and 'g&' is really helpful. It runs the last substitute across the entire
file, preserving flags.

------
makecheck
It is also very useful to learn the code-folding commands ("z*"). Rather than
repeat them here, just say ":help fold".

------
gnubardt
remapping capslock -> esc will make editing so much easier and faster. being
able to easily enter command mode has increased my speed more than anything
else, it's also really useful in other interfaces, to be able to quickly hit
escape instead of reaching over to the top of the keyboard.

add xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' to your ~/.xinitrc on
linux

~~~
graywh
Remapping capslock to another control will make editing even easier and
faster. Especially when you realize escape can be entered with ctrl-[ and
sometimes ctrl-3.

------
pssdbt
Love me some vim, but isn't this kind of old? It is awesome though - think I
used it back when I was getting started with vim.

------
mkramlich
vi is my favorite Rogue-like, with NetHack in close second, and my own
<http://DeadByZombie.com> in third.

vi is the only Rogue-like where you can get real work done with it. And every
time you learn a new trick it's like your XP level or attribs go up, or you've
descended down to a new more evil level of the dungeon, with more powerful
monsters to fight with your enhanced vi-fu.

~~~
apotheon
. . . and I thought vi(m) was awesome before!

I will never look at the king of all editors quite the same way. You have my
thanks, mkramlich. May your life be long and prosperous.

(I totally didn't mean that to sound like a Vulcan blessing, I swear.)

