Hot answers tagged

36

There are several ways to do this. Inside Current Directory If you want to perform the search/replace in a project tree, you can use Vim's argument list. Simply open Vim and then use the :args command to populate the argument list. You can pass in multiple filenames or even globs. For example, :args **/*.rb will recursively search the current directory ...


30

Let's say we have a simple project structure like this: greeting.txt looks like and info/age.txt looks like Let's say we want to replace all occurences of Sam with Bob. Here's what we would do: Set working directory Make sure Vim's current working directory is the root of the project (won't show you how to do this here). Find files that contain 'Sam' ...


27

Some features that will only work with gVim: 24-bit color support out of the box (to get the same amount of colors in terminal vim, you have to try a little harder, see this and this). For true italics, the same holds true (see this and this). Note that you should be using a font that supports true italics. Some other more advanced graphical features, such ...


17

Well… it's just as simple in vimscript. Current window Python: current_win = vim.current.window Vimscript: let current_win = winnr() Current buffer Python: current_buff = vim.current.buffer Vimscript: let current_buff = bufnr("%") Current tabpage Python: current_tabpage = vim.current.tabpage Vimscript: let current_tabpage = tabpagenr() See :...


16

Unfortunately, there's no reliable way of mapping Ctrl-=. Because of the way that ctrl+key chords interact with the terminal and are represented internally, the only Ctrl-mappings that Vim is guaranteed to be able to detect are the ones defined in the ASCII standard. Here is the full list of such ctrl+key combinations, and the byte each represents. Ctrl-@ ...


10

Ah, I found the culprit by bisecting my .vimrc file. I had mapped Escape in normal mode to clear search highlighting: " Clear highlighting on escape in normal mode nnoremap <esc> :noh<return><esc> However, that will confuse vim as it tries to parse the mouse's escape codes. So what I ended up doing is taking the solution from this answer, ...


10

If you want to do it from the normal mode, just type: 15|. If you want to move to 15th column in 25th, type 25G15|. If you want to do it as a command you can type: :call cursor(25,15) but I think it is easier to type 25G15|.


10

While I mostly agree with @romainl comment (markdown was made to be explicit enough not to need a preview) you can do this in different ways: [OSX / Unix] The instant-markdown plugin is a solution. You need to have node.js installed and to use the following command: [sudo] npm -g install instant-markdown-d You also need to have the packages xdg-utils, ...


9

To disable all mouse functions, you can simply put this in your vimrc file: set mouse= For more, see :help 'mouse'.


7

You can use a count before Ctrl-E − 15<C-e> moves down 15 lines. Ctrl-D moves down half a screen by default, although the amount it moves can be configured via the "scroll" option. :help motion.txt will provide this and a whole lot more details.


7

nnoremap only affects [n]ormal mode and will not affect [v]isual mode. You need vnoremap for that: vnoremap d "_d


7

Type <c-o> to temporarily leave insert mode and use normal mode keys instead. To create insert mode maps, read :h normal-index and :h insert-index. Then create insert maps that does about the same thing you want. For example: inoremap <c-a> <c-o>0 inoremap <c-w> <c-o>db inoremap <c-e> <c-o>$ The reason why Vim ...


6

Install the "surround" plugin. Then you can just do d s B . From the project page: Surround.vim is all about "surroundings": parentheses, brackets, quotes, XML tags, and more. The plugin provides mappings to easily delete, change and add such surroundings in pairs. The command ds followed by any text object (B in this case, for "Block", as in the aB or ...


6

I can reproduce the problem on my Linux system running Vim 7.4.729 as gvim. The problem appears to be the synchronizing of Vim's syntax highlighting engine. To save time, Vim doesn't always look at the whole file to figure out how to highlight it. In this case, Vim isn't looking back far enough in the file to see the opening parenthesis, so it thinks any ...


6

Summary It's a bug and there's a patch (743). The bug affects both your examples, but you don't see it in one case because the character that is moved down is a (whitespace). The solution is to install the patch, but there are also many workarounds or alternative methods, not affected by the bug. NB: {, } and B all refer to the same text object: Block (...


6

Instead of printing from Vim, you could instead generate an HTML file using :TOhtml. Then you can use CSS to set the font used for the HTML and print that.


5

:promptfind and related commands are useful for the easy mode (evim), which according to :help easy sets Vim up to work like most click-and-type editors. As Notepad has such a find dialog, and users coming from such editors expect it / initially feel better with it, Vim has it, too. I personally wouldn't recommend this way for switching to Vim, though.


5

Since you aren't asking for the cursor to be returned to its original position, [{x]}x does the job. It's 6 characters long with two presses of Shift but the principle is straightforward so it's easy to remember. If you want to go back to the original position, you can use [{x``]}x``


5

Important note As I mentioned it in the comments when you begin to use Vim the best you can do is to start with an emtpy .vimrc. From this you'll be able to build your own configuration which really suits your needs. There are a lot of resources to help you beginning with Vim. So don't copy stuff you don't understand in your .vimrc it I'll only cause ...


5

From :help popt-option: formfeed:y When a form feed character is encountered, continue printing of the current line at the beginning of the first line on a new page. So… add the line below to your vimrc: set printoptions+=formfeed:y insert a form feed where you want your page break to occur with <C-l> in insert mode, do :...


5

What you want is the "changelist": :help changelist. Use 3g; to jump to the third previous change in the "changelist" and 2g, to jump back 2 steps in the list.


5

| is the command separator, so it terminates the map. You need to escape it: nnoremap <c-m> <c-w>\| Or use <bar>: nnoremap <c-m> <c-w><bar> See :help :bar and :help map_bar.


5

You don't need a plugin, all you need is two lines of vimscript! If you would like every time you press 'j' or 'k' to be added to the jumplist, this is pretty easy. You could do it with this: nnoremap <silent> j :<C-u>exe "normal! m'".v:count1."j"<cr> nnoremap <silent> k :<C-u>exe "normal! m'".v:count1."k"<cr> ...


5

Documentation of Vim plugins (rightfully) assumes that you know your way around Vim itself. I would therefore recommend that you start by finding your way around the Vim documentation and Vim itself. A good starting point for Vim itself is the Vim tutor which you can probably find by typing "vimtutor" (without the quotes) in a terminal. To understand what ...


5

You seem to be looking for MacVim Preferences, and they are under the MenuBar entitled "MacVim". MacVim -> Preferences -> General There you'll find settings for what to do on startup, and after the last MacVim window closes. You can decide to automatically open a blank window on startup, and also for when "the last window closes" you can check "Leave ...


5

<esc> and <C-c> are mostly similar. They will differ in some cases such as the following: Doing a vertical insert (<C-v>, then going down, then i to insert the same character, or text, on multiple lines): <esc> will leave the insert mode and insert the typed text on the selected lines, whereas <C-c> will leave the insert mode ...


4

I just can talk about gVim. Besides basic differences, I found that using gVim help me a lot at the beginning to learn basic commands (for example one way of copying selected text to the clipboard with "+y) by reading each of the shortcuts displayed on the menu. It may sound silly, but you really should spend some time traversing the menu and not just click ...


4

See :help cmd-key and :help macmenu. As you noticed ⌘-T is now mapped to "New Tab" in the menu. You need to free up ⌘-T before you can remap it to something else. Something like the following should be added to your .gvimrc (.vimrc will not work): " Free Up Cmd-t macmenu File.New\ Tab key=<nop> " Remap it to fuzzyFinder nmap <D-t> :FufBuffer&...


4

Some of us are stuck in Windows land, so the terminal options are less convenient. In Windows Explorer you can right-click a file and open it immediately with gVim. That's a lot easier and faster than opening a terminal (cygwin or whatever), navigating to the directory, and vimming the file. (On my work PC, gVim and MinGW bash cover most of my editing ...


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