Speed up cursor in macvim with janus - vim

I have MacVim installed and want to increase the speed by which the cursor moves about the screen. In other words, I want the cursor to move faster when I click on the arrow keys or h,j,k, and l. What command do I add, and which file do I add it to? (.vimrc, .vimrc.after, etc...)

The simplest solution would be to drop Janus which is full of settings and plugins (30) that you probably don't use/need. Or, at the very least, review all of the decisions made for you by complete strangers and remove/reset anything you don't need.
A better solution (in the long term) would be to learn about motions and text-objects: for anything other than very short movements hjkl and the arrows are equally useless when you get used to bBeEwW^$fFtT{}()[]<C-f><C-b>/? and so on.
As I like to say, :help motion.txt will blow your mind.
Or $ vimtutor, actually. Did you do it?

Related

Vim: Is it possible to bind a key to open search (i.e. put me in the command mode having entered a slash, but do not type anything)

While vim's way of doing things is generally good, I feel like there are aspects that really get in the way as somebody who is not completely committed to vim for text-editing.
This means that I am hitting Esc+/ and typing slashes into files in Sublime Text, and hitting Ctrl+F in vim, scrolling down a page.
Similar things happen with Ctrl+S and :w and custom mapping ; to : still doesn't make it as convenient and fail-safe as Ctrl+S. Not to mention in PuTTY, Ctrl+S does something rather upsetting (it suspends output from the terminal till Ctrl+Q is pressed). Basically, IMHO some things (like switching to a "find mode" and saving the file) are good to attach to a global left-hand home-row shortcut chord rather than requiring the user to mess about in a modal command line. It simply is too often used to subject the user to these mode changes. I suppose this isnt a legitimate complaint because the entirety of vim is constructed around the modal concept, and these functionalities are a result of that.
In any case I'd like to make it a bit easier on my brain because I've tried for a while now to keep it all intact and it's simply too much (I have more or less internalized the switching between Ctrl on a windows machine on a desktop keyboard and the use of the thumb for the Cmd on my Macbook, but this modal text editor business seems to be too much). It did not take too much deliberation for me to decide that global homerow key chords are simply more intuitive.
Mapping Ctrl+S to :w is trivial, so the question here is about the find mode. I want to bind Ctrl+F to put me in find mode, but repeating it should not type slashes into the find command. Can this be done? Is there perhaps a colon-command that when executed simply drops me into the current find-command-buffer-thing?
In your .vimrc add:
inoremap <C-f> <Esc>/
noremap <C-f> <Esc>/
In whatever mode you are in, this will put you in "find" mode (it actually just types a slash in the command line which you can use to search). With these bindings it will work for all modes, even if you are in insert mode.
do you want this?
nnoremap <c-f> /
if you like you can also try
nnoremap <c-f> q/
the 2nd mapping brings you to a search history window. you could choose previous search keywords/patterns. also available to type new pattern (by pressing i)
btw, there is no find mode
Mappings can be defined separately for the different modes in Vim, see :help map-modes. This automatically takes care of your proposed <C-f> mapping: Initially, you're in normal mode, then the search pattern is entered in command-line mode.
If you so far only occasionally use Vim, and find it too "different", several things may make the switch easier:
easy Vim (evim or vim -y) defaults to insert mode
on Windows, :behave mswin and the $VIMRUNTIME/mswin.vim script create some common Windows shortcuts
graphical GVIM has menu items like Edit > Find... and toolbars.
Some things like the flow-control freeze on <C-s> in terminals are unfortunate, mostly historical accidents; you can't blame Vim for those.
You don't need to map anything. / is expressive enough and is definitely not slower than <C-f>. Same for <C-s> which, despite a certain familiarity, is not much better than :w<CR>. You are learning a new tool, remember?
What you should focus your efforts on is getting confortable with Vim's modality. The simple fact that, for you, doing a search involves hitting <Esc> is a sign that you didn't get that part. Your other comments on using Vim shortcuts in ST and ST shortcut in Vim are not good signs either and the part where you complain about having to adjust to your Mac's Cmd is the icing on the cake, IMO.
It may sound brutal but, from your question, it seems like you are doing too much at the same time, without organization and for, probably, no good reasons.
Switching from Windows to Mac OS X and switching from ST2 to Vim at the same time is sure to be confusing and I suggest you slow down a little and make a choice before you loose your mind and waste more of your time.
Which leads me to this: Why do you use a Mac and why are you using Vim?
Windows is a fine OS. Sublime is a fine editor. Even if you switch to the Mac, Sublime works very well there. So Why Vim?
If you are tired by some Sublime limitations and want the awesome power of Vim, fine. But you must wrap your head around its modality and awkwardness and accept to change your habit.
If you don't approach Vim with more flexibility, you'll never get full benefits.
If you decided to use Vim because it is trendy, I'll respectfully suggest you to stop there and go back to Sublime. Vim is weird, Vim is different, Vim is huge, Vim is a rabbit hole… if you are not ready to work with it and insist on not accepting its core design, you won't get far so why bother? You can pretty much live all your professional carreer without ever touching Vim. There's no shame in that.
Remapping / to <C-f>, on the other hand…

vim keybindings with neo keyboard layout

This question is the same as this one, only regarding the (lesser known) neo keyboard layout instead of dvorak.
I want to start programming and I understand that vi and vim are considered to be highly productive editors for coding if used wisely.
Now I'm using the neo keyboard layout and I wonder what keybindings for vim might be best suited for this layout.
I don't want to learn to use vim, find out my keybindings don't work well and then I have to readjust my habits.
So to all of you who use vim + neo: How do you remap vim's keybindings to best work with neo?
(More generally: What are the things I should keep in mind when changing vim keybindings?)
Generally, I wouldn't change the keybindings. The Vim commands work because by and large they're mnemonics. Just leave them alone and use them where they stand. I see that hjkl aren't so well laid out on that layout but you do seem to have cursor keys behind "Ebene 4" so if that's not too much trouble maybe that'd be ok. (I don't find myself using hjkl much anyway, I usually use other more direct jump movement commands.)
I'm a Dvorak layout user.
More generally, as a VIM user but not a Neo user, I would generally mimic the VIM key layout onto your keyboard. Pay attention to which keys in VIM are under the resting positions of each finger and translate that onto Neo.
Keeping a traditional layout that is overlaid onto new keyboard layout will keep common keys under your resting finger positions. It will also build muscle memory that can be transferred to QWERTY when you need to work on a non-Neo keyboard.
I am a VIM and Neo2 User myself.
Both quite a time now. And I can tell you: about 90% of the commands are even nicer to use (imho at least), than they where back on qwertz. Some '`' commands type weird, but you get used to it. But you may consider to change vim's LEADER-Key (i've moved it to 'j') tho.

Is there a way to move within a file in Vim similar to Emacs' Isearch?

I've been using Vim for some time and I feel that I'm finally becoming somehow 'fluent' with it, but some of the feature listings, videos and other stuff I've seen (particularly Tim Visher's Vimgolf in Emacs series) really convinced me to give Emacs a try.
So for the past week, I've been using Emacs almost exclusively. I really miss some concepts I'm familiar with from Vim (mostly the action-movement style, things like ci" etc.), but one thing I really learned to love in Emacs is the way to move around a file with Isearch.
For example, if I wanted to move to a line where a function fn is called, and there were 2 other instances of 'fn' between the point and the position I want to move to, I'd do C-s fn C-s C-s. If I wanted to do the same in Vim, I'd have to do something like /fn <CR> n n :noh <CR>, which is nowhere as nice, so I'd probably just check the line number and do #G wwwww....
So my question is: is there a way to emulate the efficiency of Emacs' movement with search in Vim? It doesn't have to use search, I'm just looking for something other than the cumbersome go-to-line and forward several words I described above.
Edit: Item 4 in Effective Emacs describes nicely what I'm trying to accomplish.
What is described in your link is exactly my primary mean of movement in Vim: /foo<CR>nn for incremental forward search and ?bar<CR>nn for incremental backward search.
I don't see what is more efficient in <C-s>foo<C-s><C-s> and <C-r>foo<C-r><C-r>: that's even more keystrokes!
Anyway, I think that :set hlsearch is your problem. If all the matches are contained in the viewport that's OK but, as soon as some matches are hidden it becomes useless. I don't have set hlsearch so /foo<CR> is quite the opposite of inneficient for me.
Well, another problem is having (at least) three functions with the same name in the same file…
Vim has wonderful text-ojects: } or ]m that are very useful when looking at some code for the first time.
You can emulate Emacs with this keymap: cnoremap <C-s> <Cr>/<C-p>.
Though Vim has better ways for moving around than searching. Have you tried ctags?
I also recommend the EasyMotion plugin for quickly moving around in the visible area of the text.
I think you're looking for
set incsearch
you can couple it with
set hlsearch
for even better results.
Also check out "*", it's pretty awesome.

Vim, Long Lines and Scrolling

I use Vim to edit English text files with >10.000 words and long paragraphs. The files are formatted as plain text and each paragraph is a long line. I use the wrap option, and I bind j and k to gj and gk respectively so I can move by display lines.
If my cursor is on the top of the screen (but not the beginning of the document) and I move the cursor up (using gk), the screen scrolls up to display the whole long line (a 300-word paragraph). The problem is that because of the length of the line this makes the screen scroll by half of the screen. This is disorienting because I don't know beforehand how much the screen will move. Scrolling with ^Y has the same problem.
Is there a way to make Vim scroll by just one display line when using gk and its ilk? This is more natural for editing non-source-code and the default behavior in most text editors as well as in word processors, but not in Vim. I think this would mean that Vim would have to stop insisting on showing the entire line I'm editing.
I have personally fixed this problem by switching to hard wrapped prose documents. I don't believe there is any other solution. Here's one of the articles that first exposed me to the idea: http://alols.github.io/2012/11/07/writing-prose-with-vim/
I must confess that, in the beginning, the idea to convert all my documents to this old-fashioned way of writing text files looked annoying as hell to me, and it'll probably do to you too. But I soon realized by trying other modern editors that none of them was as powerful and stable as Vim. All it took me before this felt completely natural was some formatoptions tuning. In my case, this works best:
setlocal formatoptions=wat
Also, here's one handy function I discovered to go back to soft wrap at anytime which you might find useful: Unwrap text in vim
I suggest you define a macro to scroll your page. If you have a screen height of 50, you could go with something like:
map zp 48gj

Vim: transitioning from mouse to movement

I use MacVim (and gvim) a lot. I'm familiar with and use a lot of the basic movement commands (b, w, $, 0, G). However, for a lot of things—such as selecting particular lines on the screen or jumping to a particular column in a different line—I use the mouse (sometimes in concert with my left hand on the keyboard). It also helps that my mouse has a scroll wheel and buttons for changing tabs.
I also need to admit... I use the arrow keys on my keyboard rather than hjkl.
I think that my speed (and posture at the computer) will be improved by not having to escape from insert mode, and from keeping both hands on the main part of the keyboard.
What convinced you to abandon the mouse? What are the most helpful shortcuts for moving quickly between lines and columns, scrolling, etc.?
This question is inspired by this recent post
I think that my speed (and posture at
the computer) will be improved by not
having to escape from insert mode
No, you must escape from insert mode right after you typed what you want. It quickly becomes a reflex, so you don't really lose time (I sometimes even press escape after completing a web form...). Normal mode isn't just for moving around, it's used to perform most operations (save from typing): for instance deleting or moving sections of text. You also benefit from entering insert mode with the appropriate key: o to start a line, S to replace a line (while keeping indentation), A to move to the end of the line, c+motion to replace a few words or until a given character... All of these save keystrokes.
The mouse seems fast, but in reality it isn't precise, so you lose time (in addition to the constant back and forth with the keyboard). ViM has a long list of moving commands (see :help usr_03) which, when mastered, are faster than the mouse in most situations.
Use search the most you can (/, ?, *, #, f, t...). I personally use Ctrl+(d,u,f,b) a lot. Also, Ctrl+(o, i) and `` are really useful to go back where you were before a search or something else.
h, j, k, l are there to place your right hand near to useful commands (i, u, o...): I always have my fingers on them. The arrows force you to move your hand a lot.
Try to look at a few commands in :help, then use them a lot, and you'll get habits about what you should use to move according to the situation. Nobody uses ViM the same way.
The more I used the keyboard movement in vim, the less I wanted to use the mouse. It doesn't help that extended periods of time where I'm constantly moving from keyboard to mouse can take a toll on my wrist.
If you want to force doing things the vim way, unplug your mouse for a while! The more you use the keyboard, the more you will love it. This worked for me.
For moving between lines, I usually just use jk but I often skip to lines using :line_num. Getting to a specific column in a line, I typically use wbe^0$ and put modifiers in front of w, b, or e if I'm skipping through several words. And there is also the shifted versions, WBE which also come in handy often.
I have to admit that I often use the arrow keys for specific movement in vim.
I rarely use hjkl. However, I find that most of my navigation is done with other commands such as w (skip a word forward), b (skip a word backwards). Combine this with modifiers such as 3w (3 words forward). : skip to a specific line.
I've never really had to abandon the mouse since I never really started with it. All I can say is that attempting to use editors without all the keyboard shortcuts that vim has can feel quite painful.
I'd run vimtutor from the command line (Terminal.app in OS X). It runs vim with a tutorial document. That document was what really made me realize the power of some of the commands. You'll pick up some that are most useful to you and gain more over time. Eventually you'll find yourself using the mouse less and less.
One command that will really improve your movement speeds is f. f plus a character will jump to the first occurrence of that character on the current line. Pressing ; will jump to the next occurrence. Of course this can be used in combination with other commands. So, for example, removing all characters up to and including the first closing parenthesis is achieved by pressing d+f+).
You can seriously revolve your life around jk in hjkl.
nnoremap <c-k> ddkP "move current line up one
nnoremap <c-j> ddp "move current line down one
vnoremap <c-j> dp'[V'] "move visual block down one
vnoremap <c-k> dkP'[V'] "move visual block up one
"These may be a bit more esoteric to me"
inoremap jj <esc>o "Insert mode can move to next line (works mid line)
inoremap kk <esc>O "Insert mode new line on previous line
also for the desktop gui (ion3 and gnome)
winj - next window
wink - prev window
(This beats alttab if your editing in vim all day)
also read :he motion.txt in its entirety using j and k to scroll up and down as you do.
I learned vi so for me the mouse has never been something to use with a text editor.
I don't use hjkl except when the machine/network/keyboard/whatever-in-between is not comfortably configured.
Use the mouse where it makes sense. It often does (copy/paste to and from other gui applications).
To answer your question, though: Once you start using vim as a tool for transforming text bits with macros, the movements will all start to fall into place ;)
I think you're wondering if there's a quick way to move around while in insert mode (without using the mouse or arrow keys) but unfortunately there isn't; you have to escape out of insert mode. However I know that jumping all the way to your Esc key can be really annoying, which is why I've gotten into the habit of escaping with Ctrl+c, it's much faster.
I almost never use hjkl because it's too tedious. I usually try to jump right to where I want to go. There's a great cheat sheet out there (a Dvorak version is a available also (although it's in PDF)) that you can stare at and imagine the possibilities.
Mostly I use f, F, t, and T, and sometimes they're enhanced by typing a number up front like d2t) will delete up to the second close paren. Sometimes I use search. A lot of the time I use w, W, b, B, e, and E. They're all fantastic.
When I see vim users arrowing all over the place in visual mode just to delete text it makes me shudder, because there are so much easier ways (and hjkl only make you move your arm less, they don't change the number of button presses).
Something I did that I don't know if it's common or not is remapped my arrow keys to be <Esc><Up> and so on. For whatever reason I started out always arrowing around and assuming I'd be back in normal mode, so I just made it do that...
The biggest bummer about Vim is that now when I edit anything anywhere else I hit escape all of the time and type :w after every change...

Resources