Loading ...
Sorry, an error occurred while loading the content.
 

Re: Printing filename without extension under current cursor position

Expand Messages
  • Tim Chase
    ... Change your % to =expand( %:t:r ) However, you can do the whole thing with something like map 0put = class
    Message 1 of 4 , Jan 1, 2006
      > map <F1> 1GIclass <C-R>% <ESC> " generate a java main class template
      > ----
      >
      > This peace of code produces the phrase "class filename.java ..."
      >
      > How can I get vim printing me the filename WITHOUT extension
      > under the current cursor position?

      Change your

      <C-R>% <ESC>

      to

      <C-R>=expand("%:t:r")<cr><esc>

      However, you can do the whole thing with something like

      map <F1> 0put ='class '.expand('%:t:r')<cr>

      which will put the desired text on the first line as it
      looks like your current mapping should do.

      For more info, you primarily want the modifiers available at

      :help expand()

      but you might also be interested in reading

      :help :put
      :help "=

      which will provide some of the details on these little toys.
      Hope they help!

      -tim
    • A. J. Mechelynck
      ... I think it is something like ... see :help expand() HTH, Tony.
      Message 2 of 4 , Jan 1, 2006
        Steve Kreyer wrote:
        > Hi,
        >
        > I want to write a macro which generates me a "java main class template",
        > via
        > a key mapping:
        >
        > ----
        > map <F1> 1GIclass <C-R>% <ESC> " generate a java main class template
        > ----
        >
        > This peace of code produces the phrase "class filename.java ..."
        >
        > How can I get vim printing me the filename WITHOUT extension
        > under the current cursor position?
        >
        > Thanks for your time...
        >
        > Regards
        >
        > Steve
        >
        >
        >
        >

        I think it is something like

        :echo expand("<cfile>:r")

        see ":help expand()"


        HTH,
        Tony.
      • Steve Kreyer
        Hi, ... Ok expand() was the function I m looking for. expand( %:r:t ) and expand( %
        Message 3 of 4 , Jan 1, 2006
          Hi,

          Tim Chase schrieb:

          > Change your
          >
          > <C-R>% <ESC>
          >
          > to
          >
          > <C-R>=expand("%:t:r")<cr><esc>
          >
          > ...
          >
          > For more info, you primarily want the modifiers available at
          >
          > :help expand()

          Ok expand() was the function I'm looking for.
          expand('%:r:t') and expand('%<') will do the trick...

          >
          > but you might also be interested in reading
          >
          > :help :put
          > :help "=

          Good tip :)

          >
          > which will provide some of the details on these little toys. Hope
          > they help!
          >
          > -tim
          >
          Thank you for your help and time...

          Regards

          Steve
        Your message has been successfully submitted and would be delivered to recipients shortly.