EzDevInfo.com

vi interview questions

Top vi frequently asked interview questions

Vi-Vim like control keybindings for Windows

I've been using gVim for a while and love the interface. I'm in love with my keyboard-fu skillz.

I was wondering if there was any application that would extend its functionality to all parts of Windows 7? At least some basic functionality.

I'd like to be able to control Explorer, a browser, etc.

I just want to stop using my bloody mouse. It's no fun.

Thanks.


Source: (StackOverflow)

How to show the current Vi mode when using Vi keybindings in the shell?

I use the vi keybindings in my tcsh shell.

Now, I don't know which vi mode I'm in (insert mode or command mode), which leads to a lot of frustration.

Does anyone know of a way to show the current vi mode in the shell? (by including in the prompt or something)


Source: (StackOverflow)

Advertisements

What Vim features do you use? [closed]

I spend almost all day programming in Vim and I am sure that a lot of you do too. What features do you use that make your day to day coding that much better? One that I use is gv, which will let you reselect the previously selected text. It is great for reindenting!


Source: (StackOverflow)

How to use a pipe to edit a file with vi

Lets say I have a file called file.txt. In it is a name of a file that I want to edit with vi. I want to do something like this so that I can edit the file:

cat file.txt | vi

However, that doesn't work. How can it be done?

To clarify things:

Here are the contents of file.txt:

textfile

So I want to somehow send the contents of file.txt to vi so that the same thing will happen as when typing vi textfile.

The contents of file.txt can change. I want vi to edit whatever file is listed in file.txt.


Source: (StackOverflow)

Inserting a blank line in vim?

I quite often find I have a need to insert a blank line either below or above the current line when editing in vim. o and O will do this, but they subsequently switch into insert mode, which is annoying. Is there any built-in command to do this which will remain in normal mode?


Source: (StackOverflow)

Any IRC clients with VI key binds?

Is there any IRC client that supports VI keys? The ''obvious'' script VimIRC is and has been broken for so long it's not even funny.

Do you know any IRC clients on Linux, GUI or Curses, that provides some of that nice vi usability?

Or could some of the existing clients be scripted to use? Irssi, XChat, even ERC would do?


Source: (StackOverflow)

Logged in to vi, made changes, forgot to sudo first - now what

I made lengthy changes to a configuration file on a Ubuntu Linux computer with the vi editor. Unfortunately, I forgot to sudo first, so now I'm in the editor, but can't save my changes because of missing rights. Can I retroactively sudo the user on that terminal, or what would be the best course of action to take?


Source: (StackOverflow)

Readline in vi mode: how can I enable up/down arrows?

When bash has vi bindings available (set -o vi), up/down arrows work in both command and insertion mode. When I setup readline's ~/.inputrc to use vi mode (set editing-mode vi), applications like irb don't get the arrow functionality. I've tried "set enable-keypad on" in inputrc to no effect.

How do I get bash-like arrow functionality in other readline aware applications?


Source: (StackOverflow)

How to get rid of the warnings when opening a file that has a .swp file?

How can I get rid of the annoying warnings when I open a file that has a .swp file? Or, how do I not generate the .swp files at all? Example warning:

E325: ATTENTION
Found a swap file by the name ".notes.swp"
          owned by: james   dated: Fri Dec  3 17:38:07 2010
         file name: ~james/school/se/project-dir/rottencucumber/doc/notes
          modified: no
         user name: james   host name: james-laptop
        process ID: 2251 (still running)
While opening file "notes"
             dated: Fri Dec  3 18:46:10 2010
      NEWER than swap file!

(1) Another program may be editing the same file.
    If this is the case, be careful not to end up with two
    different instances of the same file when making changes.
    Quit, or continue with caution.

(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r notes"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".notes.swp"
    to avoid this message.

Swap file ".notes.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

Source: (StackOverflow)

vi / vim abrumpt buffer movements within window

When using :set wrap in vi/vim, the contents of an entire wrapped line are placed in the display buffer upon moving the cursor into a new line, even when navigating through a file by display line (gj/gk) as opposed to real line (j/k). For example, if a line is wrapped over 5 screen lines and is currently outside the display buffer, the buffer will jump by 5 lines when navigating into this line to force the entire line to fit in the screen. Is there a way to disable this behavior? Note that set display+=lastline will allow the display of partial lines when a wrapped line is forced off the screen by navigating away from the line, but this does not resolve the buffer jumps that occur when navigating into a line that was initially outside the buffer.

Clarification: In case the above description is nebulous, the gist is that I would like to be able to scroll smoothly in vim with line wrapping enabled such that lines will be partially displayed off the screen rather than obligatorily being displayed in their entirety.


Source: (StackOverflow)

Vi can write to file despite file being read-only

The following example show how to create a file with only read permissions. As we can see, when I try to write to this file using the echo command I get, Permission denied.

But why, in the case that we use vi, do we not get Permission denied? As can be seen here, we can write to the file even though the file is read-only.

What is happening here? Is this a vi bug?

[admin@madona-machine1 ~]$ touch test-file
[admin@madona-machine1 ~]$ ls -ltr
total 0
-rw-r--r-- 1 admin admin 0 Apr 13 07:32 test-file
[admin@madona-machine1 ~]$ chmod -w  test-file
[admin@madona-machine1 ~]$ ls -ltr
total 0
-r--r--r-- 1 admin admin 0 Apr 13 07:32 test-file
[admin@madona-machine1 ~]$ echo try_to_write > test-file
-bash: test-file: Permission denied
[admin@madona-machine1 ~]$ vi test-file

I am good singer,

 ~
 ~
 ~
 ~
 ~
 ~
 ~                                                
   "test-file" 1L, 4C written

Source: (StackOverflow)

How do i select all text in Vi/Vim?

Using VI tool for editing config files.

How can I select all the text in a file (around 1000 lines), copy it, then paste into Google Docs?


Source: (StackOverflow)

Close VIM session over ssh

I work remotely some days and I left vim open with some unsaved changes at the office. Now I'd like to save and close those sessions so I can work on those files at home. I am logged into that machine over SSH. Anyone have any idea?


Source: (StackOverflow)

How can I edit all the files returned by find in vi in Linux?

Something I find myself doing a lot is running a find command and then editing all of them in vi, which looks something like this:

> find . "*.txt"
./file1.txt
./file2.txt
./path/to/file3.txt

> vi ./file1.txt ./file2.txt ./path/to/file3.txt

Is there a clever & simple way to do this all in one command line?


Source: (StackOverflow)

How to switch comfortably to vi command mode on the zsh command line?

In vi, I have mapped 'jj' to escape to be able to switch to command mode without using the annoying escape key. Now I want to have the same for command line editing for which I use vi-mode. I already have found the following solution:

bindkey '^j' vi-cmd-mode

lets you change with control-j into command mode. Still searching for a solution without modifier-keys as 'jj' or something similar.


Source: (StackOverflow)