The default editor that comes with the UNIX operating system is called vi (vi sual editor). Alternate editors for UNIX environments include pico and emacs, a product of GNU. The UNIX vi editor is a full screen editor and has two modes of operation: Command mode commands which cause action to be taken on the file,. You can read this article, but I’m pretty sure since the default terminal in Mac OS X has a built-in scrollbar, the mousewheel commands automatically go to it. You could definitely use gVim as suggested in the previous answer. I find that I don’t generally want to use the mouse in Vim though as it takes my hands off the keyboard.
Using Vim Macro feature you can record and play a sequence of actions inside the editor.
This article explains how to perform record and play inside Vi and Vim editor using two detailed examples.
Type: Esc i followed by 1.
Type: Esc q followed by a
Type: Esc yy followed by p
Note: Vim will still show recording at the bottom as shown below.
Type: Control a
By placing the cursor at the 2nd line, press Ctrl+a which increment the number to 2. as shown below.
Note: vim will still show recording at the bottom.
Press q to stop the recording. You’ll notice that recording message at the bottom of the vim is now gone.
Type: [email protected]
This example explains how you can executing the same command, with different input for it. i.e Framing the same command, with different arguments.
Type: q a
Type: I (Upper case i) followed by “ALTER USER ”
Place the cursor anywhere in the first line, and then press I. Which will take you to the first character of the line. Type ALTER USER
Type: Esc w yw
Type: Esc A followed by ” IDENTIFIED BY ‘”
Type: Esc p
Press Esc, and then type p to paste the name that was copied in the step #4.
Type: Esc A followed by ‘;
Press Esc, and A to go to the end of the line, and ‘;
Type: Esc j followed by q
Note: The recording message shown in the bottom of the vi will now disappear. At this stage, the change-password.sql will look like the following.
Type: 8 @ a
Vim 101 Hacks, by Ramesh Natarajan. I’m a command-line junkie. So, naturally I’m a huge fan of Vi and Vim editors. Several years back, when I wrote lot of C code on Linux, I used to read all available Vim editor tips and tricks. Based on my Vim editor experience, I’ve written Vim 101 Hacks eBook that contains 101 practical examples on various advanced Vim features that will make you fast and productive in the Vim editor. Even if you’ve been using Vi and Vim Editors for several years and have not read this book, please do yourself a favor and read this book. You’ll be amazed with the capabilities of Vim editor.
Following are few awesome Vi / Vim editor tutorials that you might find helpful.
Note: Please subscribe to The Geek Stuff and don’t miss any future Vi and Vim editor tips and tricks.
I’ve been googling around trying to figure out if it’s possible to use my mouse wheel to scroll while inside Vim in Mac’s Terminal, with no luck. It seems as if only X11 or iTerm support this.
Before I give up, I thought I’d try the geniuses here to see if anyone knows a way to do this. So, does anyone know if I can set that up?
Or should I seriously consider using a different terminal application?
Use MouseTerm (and do make sure to install SIMBL first!) and scrolling will work like a charm, even remote, using Mac Terminal.
You need to fully quit the Terminal application (Command+Q) and then launch it again after installing MouseTerm.
And if you’re using iTerm, add this to your vimrc
This is an old question, but a top hit on google, so I feel compelled to provide an updated answer. Powersaves mac download online.
Running OSX El Capitan 10.11, vim mouse and trackpad scrolling just worked(TM) for me in Terminal.app by default. However occasionally the mouse/trackpad input stopped manipulating the vim buffer, and started scrolling the terminal buffer. The answer was
Command+R or Menu View –> Allow Mouse Reporting. Turning that on allowed the mouse/trackpad scroll operations to move the cursor in vim.
You can read this article, but I’m pretty sure since the default terminal in Mac OS X has a built-in scrollbar, the mousewheel commands automatically go to it. You could definitely use gVim as suggested in the previous answer. I find that I don’t generally want to use the mouse in Vim though as it takes my hands off the keyboard.
I just use
50j to go down and
50k to go up. Not exactly scrolling, but it works pretty well.
If the mouse functionalities still do not work properly take a look at my answer in this post How to let vim behave on Mac OS X as on Ubuntu?, just add to your .vimrc
Make sure the terminal is
xterm & not
Terminal Menu > Preferences > Profiles > Advanced. I accidentally broke scrolling by changing the term type in a naive effort to get coloring to work over ssh.
Use gVim, which gives you a text editing environment in a window you can scroll. Terminal is not involved when using gVim.
I’m using xterm in X11 (XQuartz 2.3.4) and vim works very fine with mouse and also suport 256 colors.
Here is the ~/.Xresources I use to make my xterm nicer in X11:
Little tips, to remove the bell sound in X11’s xterm type this command:
I would recommend using iTerm – it has so many advantages over Terminal eg Mouse support, 256 colors, sensible copy and paste (auto-copy, word/url selection with double click, middle click paste)…