Tag Info

Hot answers tagged

42

You, glen, are the owner of the directory (see the . file in your listing). A directory is just a list of files and you have the permission to alter this list (e.g. add files, remove files, change ownerships to make it yours again, etc.). You may not be able to alter the contents of the file directly, but you can read and unlink (remove) the file as a whole ...


16

You're talking about the greatest feature ever! To use vi commands to edit your shell commands (and history) add the following to your .bashrc file: set -o vi You can also run that command from the command line to affect only your current session. If you don't use bash, substitue the appropriate rc file for your shell. This allows you to use vi ...


16

Use the write command: :write Which can be abbreviated: :w If you want to write to another file without changing the current file, supply a different filename to the write command: :write newfile If you want to write to another file and change to that file, use the saveas command: :saveas newfile Which can be abbreviated: :s newfile


14

dW (capital W) or more generally you can do df followed by the character to search for, in this case space. You can also use t instead of f to delete up to but not including the found character. And if you capitalize the F or T, they work backwards.


13

before: -rw-r--r-- 1 root staff 0 19 Dec 12:38 temp after: -rw-r--r-- 1 glen staff 7 19 Dec 12:38 temp The vim does not break through the permission barrier. Just have a look at the file information listed carefully then you could find out that vim actually deleted the original file (because you have the permission to remove the file though ...


12

No vi doesn't have any significant advantage over vim rather its the other way around. Vim has more advantages then Vi. You may be interested in : Why, oh WHY, do those #?@! nutheads use vi? Edit also read : Is learning VIM worth the effort?


11

You can use xargs: locate filename123 | xargs vi By default xargs will execute as few instances of the specified command as possible, passing as many parameters as possible according to the system's ARG_MAX. To limit the number of parameters passed to an instance of vi, use xargs' -n option. To handle file names containing spaces use xargs' -d option: ...


10

For vim, you have powerful scripting available. For example, in my .vimrc, I have: " Stolen from http://www.debian-administration.org/articles/571 " Sets +x on stuff starting with the magic shebang. au BufWritePost * if getline(1) =~ "^#!" | silent !chmod a+x <afile> If you want to do it by filename only, instead of looking for the #! line, you ...


10

I tend to use ctrl+z to sleep vi, run what I need to in the shell, then fg to resume vi. Not exactly an answer to your question, but I find it a very fast way to work. If you do forget that you have vi open in the background (this can happen when you are busy), when you try to log out of the shell using ctrl+d you will be warned that you have background ...


10

The current filename is in the "% register, so you can insert it (while in insert mode) with <c-r>%; the full path can be inserted with <c-r>=expand("%:p"). You could make a macro of it if you use it often. For more, similar tricks, see :h expand and :h "=.


9

There are many ways: esc, shift+C ctrl+O, shift+D shift+end, del shift+end, s Don't be afraid of falling back to the normal mode even for a short instant.


9

You can use set -o vi to change your line editing commands as @jahroy posted, but you may be thinking of the fc command (available in bash and I think ksh, but probably not tcsh), which will put the previous command into an editor (FCEDIT or EDITOR, which you probably have set to vi) and then executes the command when you exit the editor. See the manpage or ...


9

The general answer is to use the :normal command, like :exe "normal \<C-W>\<C-w>" The :execute approach is the readable way to get :normal to recognize special characters like control-key combinations. The other approach is :normal ^W^W where each^W is one character inserted by typing Ctrl-vCtrl-w.


9

do (diff obtain) and dp (diff put) is what you need. Here is a small list of other helpful commands in this context. ]c - advance to the next block with differences [c - reverse search for the previous block with differences do (diff obtain) - bring changes from the other file to the current file dp (diff put) - send changes ...


9

tmux and screen have different models so there is no exact equivalent. In screen terms, a split lets you display multiple windows at the same time. next (C-a n) rotates windows through the active part of the split; this lets you rotate “hidden” windows through the active region of the split. In tmux terms, a split divides a window into one or more panes. ...


9

Rather than yanking into the a register yank into the * or + register to yank the file contents into the X clipboard using one of: :%y* :%y+ This does require that you're using a copy of vim that has X support compiled in and is able to connect to your X server. Which of those works better for you will depend on which type of clipboard the target ...


8

If you're using bash, as jahroy and evil otto have already answered, you can use set -o vi to cause bash to use vi-style editing commands. Once you've done this, you can type Esc v to launch the vi editor with a temporary file containing a copy of the current command line. You can edit the command, even replacing it with multiple lines; when you save the ...


8

The most general: Move cursor to first line of the group you want to write. Hit m and a sequentiall. That's "set mark named 'a'". Move cursor to last line of the group, hit 'm' and 'b'.' Change over to command mode hit: as a sequence do :'a,'b w filename then hit return. That will work in vi, nvi and vim. Another method, works in more modern vim: Put ...


8

Since you mentioned "get the stdout", note that you can do :r! command and the output of the command will be added to the file, or :<range>!command to have the content of the range filtered through the command [e.g. :1,$!wc]


8

There are several possibilities. One method is to compile using :!gcc file.c But a nicer strategy would be to have a Makefile and compile just using :make Where the easiest Makefile would look like. program: gcc file.c Others can explain this a lot better.


8

You'll have to use tmux shortcuts. Assuming your tmux command shortcut is the default: Ctrl+b, then: Ctrl+b, [ Enter copy(?) mode. Move to start/end of text to highlight. Ctrlspace Start highlighting text (on Arch Linux). When I've compiled tmux from source on OSX and other Linux's, just Space on its own usually works. Selected text changes the colours, ...


8

I would have a hard time living without vim but I can't stand vi. However, learning the former will at least leave you with an idea of how to deal with the later when that's all that is available. The vim interface by default is actually pretty close to vi. If I'm working on a system with vim the first thing I do is add this stuff to ~/.vimrc: syntax ...


8

I've had the most luck with this: :%!xmllint --format % It's strict about your tags, though, so it will error out if your opening and closing tags don't match. It also adds an XML declaration at the top of your file, if you don't have one as well. This page recommends the following, although I can't get it to work: :set filetype=xml :filetype indent on ...


7

Have a look at http://mercurial.selenic.com/wiki/CACertificates - it should be enough to specify the cacerts. In short don't depend on the specific fingerprint but check if the cert is signed by a trusted source. For Debian/Ubuntu/Arch/Gentoo: [web] cacerts = /etc/ssl/certs/ca-certificates.crt Fedora/RHEL: [web] cacerts = ...


7

When you have the file open, you can run: :set filetype=messages To automate this for all files called messages, put the following into ~/.vim/ftdetect/messages.vim: autocmd BufNewFile,BufReadPost *messages* :set filetype=messages


7

Aliases are internal to each of your current shell environments - they are expanded by the currently running shell (bash in your case), so they only have effect on what you execute by typing/pasting in your terminal. You have at least two options here: create a wrapper script named vii that will execute vim -c 'startinsert' and put it preferably in ...


7

Not sure if vi is required for this operation. There is xclip utility that allows you to copy anything from console output to x server clipboard. You should specify DISPLAY=:0.0 environment and execute it like this: cat file | xclip or for remote file ssh remote "cat file" | xclip Or from vi (note, that this way will temporaly clear vi buffer ...


7

This feature is called Software Flow Control (XON/XOFF flow control) When one end of the data link (in this case the terminal emulator) can't receive any more data (because the buffer is full or nearing full or the user sends C-s) it will send an "XOFF" to tell the sending end of the data link to pause until the "XON" signal is received. What is ...


6

using .zshrc to modify my environment variables That's the root cause of your problem. .zshrc is a startup file for interactive shell sessions. Use it to set shell settings, not to set environment variables. Environment variables are typically set in a session file such as .profile. See Alternative to .bashrc (what goes for .bashrc also goes for ...


6

Just set the editor variable to [core] editor = vim -c 'startinsert' For your other answer, yes you can't place aliases in a directory as an alias is a concept from your shell. The normal way is to create an appropriate wrapper script to execute the specified commands, e.g. #!/bin/sh vim -c 'startinsert' "$*" and save the script as vii and make it ...



Only top voted, non community-wiki answers of a minimum length are eligible