vim (Vi IMproved) is a text editor supporting different editing modes.

learn more… | top users | synonyms

9
votes
5answers
3k views

vim: replace all character till end of line

Maybe I am being daft but can you replace all the characters from where the cursor is to the end of line by one command? Then use . to do the same replace on the next line and so on.
9
votes
3answers
4k views

How to move to last character of the file in vim?

File: i am someone1. i am someone2. i am someone3 ~ ~ Documentation says G takes me end of the file, but it only takes me to the beginning of last line. I want to be able to come to last character ...
9
votes
2answers
1k views

Select code block in vim

Given a code like this: 588 while ($linecounter > 0) { 589 $token = " "; 590 while ($token != PHP_EOL) { 591 if (fseek($handle, $pos, SEEK_END) == ...
9
votes
2answers
2k views

Can less invoke vim instead of the default vi when I hit the 'v' key?

I want to launch vim instead of the default vi editor when I hit v in less. Are there any settings I can modify to allow me to do this?
9
votes
2answers
5k views

How do I cycle through panes inside a window in tmux like in screen?

I thought Tmux - move window to pane was the same question but it doesn't seem to be. Coming from using GNU screen regularly, I'm looking for tmux to do the same things. On of the things I do ...
9
votes
4answers
699 views

Delete whitespace for a set of lines in Vim editor

I have some text like the following in a file: sample text some random text even more random text text with no indent worst indention I need to delete the empty space before each ...
9
votes
2answers
582 views

vim: use string from search in replace command

I often use vim / search command to verify my regular expressions (just to see what it matches). After that i usually use the :%s replace command, where i use that regexp from search as a string to be ...
9
votes
2answers
366 views

Trying to “locate” and then open a file

Suppose that I have a file named filename123.txt and it is the single file that is named so, and I can locate it with the command locate filename123. And it returns only this file. Now I want to open ...
9
votes
2answers
981 views

What is meant by a shell is in “vi” mode or “emacs” mode?

This question follows directly from the answer to one of my previous questions here. I am newbie to unix world and this site has helped a lot to understand some core concepts. In this case I am ...
9
votes
2answers
733 views

How to set on executable bit for a particular file automatically

I want that when i make create a particular file, suppose i create it in vim editor, the created file should get executable permission as well when it gets created . I want this as i am creating some ...
9
votes
1answer
1k views

Vim: Making XML text “pretty”

Is there an easy way within vi to make your XML text "pretty"? For example: I want this.. <person> <name>Nick</name> <age>26</age> ...
9
votes
2answers
566 views

vim - open file and goto line number using <filename>:<line nbr>:

Several tools such as grep, py.test, etc ... use the pattern <FileName>:<line number>: to point to errors. For example: ; grep -Hn Common setup.cfg setup.cfg:11: Common How can I ...
9
votes
2answers
376 views

How do I modify the ci command in vim

Just like "ci(" changes everything between parentheses, I want "ci$" to change everything between dollar signs (for editing LaTeX.) Is this possible?
9
votes
3answers
614 views

GVim compiled from source opened via SSH -X does not copy paste on selection

I'm using SSH (with -X specified) from a Ubuntu box to a RHEL4 box and running GVim. It opens as expected in my local X, but the copy and paste via select doesn't work. I cannot select text in GVim ...
9
votes
3answers
80 views

Bash autocomplete with vim command

In bash, autocompletion of paths has recently stopped working when issuing vim commands where the path is deeper than two directories (it continues to work as expected with other commands, such as ls ...
9
votes
1answer
798 views

Why am I getting 'Name collision between …' errors and how can I fix them?

Every time I try to launch vim or emacs or even top (I think it's actually any command that uses ncurses) in a unix terminal (on a cluster computer over ssh), I get a a continuous stream of 'Name ...
9
votes
2answers
333 views

Vim, context-sensitive comment/uncomment behavior

I edit a lot of PHP code with Vim, and I've run into a snag with some macros in my .vimrc. I currently use these two macros to comment/uncomment in C-style "c-style (//) comment (press the [.] key) ...
9
votes
1answer
929 views

How to have tail -f show colored output with vim?

In this question, Gilles answered Yet another possibility is to run tail -f in an Emacs shell buffer and use Emacs's syntax coloring abilities. Because I'm a vim user, I'd like to do this with ...
8
votes
5answers
2k views

What is `^M` and how do I get rid of it?

When I open the file in vim I am seeing strange ^M characters. Unfortunately, the world's favorite search engine does not do well with special characters in queries, so I'm asking here: What is ...
8
votes
5answers
9k views

delete line in vi

How can I delete a line in VI? Here what I am doing right now: Open up the terminal alt + ctrl + t vi a.txt I move my cursor to the line which I wan to delete, then what key-combination is should ...
8
votes
4answers
1k views

Why would vim return non-zero exit code if I exit immediately after opening?

I'm running into a bit of a strange problem w/ vim on Snow Leopard: I get a non-zero exit code from simply running vim and then quitting. $ vim # exit immediately using :q $ echo $? 1 However, if I ...
8
votes
2answers
313 views

Is there a command reverse search in vim?

In linux cli I can do ctrl-r and do a reverse search and choose something I have done easily. Is there something similar in vim? I mean I may run a command using : (could be anything like a long ...
8
votes
2answers
378 views

vim: Can I make *only* y perform a copy?

I'm learning to like vim, but one thing that I haven't yet fully embraced is the copy and paste situation. In a muggle text editor I would Ctrl-C copy a piece of text and then edit/delete and then ...
8
votes
6answers
5k views

Are cygwin vim commands different than normal vim?

I am unable to edit text files using vim in cygwin. I have to press i many times to insert text. Sometimes it works and sometimes doesn't. Whenever I move cursor up down I have to press I many times. ...
8
votes
3answers
356 views

Vim: pasting lines line by line

Let's suppose I have a file containing: xxx yyy zzz and another file: kkk qqq ppp I want to obtain: xxxkkk yyyqqq zzzppp Is that possible in Vim with some command? (I've tried using VISUAL ...
8
votes
4answers
320 views

vim: hide first n letters of all lines in a file

I am analyzing log file using vim and the format looks like this YYYY-MM-DD HH:MM:SS.USEC PID Name LogText Since Most of the times I don't care about date and time. I want to hide them and just ...
8
votes
1answer
340 views

Is there a way to move by screen lines in vim?

When editing files in vim, it is a small annoyance that when I move lines with j and k, it moves by file lines, rather than screen lines like other editors. With my own files, I can deal with this by ...
8
votes
2answers
328 views

Vim command for inserting a character

I'm looking for the opposite of x. I want to insert just one character and stay in command mode.
8
votes
2answers
1k views

why inode value changes when we edit in “vi” editor?

When I edit a file in "vi" editor the inode value of the file is changing. But when edited with cat command the inode value is not changing.
8
votes
1answer
984 views

How to change the name of a vim buffer

Is it possible to change the name of a buffer in vim? Specifically, I'm using Conque Shell to open shells in vim (each shell is in a buffer) and with multiple shells, I see: 10: bash - 1 11: bash - ...
8
votes
2answers
2k views

Copy text from one tmux pane to another (using vim)

I have two files opened in vim, each in one tmux pane. I would like to copy let's say 10 lines from one file to another. How can I accomplish this not using the mouse's Copy -> Paste ?
8
votes
2answers
186 views

VIM: show all lines edited in session

Is there a command or plugin that I can use to show all the lines I have edited in a Vim session? I would like to be able to have all the changes I have made highlighted when working in co-workers ...
8
votes
1answer
748 views

What would cause vim not to retain command history?

On other distros I have run, vim remembers your command history even between sessions; this is especially handy when doing a lot of similar operations on different files. For some reason, it has been ...
8
votes
2answers
668 views

tmux, TERM and 256 colours support

Introduction My question arises from the necessity of understanding why I have now (after multiple trials) Terminal and tmux supporting 256 colours and tput colors telling me there are only 8 of ...
8
votes
1answer
1k views

screen + vim — Any way to automatically set screen window name to open vim filename?

I have a pretty nice screen rc file that shows me the open screen windows almost like tabs at the bottom of the terminal. Currently the windows are named according to my prompt which is not so useful. ...
8
votes
2answers
166 views

Vim - map last shell command to the key

Is there any way to map leader-r to repeat last command sent to bash? For example, when working with C files I would like to compile and run program from vim without typing :!make or gcc. I know I ...
8
votes
0answers
87 views

vim/gvim failing to put X11 clipboard in registers “+ or ”*?

Due to the lack of security with standard vino server, I switched to use x11vnc on my linux (with Xubuntu 14.04) box and SSVNC on the windows side. With vino, cut and paste from windows to Linux ...
7
votes
8answers
2k views

Compiling code from vim

New to vim and and I want to be able to compile code from within vim without running a new terminal and calling the compiler. How do I go about doing this? Note that this requirement is not ...
7
votes
4answers
608 views

vim insert current filename into the contents

After some searching, I got to know :echo @% display's the current file-name in the bottom line of vim-screen. I would like to dump the file-name(with and without full path) into the contents of the ...
7
votes
3answers
2k views

How to make a symbolic link to /usr/bin/vim but with start-up parameters?

After I make&make install vim from source, I found many symbolic links of vim in /usr/local/bin, such as evim, rvim, view... The vim(1) man page said that "rvim" is equivalent to "vim -Z" and so ...
7
votes
3answers
600 views

Temporary .vimrc

Is there a way to read a .vimrc file for only a single ssh session? That is, when I log in I perform some operation so that vim uses say /tmp/myvimrc until I log out? I do not want to permanently ...
7
votes
7answers
1k views

Open a file given by the result of a command in vim

I find myself doing the following almost every day Run a find (find -name somefile.txt) Open the result in vim The problem is I have to copy and paste the result of the find into the vim command. ...
7
votes
2answers
4k views

How to compile a c program without leaving the editor? [duplicate]

I am using vim editor on Linux mint. I want to know if there is any way to compile c program without leaving the editor.
7
votes
5answers
3k views

vim on FreeBSD does not react on arrow keys correctly and other vi-like behaviours

I tried to use vim on FreeBSD (via ssh on Linux xterm-compatible terminal). However vim behaves similar to vi out-of-box. For example it does not react on delete key, insert F character instead of ...
7
votes
2answers
418 views

How can I switch 2 characters in vi?

I like the fact that I've memorized ddp for switching two lines (i.e. dd deletes the line and then p puts it back '1 higher'). Is there are similar set of keystrokes for switching 2 characters so ...
7
votes
2answers
264 views

How do I get just the user-manual for Vim

To get the vim user-manual I am doing vi test and then, once the file is opened, I do :help user-manual This opens up a split window, which makes reading manual inconvenient to read. How do I ...
7
votes
1answer
2k views

Jump to specific character in a line in VI

In VI, I know that if you do :some_number and hit enter, you will jump to the line specified by "some_number". Is there an equivalent for jumping to a specific character in a single line? ...
7
votes
2answers
650 views

vim spell checker?

Is there a way to spell check a file using vim?
7
votes
2answers
1k views

How to make vim apply /var/log/messages syntax highlighting to any file called “messages” or “messages-*”?

I love vim's colorization of /var/log/messages, but it only works for that – the absolute filename. It doesn't work for older rotations of messages (e.g. /var/log/messages-20120610) or for messages ...
7
votes
1answer
2k views

Setting vim filetype with modeline not working as expected

As per the accepted answer to this question, I'm attempting to use modelines in vim to force filetype detection in some files. For example, at the top of a file named gitconfig (note there is no ...