2

I'm very new to vim and there are several things I can't make work.

1) LISTCHARS. I set up vim to put dots at trailing spaces, but I want vim to replace spaces with dots in files, because now vim saves dots only after last words at the end of lines. Also, I want vim to put a > mark at the beginning of the current line and put something instead of TABs.

2) How can I override default key bindings? For example, if Vim has its own binding [Ctrl + A] doing something and I want Shift + T doing the same thing - what should I do? An extension of that question: by default, to move between split windows in vim there's a binding [CTRL+W, arrow] (it's like two consistent clicks). How can I override that? I want to use alt + arr instead of [ctrl+w, arrow].

3) I did:

nmap <C-Space> :NERDTreeToggle<CR>

to toggle the sidebar, but it doesn't work. I read ctrl-space is not easy to override, but I still want to use it to toggle the sidebar.

paisanco
  • 4,098
  • 6
  • 27
  • 33
Max
  • 45
  • 8

2 Answers2

0

1) If you read the vim help on 'listchars', you'll see that it provides a trail:c option that can be used to mark trailing spaces with a custom character c. I assume that's the option you are currently using. Fortunately, as of patch 7.4.711 (also see the changelog), 'listchars' now supports a space:c option that can be used to mark all spaces with a character c. So you can use that, if your version of vim is recent enough. (Note that the online vim help page I just linked to seems to be a bit out-of-date at the moment, so it doesn't mention the space:c option.) For example:

:set lcs+=space:.

With regard to putting > at the beginning of the current line, I believe that's not possible. So I'm afraid you're out of luck, unless someone else knows a trick I'm not aware of.

Finally, you can use the tab:xy option to put something instead of tabs. I actually like to use a couple of Unicode characters for this:

:set lcs+=tab:•·

2) What you're looking for here is mapping. You should note that "Shift + T" is actually just capital T, since shifting a letter key sends the capital variant of the letter on all modern computers. So you can do what you want with this:

nmap T <C-a>

This will set up T to increment the number under the cursor, which is the normal function of ^a.

Finally, with regard to mapping alt-modified arrow keys, this can be tricky, because it depends on which platform you're running vim on, e.g. whether you're running gvim on Windows or a terminal build on a Unix platform. If gvim, you can use the straightforward <M-...> codes:

nmap <M-Left> <C-w>h
nmap <M-Down> <C-w>j
nmap <M-Up> <C-w>k
nmap <M-Right> <C-w>l

But on other platforms, you'll need to figure out the escape sequences that might be sent when pressing a meta-modified arrow key, and map those. For example, when I run Cygwin vim in mintty on Windows, I can use this:

nmap <Esc>[1;3D <C-w>h
nmap <Esc>[1;3B <C-w>j
nmap <Esc>[1;3A <C-w>k
nmap <Esc>[1;3C <C-w>l

You should be able to figure out the escape sequences sent by a key combination by entering insert mode in a buffer (or command-line mode should work as well), pressing ^v, and then pressing the key combination. The characters that are inserted are the escape sequence sent by the key combination.

3) I've never used the NERD tree plugin before or tried mapping control-space, so I can't speak to this one. Perhaps you could ask a new question that focuses on this issue.

bgoldst
  • 34,190
  • 6
  • 38
  • 64
  • i already tried to set lcs like u offered be4 i wrote that issue. that is what was in my .vimrc ": " listchars set list set lcs=trail:· set lcs+=space:· set lcs+=tab:→→ set listchars=eol:¬ that didnt work. only eol worked and about 2) in sublime text or atom it is easy to write keybinding. for example in sublime text there is syntax for double keybinding ["ctrl+k","ctrl+b"] to toggle sidebar. what syntax is there in vim for double keybindings? for example for C-W+arrow would it be ? – Max May 21 '16 at 18:02
  • 1) My hypothesis is that you are overwriting the `set lcs+=space:c` and `set lcs+=tab:xy` settings when you run the `set listchars=eol:c` setting. Note that the former two settings use `+=`, while the last setting uses `=`, without the plus. That will overwrite all previous settings. You need to change it to `+=` for the previous settings to remain in effect. 2) Correct. – bgoldst May 21 '16 at 18:10
  • You were right, my eol overrode previous lcs. but, however lcs+=tab•·. or lcs+=tab:→→. doesnt work. i even tried to delete all other lcs, and left only one with tab - it didnt work. and btw how can i put >- at beginning of the line where im currently in? – Max May 21 '16 at 18:18
0

1)

If you just did:

set listchars=...

this will not work because you must also turn on the list option with:

set list

I misread your problem. You should use trail:. like bgoldst recommended.

2)

First, you must decide how you want the remapping to work, since remaps are modal, e.g. they work in certain modes. If for example, you want <shift-t> to equal <C-a>in normal mode, you must do nnoremap.

nnoremap T <C-a>

You can also do this for visual, insert or command mode with

vnoremap
inoremap
cnoremap

Recommended reading: What is the difference between the remap, noremap, nnoremap and vnoremap mapping commands in vim?

3)

<C-space> does not map to a real ASCII character, making it hard to map. However, you can still do it. Enter insert mode, and type

<C-v><C-space>

(ctrl+v then ctrl+space) This will insert the value that vim sees when you press ctrl+space. Most likely, you will see ^@, e.g. a null byte. If this is the case, you can map to ctrl+space with

nnoremap <NUL> :NERDTreeToggle<CR>
Community
  • 1
  • 1
DJMcMayhem
  • 7,285
  • 4
  • 41
  • 61
  • so about 3) what do i have exactly to put into vimrc? nnoremap :NERDTreeToggle these two lines after what ctrl-v + ctrl-space would toggle side bar ? – Max May 21 '16 at 17:56
  • @Max No, just let's you see what vim sees when you press . If typing that inserts a `^@` (it most likely will) then vim sees a byte, so you can jsut do `nnoremap :NERDTreeToggle` – DJMcMayhem May 21 '16 at 17:58
  • and i tried set list then on next line set lcs+=tab:•· as bgoldst offered - that didnt work. – Max May 21 '16 at 18:05