We changed our privacy policy. Read more.

Hot answers tagged

13

Try making it a mapping: " Mapping dead keys in normal mode nmap á 'a That way, when Vim gets the accented a, it interprets it as `+a Using nmap allows this to happen in normal mode only; in insert mode or command mode, you'll get the accented a as you'd expect. It is possible to apply this to other keys: nmap à `a nmap Á 'A nmap À `A nmap ç 'c nmap Ç '...


13

You can jump to numbered marks, but you can't set them directly. According to :h mark-motions: Numbered marks '0 to '9 are quite different. They can not be set directly. They are only present when using a viminfo file viminfo-file. Basically '0 is the location of the cursor when you last exited Vim, '1 the last but one time, etc. Use the "r" flag in ...


12

You can define a very simple custom mapping that lists the available marks and pre-populates the command-line with the right command stub, ready for you to type the desired mark name: nnoremap <key> :<C-u>marks<CR>:normal! ` Note that this simply follows the same pattern as that famous mapping: nnoremap <key> :ls<CR>:b<...


10

There is no way to make marks visible in vim proper. If it is however enough to just list them you can issue the :marks normal-mode command, which will give you a list of all marks in the current buffer and all global marks (the one with capitalized letters). Additionally there is a plugin called showmarks that will do the job. It displays a column left to ...


10

Especially for mapping purposes, I find using getline() more elegant than doing the yanking yourself. Calling getline() with a string '.' returns the line under the cursor. There are two good options for using this: :exec '/' . getline('.') which parses the strings '/' and what is returned from getline() together and executes that as a vim command. or /&...


7

Here's how I'd do it: Yank the line (into the unnamed register), without including the newline at the end: 0y$ Initiate a very nomagic search: /\V Add the yanked line: <c-r>" Fire off the search: <cr> As @EvergreenTree points out in a comment, you can of course create a mapping to perform all the steps in one go: nnoremap <leader>* 0y$/\...


6

Here is some basic VimScript which roughly does what you want. We override the ma through mz mappings to store the current value in g:previous_marks before calling the original m to actually set the mark. We also define <Leader>ma through <Leader>mz to show the history for said mark. You will probably want to store the info in g:previous_marks ...


6

There is nothing built in to vim, but you can script something like this: fu! s:IncrementalMark() abort let b:index_mark=get(b:, 'index_mark', -1)+1 " configure, which marks to use let marks='abcdefghijklmnopqrstuvwxyz' return 'm'.marks[b:index_mark%strlen(marks)] endfu nnoremap <silent><expr> <leader>m <sid>...


6

You could use this function to do what you want: It takes 3 arguments: A normal mode command (which should move the cursor) The mark where to beginning the motions The destination mark It will return the minimal number of motions required to reach or overstep the destination mark It test several cases and stop the function if The direction of the motion ...


6

I created a plugin that I think does what you want. If you want to change the colors that it uses simply define g:highlightMarks_colors in your vimrc as a list of colors (either names or RGB strings). I welcome any feedback you have. Screenshot as example:


6

Is there a plugin or something for that that works well? Why yes there is! I use kshenoy/vim-signature, and highly recommend it. From the README: vim-signature is a plugin to place, toggle and display marks. Apart from the above, you can also Navigate forward/backward by position/alphabetical order Displaying multiple marks (upto 2, limited by the signs ...


6

I do this by first creating a mark - for example, create a mark named "a" with ma in command mode – then search or move around the file however you want. Then go back to your mark with 'a.


6

The format for :m[ove] is :[range]m[ove] {address} Where the range is the line or lines you want to move and the address is the target. Note that the moved line(s) will actually be placed on the line below the address. So you're looking for a range of "mark a" and an address of "the current line". You can find all the special names for ...


5

I'm going to swim against the stream on this one. Just don't worry about it. Marks are pretty ephemeral and there are bunch of marks Vim automatically maintains like '[, '', and '. Humans are typically very bad at bookkeeping so we typically use only a few registers and a few marks. I personally only use a few a-z marks (typically 'm) and often only in ...


5

The existing answers all fail if your line contains certain items that are interpreted as a part of a pattern. The \V point gets most of the way there but still messes up with the backslash. Try this to escape the backslashes... /\V<C-R>=escape(getline('.'), '\') And then if you're using it in a mapping you'll need one or two <Enter>s at the ...


5

You can use \%>'m and \%<'m to match after and before a given mark, m. /\%>'afoo\%<'b For more helps see: :h /\%'m


4

Personally I would get a visual star plugin (there are few out there). There is a nice Vimcast about this: Search for the selected text. This means you can select the line visually and then press *. If a plugin isn't your thing you can add the following mapping to your vimrc: xnoremap * :<c-u>let @/=@"<cr>gvy:let [@/,@"]=[@",@/]<cr>/\V<...


4

A variation on your own response is to install fzf.vim and then bind to :Marks, e.g.: nnoremap ` :Marks<CR> This has the benefit that it will show up in fzf's fuzzy search window. (Caveat: It does require pressing <Enter> after you've found the item.)


4

This does exactly what my original question was """""""""""""""""""""""""""" " Ranger style marks command " """""""""""""""""""""""""""" function! Marks() marks echo('Mark: ') " getchar() - prompts user for a single character and returns the chars " ascii representation " nr2char() - converts ASCII `NUMBER TO CHAR' let s:mark = ...


4

Both specify certain points in a file and give you commands to jump there and as such they are the same. But marks are created by vim. Either explicitly by hand with m or automatically by vim (for the last selected text, the last position where you entered insert mode and so on). Tags on the other hand are read from the tags file which is normally created ...


4

If you haven't yanked or changed text since your last insertion, then you can use the `[ mark (see docs), which gets you back "to the first character of the previously changed or yanked text." By the way, `. will track your last change, not necessarily an insertion, a deletion, indent or format operation would also reset this mark. The `^ mark is the one ...


4

I found the answer here. Another easy way is to just add v right after y, no setting or Visual mode selection necessary. `a"ryv`b y`b yanks to mark b excluding the character under mark b, whereas yv`b yanks to mark b including the character under it. See :h o_v for more info.


3

Using 2 marks to operate on the text between those lines is the 'vi'-compatible way of the more modern and (literally) visual way of operating in Vim (and probably why visual mode was invented in the 1st place): visually select a range with whatever means (motion, text-object), then start your ex command, which operates line-wise: when you hit :, you will ...


3

Try this: :'a,'b s/\v(<[whnm]>)/\U\1/g Short expl.: \v - very magic (...) - create 1st group \U\1 - make 1st group uppercase Good references: vimregex, W.A.Zintz's articles To operate on each match, repeatedly, using a "normal-mode" command, you could do this instead: /\C\v<[whnm]> ENTER ~ (<- or any other command(s) operating on ...


3

I'm not sure I understood what you wanted. But if you want to cycle through all the available local marks from a to z, then the following mapping should allow you to do so: nnoremap <silent> <leader>m \ :<c-u>if !exists('marklist') \|\| marklist == [] <bar> \ let marklist = map(range(98, 122), "nr2char(v:...


3

The mark " indicates the position of the cursor when you last exited a buffer. Using that... Continue to use your cross-file marks but immediately follow with '" (or `" to restore the column as well as the line): 'X'" To make it a bit more convenient you can create a mapping that does the same thing: :nnoremap <leader>'X 'X'" If you put this in a ...


3

Two options I can think of off the top of my head: :[v]split, then search in only one window :nnoremap / mz/; then `z should take you back. Only works for one search at a time (i.e. new searches overwrite the mark)


3

The marks 0-9 are the last 10 files you were editing. See :h viminfo-file-marks (took me a while to find the correct help subject). '" : the cursor position when last exiting the current buffer (:h '"). Exiting here means closing the buffer (:bd) or exiting Vim while you edit a file. It does not mean leaving the buffer (like switching to another buffer). ...


3

You can define a custom command like this, that will only show the lowercase marks a-z: :com :MyMarks :sil! marks abcdefghijklmnopqrstuvwxyz


3

The ex commands :put and :delete both allow you to specify a line, so if you've already placed mark 'a on the line you want replaced, then you can execute the following after the copy: :'apu :'ad or as a one liner: :'apu|'ad If you haven't placed a mark, you could specify the line using a search instead: :/# Get here/pu ://d Or, again, as a one liner: :/# ...


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