3

I'm trying to execute simple commands in the vim terminal mode, but cannot get it to work. For example, I tried

nmap <F12> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $VIM_DIR<CR>

to open a terminal in the directory of the current file, but the final <CR> is ignored. I also tried term_sendkeys("","\<CR>") but that didn't have any noticeable effect at all.

Bananach
  • 494
  • 5
  • 15

1 Answers1

1

I tested that this works. It assumes that the terminal is opened in buffer 2.
You can check which buffer the terminal is open in with :ls.

:terminal
CTRL-W W 
:let  $VIM_DIR=expand('%:p:h')
:call term_sendkeys(2, "cd $VIM_DIR\n")
:call term_sendkeys(2, "pwd\n")

Also your initial command worked for me.

nmap <F12> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $VIM_DIR<CR>

It maybe that you are testing this mapping using keys that are already mapped. You can review the nmap mappings with:

:nmap

Or a specific mapping with:

:verb map <F12>

verb (verbose) tells you where the mapping was defined (file and line).

Biggybi
  • 2,740
  • 9
  • 29
DC Slagel
  • 266
  • 4
  • 11