New answers tagged

3

If you want it to depend on the version, use this: if version > 700 "do stuff for version 7 and up endif If what you really want to know is whether a certain command works, you can use the exists statement: if exists('+breakindent') set breakindent endif If it's being in a GUI that you care about, try if has('gui_running') or put the ...


3

It's the command-line window (keyboard shortcut q:, quit with ctrl+c,ctrl+c) It shows a history of your previous commands, which you can navigate to and edit with normal (command) mode. Once you've finished you can hit enter to run the edited or reselected command. A similar history window is available for searches (keyboard shortcut q/, quit with ...


0

This is simple and works: in normal mode, place your cursor at the first character of the string you want to right-align, like the comment delimiter, and then press leader then tab to right align the text. nnoremap <leader><tab> mc80A <esc>080lDgelD`cP With explainations: mc80A <esc>080lDgelD`cP | | | || || mc| | ...


0

I've learned Vim shows no status line for a single window, only when two are open does it show. This can be overridden by including set laststatus=2 in your .vimrc, this makes the status always show.


1

why do you use the Pipe? :%s/.*/\<a href=\"&\"\>&\<\/a\>/g (mark all command strings with \ )


4

:%s:.*:<a href="&">&</a>: Same as in ed/sed/perl... Another less ex and more vim-like way would be: if you know how to do it once for a line, record it as a macro and then run :%normal @m where m is that macro. Like (in normal mode): qmS<a href="<Ctrl-R>""><Ctrl-R>"</a><Esc>q to record the macro.


3

-o, -O, and -p are mutually exclusive. You can't combine them. From main.c, command_line_scan(): case 'p': /* "-p[N]" open N tab pages */ parmp->window_layout = WIN_TABS; break; case 'o': /* "-o[N]" open N horizontal split windows */ parmp->window_layout = WIN_HOR; break; case 'O': /* "-O[N]" open N vertical ...


2

A command line program can take input from a user via two sources: from stdin (which you are piping to), and by attaching directly to the TTY. Bad things can happen when these are mixed up. Vim does not want to read input from a pipe, it wants you, the user, directly. So let's give it the real stdin back. As a solution, we can use a command substitution to ...


1

You can remap your paste command to LEADER + p nnoremap <leader>p :set paste<cr>p:set nopaste<cr>


0

If you're pasting from the clipboard, paste directly using "+p. I use \p as a mapping for it: nnoremap <leader>p "+p This should prevent problems with indentation, etc. I have the following mappings for pasting from the clipboard and copying to it: noremap <leader>p "+p noremap <leader>y "+y


4

You don't need the second !. It should be just: :'<,'>! sort -f | uniq From :help :!: Any '!' in {cmd} is replaced with the previous external command (see also 'cpoptions'). But not when there is a backslash before the '!', then that backslash is removed. Example: ":!ls" followed by ":!echo ! \! \\!" executes "echo ls ! \!". A '|' in {cmd} is ...


3

The :intro command displays the welcome screen.


4

You could issue the command: :intro


-1

With the util-linux rename, no, this one only does basic string replacement. With the Perl-based rename, yes, see choroba's answer. With zsh's zmv: autoload -U zmv # put this in your ~/.zshrc zmv '(*)_(*).(*)' '${2}_$1.$3' zmv -w '*_*.*' '${2}_$1.$3' The two zmv invocations above are equivalent. To act in subdirectories as well, you can use zmv -w ...


0

Without looking at the exact environment, I can only guess that /tmp does not exist (or is full or has some permission issue) on the culprit machine. When-ever you write to existing file, vim is not able to save the backup, so it is complaining, and then prompting you. You can check if this is the case by trying one of the following: See if you can save ...


3

If you have the rename implementation with Perl regexes (as on Debian/Ubuntu/…, or prename on Arch Linux), you need $1 instead of \1. Also, no backslashes on capturing parentheses: rename 's/(.*)_(.*)/$2_$1/' *_* If not, you have to implement it yourself. #! /bin/bash for file in *_* ; do left=${file%_*} right=${file##*_} mv "$file" ...


5

The vim command line switch -c will execute vim commands. You can pass multiple commands and passing the two following commands will start help, in only one window vim -c help -c only


2

vim treats a sequences of [A-Za-z0-9_] or sequences of non-blank characters separated with white space as a word, sequences of non-blank characters separated with white space as a WORD. You can re-define what word mean to vim: set iskeyword-=_ Now place your cursor at e, press d+w or d+e


2

I've made a script to grep recursively for a pattern, and then I can select one of the matches so vim will open that file in that line. I call it vgrep (vim grep, although it uses also awk in it). The following is its code: #!/bin/bash my_grep() { grep -Rn -I --color=auto --exclude-dir={.svn,.git} --exclude={tags,cscope.out} "$@" . 2>/dev/null } ...


0

Check if this is useful : File=`grep -r foo /path/of/search/* | grep 'roger'` WhichItem=3 ThirdFile=`grep -r foo /path/of/search/* | head -$WhichItem | tail -1`


1

From within the vi/vim/gvim editor, you can open a file by typing :e fileName (or instead of fileName you can use path/to/fileName, absolute or relative). For the multiple file view (multiple-tab idea), first do one of the following: ctrl+s for a horizontal split ctrl+v for a vertical split Use ctrl+w+w to switch between panes


1

There are two ways you could do this: run vim in a screen session, and attach to that from different terminals run vim in client/server mode Further reading: Taking Command of the Terminal with GNU Screen Using GNU Screen to Manage Persistent Terminal Sessions Server and client mode in Vim How does vim support C/S mode?


0

vim has a hostname() function (see :h hostname()), so you can do :set statusline=%{hostname()}


1

If you want REALLY want this, you should use one of these after enter :help : :tab split Or :tabedit % And this will make a new copy of the current page(help) be positioned on a new tab. If you want to move, hit Ctrl-W (release) Shift-T will do the trick. I think that this key combination is what you really want. If you want to be proactive and open ...


0

inoremap means insert mode non-recursive map. vnoremap is visual mode non-recursive map. So vnoremap jj <esc> is what you want.


2

statusline can be modified to include variable names. For example, I'm using the statline plugin, so my statuslineis: statusline=[%{StatlineBufCount()}:%n] %<%1*[%f]%*%2*%h%w%m%r%* %y[%{&ff}%{g:statline_encoding_separator}%{strlen(&fenc)?&fenc:g:statline_no_encoding_string}] ...



Top 50 recent answers are included